W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2009

[webstorage] readTransaction clarification

From: João Eiras <joaoe@opera.com>
Date: Tue, 07 Apr 2009 13:46:10 +0200
To: public-webapps@w3.org
Message-ID: <op.ur0lm8mn2q99of@id-c0981>
Hi everyone.

The database section of the webstorage specification needs some clarification in a specific use case.
http://dev.w3.org/html5/webstorage/#sql

Please consider a typical webpage, that on first load, opens a database (using openDatabase) and then creates a read-only transaction to read data to initialize whatever needs initializing.
If it's the first time the user opens that webpage, the database that the webpage tries to access effectively does not exist yet and the user agent will have to create it, meaning that that database will be completely empty (no objects nor data).

The processing steps for readTransaction are clear though, about calling the apropriate callbacks for the queries, but it also demands, and rightfully so, that a read-only transaction must not modify data. This contradicts a bit the fact that the user agent would need to create the new datafile to represent that database.
Although the specification does not make any direct reference to datafiles, because that's an implementation detail, expecting an empty database for a readTransaction would require the user agent either to optimize this scenario to not execute any sql directly but to call the error callbacks with the apropriate error codes, if the user agent knows in advance that the database is empty, or, the user agent could create an empty datafile which would represent our new empty database, but that's a performance problem in devices with slow file IO. Even if the user agent was not aware of the fact that the database is empty, it would still cause all statements executed within the read-only transaction on our empty database to fail.

The situation is analogous to doing a first SELECT on a read-write transaction. However, the select can be interleaved between other DML/DDL statements which create and modify data, so there's no knowledge before hand if a SELECT is going to be executed on read-write transaction on an empty database. In this particular case, the user agent would just report the normal error about querying nonexistent objects.

So, I propose the readTransaction function to outright throw an exception IF the database is completely empty (no objects, no data). This would actually makes authors lives easier by getting the error sooner, and make the situation more easily detectable. It would also make implementors lives easier by introducing this optimization on the specification.

Thank you.

-- 

João Eiras
Core Developer, Opera Software ASA, http://www.opera.com/
Received on Tuesday, 7 April 2009 11:46:51 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:31 GMT