Details
-
Bug
-
Resolution: Out of scope
-
P2: Important
-
4.6.1
-
None
-
3e6a330d2aa6f139347fe29947721368a5186cc3
Description
The following code executes successfully in Qt 4.6.0 but triggers an array-out-of-bounds access in QSQLiteResultPrivate::fetchNext() in Qt 4.6.1 which I believe is caused by commit 1d6be599f5c12e9ce23bbdf081a103aa62618e15.
Modifying the code below to call setForwardOnly(true) BEFORE QSqlQuery::exec() resolves the problem. I'm not sure if the code below is legal use of the API, though the documentation for setForwardOnly() does not mention anything in this respect.
#include <QtCore/QCoreApplication>
#include <QtCore/QVariant>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtDebug>
int main(int argc, char** argv)
{
QCoreApplication app(argc,argv);
QString connection = "test-database";
{
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE",connection);
database.setDatabaseName(":memory:");
database.open();
QSqlQuery createQuery(database);
createQuery.exec("CREATE TABLE TestTable (id INTEGER PRIMARY KEY AUTOINCREMENT, content VARCHAR NOT NULL)");
createQuery.exec("INSERT INTO TestTable VALUES(0,'FirstRow')");
createQuery.exec("INSERT INTO TestTable VALUES(1,'SecondRow')");
createQuery.exec("INSERT INTO TestTable VALUES(2,'ThirdRow')");
QSqlQuery query(database);
query.exec("SELECT content FROM TestTable");
query.setForwardOnly(true);
while (query.next())
{ qDebug() << query.value(0).toString(); } }
QSqlDatabase::removeDatabase(connection);
}