Fix positional binding values order in QSqlQuery
Adapt the stringification code, that is used to produce the keys for QSqlQuery::boundValues() return value, to keep the right order of the binding values. Task-number: QTBUG-12186 Change-Id: Ic11a455bfd9ffd1418b1b021ce5cf78cae9b4504 [ChangeLog][QtSql] Fixed the order of values with positional binding in a QSqlQuery Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
parent
943fc7d782
commit
1f6e461533
@ -64,15 +64,20 @@ QString QSqlResultPrivate::holderAt(int index) const
|
||||
// return a unique id for bound names
|
||||
QString QSqlResultPrivate::fieldSerial(int i) const
|
||||
{
|
||||
ushort arr[] = { ':', 'f', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
ushort *ptr = &arr[1];
|
||||
ushort arr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
ushort *end = &arr[(sizeof(arr)/sizeof(*arr))];
|
||||
ushort *ptr = end;
|
||||
|
||||
while (i > 0) {
|
||||
*(++ptr) = 'a' + i % 16;
|
||||
*(--ptr) = 'a' + i % 16;
|
||||
i >>= 4;
|
||||
}
|
||||
|
||||
return QString(reinterpret_cast<const QChar *>(arr), int(ptr - arr) + 1);
|
||||
const int nb = end - ptr;
|
||||
*(--ptr) = 'a' + nb;
|
||||
*(--ptr) = ':';
|
||||
|
||||
return QString::fromUtf16(ptr, int(end - ptr));
|
||||
}
|
||||
|
||||
static bool qIsAlnum(QChar ch)
|
||||
|
@ -211,6 +211,8 @@ private slots:
|
||||
void QTBUG_6852();
|
||||
void QTBUG_5765_data() { generic_data("QMYSQL"); }
|
||||
void QTBUG_5765();
|
||||
void QTBUG_12186_data() { generic_data("QSQLITE"); }
|
||||
void QTBUG_12186();
|
||||
void QTBUG_14132_data() { generic_data("QOCI"); }
|
||||
void QTBUG_14132();
|
||||
void QTBUG_18435_data() { generic_data("QODBC"); }
|
||||
@ -3054,6 +3056,27 @@ void tst_QSqlQuery::QTBUG_551()
|
||||
QCOMPARE(res_outLst[2].toString(), QLatin1String("3. Value is 2"));
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::QTBUG_12186()
|
||||
{
|
||||
QFETCH( QString, dbName );
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
|
||||
// make sure that query.boundValues() returns the values in the right order even for more than 16 placeholders
|
||||
QSqlQuery query(db);
|
||||
query.prepare("INSERT INTO person (col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
QList<QVariant> values;
|
||||
|
||||
for (int i = 0; i < 18; ++i)
|
||||
values << i;
|
||||
|
||||
foreach (QVariant v, values)
|
||||
query.bindValue(v.toInt(), v);
|
||||
|
||||
QCOMPARE(query.boundValues().values(), values);
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::QTBUG_14132()
|
||||
{
|
||||
QFETCH( QString, dbName );
|
||||
|
Loading…
Reference in New Issue
Block a user