diff options
-rw-r--r-- | src/declarative/qml/qmlsqldatabase.cpp | 7 | ||||
-rw-r--r-- | tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp | 13 | ||||
-rw-r--r-- | tests/auto/declarative/sql/data/error-outsidetransaction.js | 17 | ||||
-rw-r--r-- | tests/auto/declarative/sql/tst_sql.cpp | 1 |
4 files changed, 38 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index 3ddfec3..b550f96 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -196,6 +196,11 @@ static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine * return engine->undefinedValue(); } +static QScriptValue qmlsqldatabase_executeSql_outsidetransaction(QScriptContext *context, QScriptEngine *engine) +{ + THROW_SQL(DATABASE_ERR,QmlEngine::tr("executeSql called outside transaction()")); +} + static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEngine *engine) { QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject()); @@ -308,6 +313,8 @@ static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, Q db.transaction(); callback.call(QScriptValue(), QScriptValueList() << tx); + instance.setProperty(QLatin1String("executeSql"), + engine->newFunction(qmlsqldatabase_executeSql_outsidetransaction)); if (engine->hasUncaughtException()) { db.rollback(); } else { diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index fb8bfb3..c3c7977 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -106,6 +106,7 @@ private slots: void signalTriggeredBindings(); void listProperties(); void exceptionClearsOnReeval(); + void exceptionProducesWarning(); void transientErrors(); void shutdownErrors(); void externalScript(); @@ -909,6 +910,18 @@ void tst_qmlecmascript::exceptionClearsOnReeval() QCOMPARE(object->property("test").toBool(), true); } +void tst_qmlecmascript::exceptionProducesWarning() +{ + QmlComponent component(&engine, TEST_FILE("exceptionProducesWarning.qml")); + QString url = component.url().toString(); + + QString warning = "Expected error - QTBUG-6507"; + + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); + MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); + QVERIFY(object != 0); +} + static int transientErrorsMsgCount = 0; static void transientErrorsMsgHandler(QtMsgType, const char *) { diff --git a/tests/auto/declarative/sql/data/error-outsidetransaction.js b/tests/auto/declarative/sql/data/error-outsidetransaction.js new file mode 100644 index 0000000..a7af3bd --- /dev/null +++ b/tests/auto/declarative/sql/data/error-outsidetransaction.js @@ -0,0 +1,17 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + var v; + + try { + db.transaction(function(tx) { v = tx }); + v.executeSql("SELECT 'bad'") + } catch (err) { + if (err.message == "executeSql called outside transaction()") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index 4296279..1e4e6f8 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -152,6 +152,7 @@ void tst_sql::testQml_data() QTest::newRow("iteration-forwardonly") << "data/iteration-forwardonly.js"; QTest::newRow("error-a") << "data/error-a.js"; QTest::newRow("error-notransaction") << "data/error-notransaction.js"; + QTest::newRow("error-outsidetransaction") << "data/error-outsidetransaction.js"; // reuse above QTest::newRow("reopen1") << "data/reopen1.js"; QTest::newRow("reopen2") << "data/reopen2.js"; // re-uses above DB |