So here's what I have:
this._database = window.openDatabase("testDatabase", "0.1", "Test
Database", 250 * 1024);
if (!this._database) {
console.log("Error opening database");
}
// Create settings table
this._database.transaction(function(query) {
query.executeSql('CREATE TABLE settings(id INTEGER PRIMARY KEY
AUTOINCREMENT, username VARCHAR(50), password VARCHAR(50))',
[]);
});
// Write a user
this._database.transaction(function(query) {
query.executeSql('INSERT INTO settings(username, password) VALUES
(?, ?)',
['Scott', 'password'],
function(transaction, result) {
console.log(result);
},
function(transaction, error) {
console.log(error);
});
});
// Read the table
this._database.transaction(function(query) {
query.executeSql('SELECT * FROM settings',
[],
function(transaction, result) {
console.log(transaction);
console.log(result);
},
function(transaction, error) {
console.log(error);
});
});
I'm trying to just feel around the API here before I dive head first
into anything, but running these three sequential queries doesn't
result in anything being stored in the database (or so it seems).
I've attached error and success callbacks to each, and they all go
through. The CREATE TABLE query fails after the first try since the
table already exists, so I know it's at least there. However, despite
writing a value directly into the settings table, my last query for
SELECT * FROM settings returns an empty SQLResultSet. What's more
interesting, is the INSERT query result set has a rows.length of 0.
Am I goofing something up here?
On Sep 2, 9:49 am, Scott Ferguson <[email protected]> wrote:
> Cool thanks! It looks like it doesn't work currently out of context
> of the extension, but within the extension's commandline it works
> totally fine.
>
> On Sep 1, 11:39 pm, Marcos Aruj <[email protected]> wrote:
>
>
>
> > this._database =
> > window.openDatabase("test", "1.0", "test Database", 250 * 1024);
>
> > if (!this._database) {
> > // TODO: handle error.
>
> > }
>
> > //Arguments is an Array.
>
> > this._database.transaction(function(aTransaction) {
> > aTransaction.executeSql(aSQLQuery, aSQLArguments, successCallback,
> > errorCallback);
>
> > });
>
> > successCallback : function (aTransaction, aResult) {
> > var length = aResult.rows.length; //number of rows in result set.
> > var rowsAffected = aResult.rowsAffected; //rows affected, applies for
> > update, delete statements...
>
> > }
>
> > errorCallback : function(aTransaction, aError) {
> > var message = aError.message;// error message
>
> > }
>
> > Hope this helps.
>
> > Best regards,
>
> > Marcos
>
> > On Tue, Sep 1, 2009 at 8:40 PM, Scott Ferguson <[email protected]> wrote:
>
> > > Could you provide a quick demonstration of how to use openDatabase()?
> > > Documentation is sketchy right now, it'd be much appreciated.
>
> > > On Sep 1, 5:00 pm, "Mike H." <[email protected]> wrote:
> > > > i made an ad blocking extension two months ago that uses the database
> > > > and
> > > > its working fine... i meant to release it but haven't gotten around to
> > > it.
>
> > > > On Tue, Sep 1, 2009 at 4:10 PM, Scott Ferguson <[email protected]>
> > > wrote:
>
> > > > > So I see that openDatabase() is an available call but is it working in
> > > > > the latest Chromium builds? Or maybe I just can't find the
> > > > > appropriate API documentation for it?
>
> > --
> > Marcos Aruj Alvarez
> > Ingeniero de Software
> > -------------------------------
> > [email protected]
> > -----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en
-~----------~----~----~----~------~----~------~--~---