Skip to content
Browse files

Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-symbian-staging…

… into master-integration

* 'master' of scm.dev.nokia.troll.no:qt/qt-symbian-staging:
  QSQLITE support only one statement at a time
  • Loading branch information...
2 parents 6a76433 + 5722087 commit 65378628d1772204d8254d7ec009c94b0ef2da85 Qt Continuous Integration System committed Dec 2, 2011
Showing with 62 additions and 2 deletions.
  1. +9 −2 src/sql/drivers/sqlite/qsql_sqlite.cpp
  2. +6 −0 src/sql/kernel/qsqlquery.cpp
  3. +47 −0 tests/auto/qsqlquery/tst_qsqlquery.cpp
View
11 src/sql/drivers/sqlite/qsql_sqlite.cpp
@@ -322,19 +322,26 @@ bool QSQLiteResult::prepare(const QString &query)
setSelect(false);
+ const void *pzTail = NULL;
+
#if (SQLITE_VERSION_NUMBER >= 3003011)
int res = sqlite3_prepare16_v2(d->access, query.constData(), (query.size() + 1) * sizeof(QChar),
- &d->stmt, 0);
+ &d->stmt, &pzTail);
#else
int res = sqlite3_prepare16(d->access, query.constData(), (query.size() + 1) * sizeof(QChar),
- &d->stmt, 0);
+ &d->stmt, &pzTail);
#endif
if (res != SQLITE_OK) {
setLastError(qMakeError(d->access, QCoreApplication::translate("QSQLiteResult",
"Unable to execute statement"), QSqlError::StatementError, res));
d->finalize();
return false;
+ } else if (pzTail && !QString(reinterpret_cast<const QChar *>(pzTail)).trimmed().isEmpty()) {
+ setLastError(qMakeError(d->access, QCoreApplication::translate("QSQLiteResult",
+ "Unable to execute multiple statements at a time"), QSqlError::StatementError, SQLITE_MISUSE));
+ d->finalize();
+ return false;
}
return true;
}
View
6 src/sql/kernel/qsqlquery.cpp
@@ -338,6 +338,9 @@ bool QSqlQuery::isNull(int field) const
Note that the last error for this query is reset when exec() is
called.
+ For SQLite, the query string can contain only one statement at a time.
+ If more than one statements is give, the function returns false.
+
Example:
\snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 34
@@ -887,6 +890,9 @@ void QSqlQuery::clear()
syntactically wrong query succeeds, but every consecutive exec()
will fail.
+ For SQLite, the query string can contain only one statement at a time.
+ If more than one statements are give, the function returns false.
+
Example:
\snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 9
View
47 tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -213,6 +213,8 @@ private slots:
void QTBUG_5765();
void QTBUG_14132_data() { generic_data("QOCI"); }
void QTBUG_14132();
+ void QTBUG_21884_data() { generic_data("QSQLITE"); }
+ void QTBUG_21884();
void sqlite_constraint_data() { generic_data("QSQLITE"); }
void sqlite_constraint();
@@ -328,6 +330,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
<< qTableName("bug6421", __FILE__).toUpper()
<< qTableName("bug5765", __FILE__)
<< qTableName("bug6852", __FILE__)
+ << qTableName("bug21884", __FILE__)
<< qTableName( "qtest_lockedtable", __FILE__ )
<< qTableName( "Planet", __FILE__ )
<< qTableName( "task_250026", __FILE__ )
@@ -3104,6 +3107,50 @@ void tst_QSqlQuery::QTBUG_5765()
QCOMPARE(q.value(0).toInt(), 123);
}
+/**
+* This test case tests multiple statements in one execution.
+* Sqlite driver doesn't support multiple statement at one time.
+* If more than one statement is given, the exec or prepare function
+* return failure to the client.
+*/
+void tst_QSqlQuery::QTBUG_21884()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+
+ QSqlQuery q(db);
+
+ QStringList stList;
+ QString tableName(qTableName("bug21884", __FILE__ ));
+ stList << "create table " + tableName + "(id integer primary key, note string)";
+ stList << "select * from " + tableName + ";";
+ stList << "select * from " + tableName + "; \t\n\r";
+ stList << "drop table " + tableName;
+
+
+ foreach (const QString& st, stList) {
+ QVERIFY_SQL(q, exec(st));
+ }
+
+ foreach (const QString& st, stList) {
+ QVERIFY_SQL(q, prepare(st));
+ QVERIFY_SQL(q, exec());
+ }
+
+ stList.clear();
+ stList << "create table " + tableName + "(id integer primary key); select * from " + tableName;
+ stList << "create table " + tableName + "(id integer primary key); syntax error!;";
+ stList << "create table " + tableName + "(id integer primary key);;";
+ stList << "create table " + tableName + "(id integer primary key);\'\"\a\b\b\v";
+
+ foreach (const QString&st , stList) {
+ QVERIFY2(!q.prepare(st), qPrintable(QString("the statement is expected to fail! ") + st));
+ QVERIFY2(!q.exec(st), qPrintable(QString("the statement is expected to fail! ") + st));
+ }
+}
+
+
void tst_QSqlQuery::oraOCINumber()
{
QFETCH( QString, dbName );

0 comments on commit 6537862

Please sign in to comment.
Something went wrong with that request. Please try again.