Use TRIGGER statement in Web SQL Database

746 views
Skip to first unread message

imiaou

unread,
Nov 17, 2010, 3:31:20 AM11/17/10
to Chromium HTML5
I use Web SQL Database to store data in my extension.
What I want is changing the modified time whenever a row in my table
been UPDATE(d).
Here is my code:

tx.executeSql(
'CREATE TABLE items ('
+'id INTEGER PRIMARY KEY,'
+'title TEXT NOT NULL,'
+'desc TEXT,'
+'url TEXT,'
+'list TEXT,'
+'tag TEXT,'
+'updated DATETIME DEFAULT CURRENT_TIMESTAMP ,'
+'created DATETIME DEFAULT CURRENT_TIMESTAMP);'

+'CREATE TRIGGER update_modified_time UPDATE ON items'
+'BEGIN'
+ 'UPDATE items SET updated = NOW();'
+'END;'
);

Whenever I run it, there's a "not an error" error. Quite weird.

PhistucK

unread,
Nov 17, 2010, 4:24:37 AM11/17/10
to imiaou, Chromium HTML5
If I am not mistaking, triggers are not supported within Web SQL Databases.
Anyway, the error sounds like really cryptic.
Search crbug.com for an existing issue and star it. If you cannot find one, file a new issue at new.crbug.com.

Thank you.


PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.


Jeremy Orlow

unread,
Nov 17, 2010, 10:57:04 AM11/17/10
to PhistucK, imiaou, Chromium HTML5
Agreed.

Dumitru Daniliuc

unread,
Nov 17, 2010, 2:53:23 PM11/17/10
to Jeremy Orlow, PhistucK, imiaou, Chromium HTML5
i'll take a look at this.

Dumitru Daniliuc

unread,
Nov 17, 2010, 3:07:56 PM11/17/10
to Jeremy Orlow, PhistucK, imiaou, Chromium HTML5
so the problem is that you're trying to execute 2 statements in the same call to executeSql(). when you try to do that, we return SQLITE_ERROR, which apparently has an error message of "not an error"... i'm not sure that there's a better error to return: http://www.sqlite.org/c3ref/c_abort.html.

if you move your CREATE TRIGGER statement into a separate executeSql() call, you should be fine. we do allow triggers. you will want to add some spaces between 'UPDATE ON items', 'BEGIN', 'UPDATE items', etc. in your statement though; otherwise it's equivalent to: CREATE TRIGGER update_modified_time UPDATE ON itemsBEGINUPDATE items SET updated = NOW();END;. also, you might want to consider changing "CREATE TABLE items" to "CREATE TABLE IF NOT EXISTS items", and do the same thing for the trigger.

dumi

imiaou

unread,
Nov 17, 2010, 9:16:36 PM11/17/10
to Chromium HTML5
Thanks. I'll try it.

imiaou

unread,
Nov 17, 2010, 10:09:02 PM11/17/10
to Chromium HTML5
It works!
Many thanks, dumi.

I have another question:
Does Chrome 7 stable implement all the sqlite feature so I don't worry
about if the feature is supported when I want to use it? Or is there a
status page I can check the implementation?

PhistucK

unread,
Nov 18, 2010, 1:25:35 AM11/18/10
to imiaou, Chromium HTML5
I think it does. There have not been many changes\new features since Chrome 5 or so, I believe, in this area.

PhistucK



Dumitru Daniliuc

unread,
Nov 18, 2010, 1:58:39 PM11/18/10
to PhistucK, imiaou, Chromium HTML5
this is correct. we should have support for all sqlite features, except a few of them that either didn't make much sense in the WebSQLDBs context (ATTACH or VACUUM (which btw, we do automatically for you)), or were considered a security concern (RANDOMBLOB, for example).

dumi
Reply all
Reply to author
Forward
0 new messages