diff options
author | Bill King <bking@trolltech.com> | 2009-04-16 22:54:31 (GMT) |
---|---|---|
committer | Bill King <bking@trolltech.com> | 2009-04-16 23:09:40 (GMT) |
commit | 90bc01d2854f5c7024027c6419ae22feff57aa71 (patch) | |
tree | 60149e6df41387f32cd67bccf0f465db3cb3ff01 | |
parent | 90d7509e4a1543e43a49bfb25dd672d824c4fde3 (diff) | |
download | Qt-90bc01d2854f5c7024027c6419ae22feff57aa71.zip Qt-90bc01d2854f5c7024027c6419ae22feff57aa71.tar.gz Qt-90bc01d2854f5c7024027c6419ae22feff57aa71.tar.bz2 |
Fixes long strings getting truncated by the ODBC Driver.
This test has always been wrong/confusing. Fix it to work, and make sense.
Task-number: 250026
Revby: Lincoln Ramsay
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 34 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index d6423ae..2a83fe6 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -355,7 +355,7 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni } else { fieldVal += QString::fromAscii(buf, rSize); } - if (fieldVal.size() + lengthIndicator >= colSize) { + if (lengthIndicator - fieldVal.size() <= 0) { // workaround for Drivermanagers that don't return SQL_NO_DATA break; } diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 8d77589..074f16f 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -179,6 +179,10 @@ private slots: void task_217003(); #endif + void task_250026_data() { generic_data("QODBC"); } + void task_250026(); + + private: // returns all database connections void generic_data(const QString &engine=QString()); @@ -293,6 +297,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) #ifdef NOT_READY_YET tablenames << qTableName( "Planet" ); #endif + tablenames << qTableName( "task_250026" ); tst_Databases::safeDropTables( db, tablenames ); } @@ -2677,5 +2682,34 @@ void tst_QSqlQuery::task_217003() } #endif +void tst_QSqlQuery::task_250026() +{ + QString data258, data1026; + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + QSqlQuery q( db ); + + QString tableName = qTableName( "task_250026" ); + + if ( !q.exec( "create table " + tableName + " (longfield varchar(1100))" ) ) { + qDebug() << "Error" << q.lastError(); + QSKIP( "Db doesn't support \"1100\" as a size for fields", SkipSingle ); + } + + data258.fill( 'A', 258 ); + data1026.fill( 'A', 1026 ); + QVERIFY_SQL( q, prepare( "insert into " + tableName + "(longfield) VALUES (:longfield)" ) ); + q.bindValue( "longfield", data258 ); + QVERIFY_SQL( q, exec() ); + q.bindValue( "longfield", data1026 ); + QVERIFY_SQL( q, exec() ); + QVERIFY_SQL( q, exec( "select * from " + tableName ) ); + QVERIFY_SQL( q, next() ); + QCOMPARE( q.value( 0 ).toString().length(), data258.length() ); + QVERIFY_SQL( q, next() ); + QCOMPARE( q.value( 0 ).toString().length(), data1026.length() ); +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" |