Title: [129886] trunk
Revision
129886
Author
[email protected]
Date
2012-09-28 06:44:43 -0700 (Fri, 28 Sep 2012)

Log Message

[WebDatabase] Error code should be CONSTRAINT_ERR if a statement fails due to a constraint failure
https://bugs.webkit.org/show_bug.cgi?id=97897

Patch by Christophe Dumez <[email protected]> on 2012-09-28
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Use CONSTRAINT_ERR error code instead of the generic DATABASE_ERR
when a statement fails due to a constraint failure. This is documented
in the W3C specification:
http://dev.w3.org/html5/webdatabase/#dom-sqlexception-code-constraint

Tests: storage/websql/sql-error-codes.html

* Modules/webdatabase/SQLStatement.cpp:
(WebCore::SQLStatement::execute):
* Modules/webdatabase/SQLStatementSync.cpp:
(WebCore::SQLStatementSync::execute):
* platform/sql/SQLiteDatabase.cpp:
(WebCore):
* platform/sql/SQLiteDatabase.h:
(WebCore):

LayoutTests:

Update storage/websql/sql-error-codes.html test case to check
that the CONSTRAINT_ERR error code is used when a statement
fails due to a constraint failure.

* platform/chromium/storage/websql/sql-error-codes-expected.txt:
* storage/websql/sql-error-codes-expected.txt:
* storage/websql/sql-error-codes.js:
(testConstraintFailure):
(runTest):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (129885 => 129886)


--- trunk/LayoutTests/ChangeLog	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/LayoutTests/ChangeLog	2012-09-28 13:44:43 UTC (rev 129886)
@@ -1,3 +1,20 @@
+2012-09-28  Christophe Dumez  <[email protected]>
+
+        [WebDatabase] Error code should be CONSTRAINT_ERR if a statement fails due to a constraint failure
+        https://bugs.webkit.org/show_bug.cgi?id=97897
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Update storage/websql/sql-error-codes.html test case to check
+        that the CONSTRAINT_ERR error code is used when a statement
+        fails due to a constraint failure.
+
+        * platform/chromium/storage/websql/sql-error-codes-expected.txt:
+        * storage/websql/sql-error-codes-expected.txt:
+        * storage/websql/sql-error-codes.js:
+        (testConstraintFailure):
+        (runTest):
+
 2012-09-28  Sudarsana Nagineni  <[email protected]>
 
         editing/pasteboard/paste-removing-iframe.html crashes on EFL bots

Modified: trunk/LayoutTests/platform/chromium/storage/websql/sql-error-codes-expected.txt (129885 => 129886)


--- trunk/LayoutTests/platform/chromium/storage/websql/sql-error-codes-expected.txt	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/LayoutTests/platform/chromium/storage/websql/sql-error-codes-expected.txt	2012-09-28 13:44:43 UTC (rev 129886)
@@ -7,5 +7,6 @@
 PASS: expected and got error code SYNTAX_ERR
 PASS: expected and got error code UNKNOWN_ERR
 PASS: expected and got error code QUOTA_ERR
+PASS: expected and got error code CONSTRAINT_ERR
 PASS: expected and got error code VERSION_ERR
 

Modified: trunk/LayoutTests/storage/websql/sql-error-codes-expected.txt (129885 => 129886)


--- trunk/LayoutTests/storage/websql/sql-error-codes-expected.txt	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/LayoutTests/storage/websql/sql-error-codes-expected.txt	2012-09-28 13:44:43 UTC (rev 129886)
@@ -7,5 +7,6 @@
 PASS: expected and got error code SYNTAX_ERR
 PASS: expected and got error code UNKNOWN_ERR
 PASS: expected and got error code QUOTA_ERR
+PASS: expected and got error code CONSTRAINT_ERR
 PASS: expected and got error code VERSION_ERR
 

Modified: trunk/LayoutTests/storage/websql/sql-error-codes.js (129885 => 129886)


--- trunk/LayoutTests/storage/websql/sql-error-codes.js	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/LayoutTests/storage/websql/sql-error-codes.js	2012-09-28 13:44:43 UTC (rev 129886)
@@ -4,7 +4,7 @@
         testRunner.notifyDone();
 }
 
-var TOTAL_TESTS = 7;
+var TOTAL_TESTS = 8;
 var testsRun = 0;
 function transactionErrorCallback(error, expectedErrorCodeName)
 {
@@ -79,6 +79,16 @@
                     }, "QUOTA_ERR");
 }
 
+function testConstraintFailure(db)
+{
+    testTransaction(db,
+                    function(tx) {
+                        tx.executeSql("CREATE TABLE IF NOT EXISTS ConstraintTest (Foo INTEGER PRIMARY KEY)");
+                        tx.executeSql("INSERT INTO ConstraintTest VALUES (1)");
+                        tx.executeSql("INSERT INTO ConstraintTest VALUES (1)");
+                    }, "CONSTRAINT_ERR");
+}
+
 function testVersionMismatch(db)
 {
     // Use another DB handle to change the version. However, in order to make sure that the DB version is not
@@ -110,5 +120,6 @@
     testIncorrectNumberOfBindParameters(db);
     testBindParameterOfWrongType(db);
     testQuotaExceeded(db);
+    testConstraintFailure(db);
     testVersionMismatch(db);
 }

Modified: trunk/Source/WebCore/ChangeLog (129885 => 129886)


--- trunk/Source/WebCore/ChangeLog	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/Source/WebCore/ChangeLog	2012-09-28 13:44:43 UTC (rev 129886)
@@ -1,3 +1,26 @@
+2012-09-28  Christophe Dumez  <[email protected]>
+
+        [WebDatabase] Error code should be CONSTRAINT_ERR if a statement fails due to a constraint failure
+        https://bugs.webkit.org/show_bug.cgi?id=97897
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Use CONSTRAINT_ERR error code instead of the generic DATABASE_ERR
+        when a statement fails due to a constraint failure. This is documented
+        in the W3C specification:
+        http://dev.w3.org/html5/webdatabase/#dom-sqlexception-code-constraint
+
+        Tests: storage/websql/sql-error-codes.html
+
+        * Modules/webdatabase/SQLStatement.cpp:
+        (WebCore::SQLStatement::execute):
+        * Modules/webdatabase/SQLStatementSync.cpp:
+        (WebCore::SQLStatementSync::execute):
+        * platform/sql/SQLiteDatabase.cpp:
+        (WebCore):
+        * platform/sql/SQLiteDatabase.h:
+        (WebCore):
+
 2012-09-28  Pavel Feldman  <[email protected]>
 
         Web Inspector: split ProgressBar.js into Progress.js and ProgressIndicator.js

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLStatement.cpp (129885 => 129886)


--- trunk/Source/WebCore/Modules/webdatabase/SQLStatement.cpp	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLStatement.cpp	2012-09-28 13:44:43 UTC (rev 129886)
@@ -141,6 +141,10 @@
         // Return the Quota error - the delegate will be asked for more space and this statement might be re-run
         setFailureDueToQuota(db);
         return false;
+    } else if (result == SQLResultConstraint) {
+        db->reportExecuteStatementResult(6, SQLError::CONSTRAINT_ERR, result);
+        m_error = SQLError::create(SQLError::CONSTRAINT_ERR, "could not execute statement due to a constaint failure", result, database->lastErrorMsg());
+        return false;
     } else {
         db->reportExecuteStatementResult(5, SQLError::DATABASE_ERR, result);
         m_error = SQLError::create(SQLError::DATABASE_ERR, "could not execute statement", result, database->lastErrorMsg());

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLStatementSync.cpp (129885 => 129886)


--- trunk/Source/WebCore/Modules/webdatabase/SQLStatementSync.cpp	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLStatementSync.cpp	2012-09-28 13:44:43 UTC (rev 129886)
@@ -118,6 +118,10 @@
         ec = SQLException::QUOTA_ERR;
         db->setLastErrorMessage("there was not enough remaining storage space");
         return 0;
+    } else if (result == SQLResultConstraint) {
+        ec = SQLException::CONSTRAINT_ERR;
+        db->setLastErrorMessage("statement failed due to a constraint failure");
+        return 0;
     } else {
         ec = SQLException::DATABASE_ERR;
         db->setLastErrorMessage("could not execute statement", result, database->lastErrorMsg());

Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp (129885 => 129886)


--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp	2012-09-28 13:44:43 UTC (rev 129886)
@@ -45,6 +45,7 @@
 const int SQLResultSchema = SQLITE_SCHEMA;
 const int SQLResultFull = SQLITE_FULL;
 const int SQLResultInterrupt = SQLITE_INTERRUPT;
+const int SQLResultConstraint = SQLITE_CONSTRAINT;
 
 static const char notOpenErrorMessage[] = "database is not open";
 

Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.h (129885 => 129886)


--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.h	2012-09-28 13:38:08 UTC (rev 129885)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.h	2012-09-28 13:44:43 UTC (rev 129886)
@@ -50,6 +50,7 @@
 extern const int SQLResultSchema;
 extern const int SQLResultFull;
 extern const int SQLResultInterrupt;
+extern const int SQLResultConstraint;
 
 class SQLiteDatabase {
     WTF_MAKE_NONCOPYABLE(SQLiteDatabase);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to