From db6c099e42f96710f2ad09f6d3d2c94ffba600d7 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Mon, 25 Jul 2011 14:27:52 +1000 Subject: [PATCH] Fix bug 20505: Offline Storage API: wrong types of row fields 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 Reviewed-by: Martin Jones --- src/declarative/qml/qdeclarativesqldatabase.cpp | 10 ++++++++-- .../qdeclarativesqldatabase/data/selection.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativesqldatabase.cpp b/src/declarative/qml/qdeclarativesqldatabase.cpp index df072ed..fbe5b95 100644 --- a/src/declarative/qml/qdeclarativesqldatabase.cpp +++ b/src/declarative/qml/qdeclarativesqldatabase.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -222,8 +223,13 @@ static v8::Handle qmlsqldatabase_rows_index(QV8SqlDatabaseResource *r // XXX optimize v8::Local 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 { diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js b/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js index f116eff..4ae40b1 100644 --- a/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js @@ -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; } -- 2.7.4