Fix bug 20505: Offline Storage API: wrong types of row fields
authorCharles Yin <charles.yin@nokia.com>
Mon, 25 Jul 2011 04:27:52 +0000 (14:27 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 28 Jul 2011 08:04:08 +0000 (10:04 +0200)
fields types should be returned as same as defined, not strings.

Change-Id: I9a0d03acb79850e93cc9266e2595ee61af2089a0
Task-number:QTBUG-20505
Reviewed-on: http://codereview.qt.nokia.com/2065
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/qml/qdeclarativesqldatabase.cpp
tests/auto/declarative/qdeclarativesqldatabase/data/selection.js

index df072ed..fbe5b95 100644 (file)
@@ -51,6 +51,7 @@
 #include <QtSql/qsqlquery.h>
 #include <QtSql/qsqlerror.h>
 #include <QtSql/qsqlrecord.h>
+#include <QtSql/qsqlfield.h>
 #include <QtGui/qdesktopservices.h>
 #include <QtCore/qstack.h>
 #include <QtCore/qcryptographichash.h>
@@ -222,8 +223,13 @@ static v8::Handle<v8::Value> qmlsqldatabase_rows_index(QV8SqlDatabaseResource *r
         // XXX optimize
         v8::Local<v8::Object> row = v8::Object::New();
         for (int ii = 0; ii < record.count(); ++ii) {
-            row->Set(r->engine->toString(record.fieldName(ii)), 
-                     r->engine->toString(record.value(ii).toString()));
+            QVariant v = record.value(ii);
+            if (v.isNull()) {
+                row->Set(r->engine->toString(record.fieldName(ii)), v8::Null());
+            } else {
+                row->Set(r->engine->toString(record.fieldName(ii)),
+                         r->engine->fromVariant(v));
+            }
         }
         return row;
     } else {
index f116eff..4ae40b1 100644 (file)
@@ -7,6 +7,8 @@ function test() {
             tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
             tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
             tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
+            tx.executeSql('CREATE TABLE IF NOT EXISTS TypeTest(num INTEGER, txt1 TEXT, txt2 TEXT)');
+            tx.executeSql("INSERT INTO TypeTest VALUES(1, null, 'hello')");
         }
     );
 
@@ -21,6 +23,22 @@ function test() {
                 r = "passed";
         }
     );
+    if (r == "passed") {
+        db.transaction(function (tx) {
+            r = "";
+            var firstRow = tx.executeSql("SELECT * FROM TypeTest").rows.item(0);
+            if (typeof(firstRow.num) != "number")
+                r += " num:" + firstRow.num+ "type:" + typeof(firstRow.num);
+            if (typeof(firstRow.txt1) != "object" || firstRow.txt1 != null)
+                r += " txt1:" + firstRow.txt1 + " type:" + typeof(firstRow.txt1);
+            if (typeof(firstRow.txt2) != "string" || firstRow.txt2 != "hello")
+                r += " txt2:" + firstRow.txt2 + " type:" + typeof(firstRow.txt2);
+            if (r == "")
+               r = "passed";
+            else
+               r = "SELECT RETURNED VALUES WITH WRONG TYPES " + r;
+        });
+    }
 
     return r;
 }