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>
This commit is contained in:
parent
5fbb17c397
commit
13fe0ab5de
@ -487,20 +487,6 @@ static QList<QVariant> toList(char** buf, int count, T* = 0)
|
|||||||
}
|
}
|
||||||
return res;
|
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,
|
static char* readArrayBuffer(QList<QVariant>& list, char *buffer, short curDim,
|
||||||
short* numElements, ISC_ARRAY_DESC *arrayDesc)
|
short* numElements, ISC_ARRAY_DESC *arrayDesc)
|
||||||
@ -531,7 +517,7 @@ static char* readArrayBuffer(QList<QVariant>& list, char *buffer, short curDim,
|
|||||||
}
|
}
|
||||||
break; }
|
break; }
|
||||||
case blr_long:
|
case blr_long:
|
||||||
valList = toList<long>(&buffer, numElements[dim], static_cast<long *>(0));
|
valList = toList<int>(&buffer, numElements[dim], static_cast<int *>(0));
|
||||||
break;
|
break;
|
||||||
case blr_short:
|
case blr_short:
|
||||||
valList = toList<short>(&buffer, numElements[dim]);
|
valList = toList<short>(&buffer, numElements[dim]);
|
||||||
@ -581,7 +567,7 @@ QVariant QIBaseResultPrivate::fetchArray(int pos, ISC_QUAD *arr)
|
|||||||
return list;
|
return list;
|
||||||
|
|
||||||
QByteArray relname(sqlda->sqlvar[pos].relname, sqlda->sqlvar[pos].relname_length);
|
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);
|
isc_array_lookup_bounds(status, &ibase, &trans, relname.data(), sqlname.data(), &desc);
|
||||||
if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
|
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;
|
ISC_ARRAY_DESC desc;
|
||||||
|
|
||||||
QByteArray relname(inda->sqlvar[column].relname, inda->sqlvar[column].relname_length);
|
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);
|
isc_array_lookup_bounds(status, &ibase, &trans, relname.data(), sqlname.data(), &desc);
|
||||||
if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
|
if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
|
||||||
|
@ -259,6 +259,9 @@ private slots:
|
|||||||
void dateTime_data();
|
void dateTime_data();
|
||||||
void dateTime();
|
void dateTime();
|
||||||
|
|
||||||
|
void ibaseArray_data() { generic_data("QIBASE"); }
|
||||||
|
void ibaseArray();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// returns all database connections
|
// returns all database connections
|
||||||
void generic_data(const QString &engine=QString());
|
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 )
|
QTEST_MAIN( tst_QSqlQuery )
|
||||||
#include "tst_qsqlquery.moc"
|
#include "tst_qsqlquery.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user