summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-08-02 01:40:37 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-09-08 08:02:14 +0200
commit13fe0ab5de63871cdacd41a68608b97b29edb89d (patch)
tree91cd83f62fdae7bc44962e37c933a5e39ae7d536
parent5fbb17c39785ed2c80219c9c0ea97879e371d490 (diff)
Interbase: Correctly read/write arrays to the database
The fix ensures that it can find the column for the array correctly when reading/writing and also handles the integer typed arrays correctly too. Pick-to: 5.15 Fixes: QTBUG-83409 Change-Id: I92d982bdf0927e6ebc6dce84fec9ad6c44c26c25 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
-rw-r--r--src/plugins/sqldrivers/ibase/qsql_ibase.cpp20
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp29
2 files changed, 32 insertions, 17 deletions
diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp
index 4c1178f3c3..1754492fe7 100644
--- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp
+++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp
@@ -487,20 +487,6 @@ static QList<QVariant> toList(char** buf, int count, T* = 0)
}
return res;
}
-/* char** ? seems like bad influence from oracle ... */
-template<>
-QList<QVariant> toList<long>(char** buf, int count, long*)
-{
- QList<QVariant> res;
- for (int i = 0; i < count; ++i) {
- if (sizeof(int) == sizeof(long))
- res.append(int((*(long*)(*buf))));
- else
- res.append((qint64)(*(long*)(*buf)));
- *buf += sizeof(long);
- }
- return res;
-}
static char* readArrayBuffer(QList<QVariant>& list, char *buffer, short curDim,
short* numElements, ISC_ARRAY_DESC *arrayDesc)
@@ -531,7 +517,7 @@ static char* readArrayBuffer(QList<QVariant>& list, char *buffer, short curDim,
}
break; }
case blr_long:
- valList = toList<long>(&buffer, numElements[dim], static_cast<long *>(0));
+ valList = toList<int>(&buffer, numElements[dim], static_cast<int *>(0));
break;
case blr_short:
valList = toList<short>(&buffer, numElements[dim]);
@@ -581,7 +567,7 @@ QVariant QIBaseResultPrivate::fetchArray(int pos, ISC_QUAD *arr)
return list;
QByteArray relname(sqlda->sqlvar[pos].relname, sqlda->sqlvar[pos].relname_length);
- QByteArray sqlname(sqlda->sqlvar[pos].aliasname, sqlda->sqlvar[pos].aliasname_length);
+ QByteArray sqlname(sqlda->sqlvar[pos].sqlname, sqlda->sqlvar[pos].sqlname_length);
isc_array_lookup_bounds(status, &ibase, &trans, relname.data(), sqlname.data(), &desc);
if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
@@ -768,7 +754,7 @@ bool QIBaseResultPrivate::writeArray(int column, const QList<QVariant> &list)
ISC_ARRAY_DESC desc;
QByteArray relname(inda->sqlvar[column].relname, inda->sqlvar[column].relname_length);
- QByteArray sqlname(inda->sqlvar[column].aliasname, inda->sqlvar[column].aliasname_length);
+ QByteArray sqlname(inda->sqlvar[column].sqlname, inda->sqlvar[column].sqlname_length);
isc_array_lookup_bounds(status, &ibase, &trans, relname.data(), sqlname.data(), &desc);
if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 8b057ec039..9e79a25f68 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -259,6 +259,9 @@ private slots:
void dateTime_data();
void dateTime();
+ void ibaseArray_data() { generic_data("QIBASE"); }
+ void ibaseArray();
+
private:
// returns all database connections
void generic_data(const QString &engine=QString());
@@ -4764,5 +4767,31 @@ void tst_QSqlQuery::mysql_timeType()
}
}
+void tst_QSqlQuery::ibaseArray()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+
+ const auto arrayTable = qTableName("ibasearray", __FILE__, db);
+ tst_Databases::safeDropTable(db, arrayTable);
+ QSqlQuery qry(db);
+ QVERIFY_SQL(qry, exec("create table " + arrayTable + " (intData int[0:4], longData bigint[5], "
+ "charData varchar(255)[5])"));
+ QVERIFY_SQL(qry, prepare("insert into " + arrayTable + " (intData, longData, charData) "
+ "values(?, ?, ?)"));
+ const auto intArray = QVariant{QVariantList{1, 2, 3, 4711, 815}};
+ const auto charArray = QVariant{QVariantList{"AAA", "BBB", "CCC", "DDD", "EEE"}};
+ qry.bindValue(0, intArray);
+ qry.bindValue(1, intArray);
+ qry.bindValue(2, charArray);
+ QVERIFY_SQL(qry, exec());
+ QVERIFY_SQL(qry, exec("select * from " + arrayTable));
+ QVERIFY(qry.next());
+ QCOMPARE(qry.value(0).toList(), intArray.toList());
+ QCOMPARE(qry.value(1).toList(), intArray.toList());
+ QCOMPARE(qry.value(2).toList(), charArray.toList());
+}
+
QTEST_MAIN( tst_QSqlQuery )
#include "tst_qsqlquery.moc"