Kimmo Kinnunen <kimmok@iki.fi>
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2008 07:18:39 +0000 (07:18 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2008 07:18:39 +0000 (07:18 +0000)
Reviewed by Tim Hatcher.

Fixes: http://bugs.webkit.org/show_bug.cgi?id=17191
HTML5: Client-side database queries should return values of type number
Test: storage/sql-data-types.html

Make the DB queries return a value as a number if it was inserted
as a number to the database.
* platform/sql/SQLiteStatement.cpp:
(WebCore::SQLiteStatement::getColumnValue): new member function to return SQLValues
* platform/sql/SQLiteStatement.h:
* storage/SQLStatement.cpp:
(WebCore::SQLStatement::execute): use getColumnValue instead of getColumnText

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30087 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
WebCore/ChangeLog
WebCore/platform/sql/SQLiteStatement.cpp
WebCore/platform/sql/SQLiteStatement.h
WebCore/storage/SQLStatement.cpp

index 4ad6487..533f7f1 100644 (file)
@@ -1,3 +1,14 @@
+2008-02-06  Kimmo Kinnunen  <kimmok@iki.fi>
+
+        Reviewed by Tim Hatcher.
+
+        Test for: http://bugs.webkit.org/show_bug.cgi?id=17191
+        HTML5: Client-side database queries should return values of type number
+
+        * storage/sql-data-types-expected.txt: Added.
+        * storage/sql-data-types.html: Added.
+        * storage/sql-data-types.js: Added.
+
 2008-02-07  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
index f725fd6..49bef09 100644 (file)
@@ -1,3 +1,19 @@
+2008-02-06  Kimmo Kinnunen  <kimmok@iki.fi>
+
+        Reviewed by Tim Hatcher.
+
+        Fixes: http://bugs.webkit.org/show_bug.cgi?id=17191
+        HTML5: Client-side database queries should return values of type number
+        Test: storage/sql-data-types.html
+
+        Make the DB queries return a value as a number if it was inserted
+        as a number to the database.
+        * platform/sql/SQLiteStatement.cpp:
+        (WebCore::SQLiteStatement::getColumnValue): new member function to return SQLValues
+        * platform/sql/SQLiteStatement.h:
+        * storage/SQLStatement.cpp:
+        (WebCore::SQLStatement::execute): use getColumnValue instead of getColumnText
+
 2008-02-07  Ada Chan  <adachan@apple.com>
 
         <rdar://problem/5292433> certificate authentication support broken in Safari 3.0
index 35c386b..ac96034 100644 (file)
@@ -236,7 +236,35 @@ String SQLiteStatement::getColumnName(int col)
         return String();
     return String(reinterpret_cast<const UChar*>(sqlite3_column_name16(m_statement, col)));
 }
-    
+
+SQLValue SQLiteStatement::getColumnValue(int col)
+{
+    ASSERT(col >= 0);
+    if (!m_statement)
+        if (prepareAndStep() != SQLITE_ROW)
+            return SQLValue();
+    if (columnCount() <= col)
+        return SQLValue();
+
+    // SQLite is typed per value. optional column types are
+    // "(mostly) ignored"
+    sqlite3_value* value = sqlite3_column_value(m_statement, col);
+    switch (sqlite3_value_type(value)) {
+        case SQLITE_INTEGER:    // SQLValue and JS don't represent integers, so use FLOAT -case
+        case SQLITE_FLOAT:
+            return SQLValue(sqlite3_value_double(value));
+        case SQLITE_BLOB:       // SQLValue and JS don't represent blobs, so use TEXT -case
+        case SQLITE_TEXT:
+            return SQLValue(String(reinterpret_cast<const UChar*>(sqlite3_value_text16(value))));
+        case SQLITE_NULL:
+            return SQLValue();
+        default:
+            break;
+    }
+    ASSERT_NOT_REACHED();
+    return SQLValue();
+}
+
 String SQLiteStatement::getColumnText(int col)
 {
     ASSERT(col >= 0);
index ab2f566..5df4731 100644 (file)
@@ -71,6 +71,7 @@ public:
     int columnCount();
     
     String getColumnName(int col);
+    SQLValue getColumnValue(int col);
     String getColumnText(int col);
     double getColumnDouble(int col);
     int getColumnInt(int col);
index 52fbbab..102d8a2 100644 (file)
@@ -107,10 +107,8 @@ bool SQLStatement::execute(Database* db)
             rows->addColumn(statement.getColumnName(i));
 
         do {
-            for (int i = 0; i < columnCount; i++) {
-                // FIXME: Look at the column type?
-                rows->addResult(statement.getColumnText(i));
-            }
+            for (int i = 0; i < columnCount; i++)
+                rows->addResult(statement.getColumnValue(i));
 
             result = statement.step();
         } while (result == SQLResultRow);