From dd478a4b829921c9dfeb23110177a30f32eca5af Mon Sep 17 00:00:00 2001 From: Bill King Date: Tue, 20 Apr 2010 12:07:22 +1000 Subject: Fix sqlite driver doesn't return error message RAISE by a trigger. Task-number: QTBUG-7988 Reviewed-by: Justin McPherson --- src/sql/drivers/sqlite/qsql_sqlite.cpp | 1 + tests/auto/qsqlquery/tst_qsqlquery.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index d3be304..9b9d30b 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -259,6 +259,7 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i q->setAt(QSql::AfterLastRow); sqlite3_reset(stmt); return false; + case SQLITE_CONSTRAINT: case SQLITE_ERROR: // SQLITE_ERROR is a generic error code and we must call sqlite3_reset() // to get the specific error message. diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index db3a929..c7a61a5 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -209,6 +209,8 @@ private slots: void QTBUG_6852(); void QTBUG_5765_data() { generic_data("QMYSQL"); } void QTBUG_5765(); + void sqlite_constraint_data() { generic_data("QSQLITE"); } + void sqlite_constraint(); #if 0 void benchmark_data() { generic_data(); } @@ -3078,6 +3080,31 @@ void tst_QSqlQuery::QTBUG_5765() QCOMPARE(q.value(0).toInt(), 123); } +void tst_QSqlQuery::sqlite_constraint() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + if (db.driverName() != QLatin1String("QSQLITE")) { + QSKIP("Sqlite3 specific test", SkipSingle); + return; + } + + QSqlQuery q(db); + const QString trigger(qTableName("test_constraint", __FILE__)); + + QVERIFY_SQL(q, exec("CREATE TEMP TRIGGER "+trigger+" BEFORE DELETE ON "+qtest+ + "\nFOR EACH ROW " + "\nBEGIN" + "\n SELECT RAISE(ABORT, 'Raised Abort successfully');" + "\nEND;" + )); + + QVERIFY(!q.exec("DELETE FROM "+qtest)); + QCOMPARE(q.lastError().databaseText(), QLatin1String("Raised Abort successfully")); +} + #if 0 void tst_QSqlQuery::benchmark() { -- cgit v0.12