Bug 125032 - Web SQL: changeVersion cannot be used in openDatabase creationCallback
Summary: Web SQL: changeVersion cannot be used in openDatabase creationCallback
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-30 14:27 PST by Luke Stebbing
Modified: 2013-11-30 14:27 PST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Stebbing 2013-11-30 14:27:05 PST
In WebKit 537.71 (Safari 7.0 (9537.71)), I'm seeing the following Web SQL bug. I suspect it affects all WebKit versions with Web SQL support.


Navigate to a domain where you wouldn't mind creating a Web SQL database with a random name, and run the following snippet in the JS console:

db = openDatabase('' + Math.random(), '1', '', 1, function(db) {
    console.log('creationCallback with version "' + db.version + '"');
    db.changeVersion('', '1', function() {
        console.log('changeVersion callback with version "' + db.version + '"');
    }, function(e) {
        console.log('changeVersion error with version "' + db.version + '"');
        console.log(e.message);
    }, function() {
        console.log('changeVersion success with version "' + db.version + '"')
    });
});


Expected:
    creationCallback with version ""
    changeVersion callback with version ""
    changeVersion success with version "1"

Actual:
    creationCallback with version ""
    changeVersion error with version ""
    current version of the database and `oldVersion` argument do not match


I looked at the WebKit source and I'm pretty sure I know what's going wrong. (I'm pinning these urls to a recent revision so they'll be stable, but the problem exists at head.)


Since a creationCallback was provided, DatabaseBackendBase::performOpenAndVerify will be passed false in for shouldSetVersionInNewDatabase, which means it won't call DatabaseBackendBase::setVersionInDatabase:
https://trac.webkit.org/browser/trunk/Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp?rev=159890#L363

(Sure enough, I closed the browser and checked the corresponding sqlite3 database on disk, and it had an empty __WebKitDatabaseInfoTable__.)


When DatabaseBackendBase::getVersionFromDatabase calls retrieveTextResultFromDatabase, there are no results and it returns a String(), which constructs a NULL String:
https://trac.webkit.org/browser/trunk/Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp?rev=159890#L104


The version is checked in ChangeVersionWrapper::performPreflight, which fails because actualVersion is a NULL String and compares unequal to any String:
https://trac.webkit.org/browser/trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.cpp?rev=159890#L53