Handle the 'real' datatype correctly in the SQLite driver
The 'real' datatype should be seen as a QVariant::Double type and not as a QVariant::String type otherwise it does not get presented correctly when using a non Qt application to access it. Test is included for QSqlQuery. Task-number: QTBUG-16373 Change-Id: Ie323ce49eb95e4d6bb4c3814ba9a957a63f4b259 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com> (cherry picked from commit b23631015c23a49e3b4d296ea0a6266bfce3d4f1) Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
parent
1175ec444f
commit
5bab4744ba
@ -95,6 +95,7 @@ static QVariant::Type qGetColumnType(const QString &tpName)
|
|||||||
return QVariant::Int;
|
return QVariant::Int;
|
||||||
if (typeName == QLatin1String("double")
|
if (typeName == QLatin1String("double")
|
||||||
|| typeName == QLatin1String("float")
|
|| typeName == QLatin1String("float")
|
||||||
|
|| typeName == QLatin1String("real")
|
||||||
|| typeName.startsWith(QLatin1String("numeric")))
|
|| typeName.startsWith(QLatin1String("numeric")))
|
||||||
return QVariant::Double;
|
return QVariant::Double;
|
||||||
if (typeName == QLatin1String("blob"))
|
if (typeName == QLatin1String("blob"))
|
||||||
|
@ -965,7 +965,7 @@ void tst_QSqlDatabase::recordSQLite()
|
|||||||
|
|
||||||
FieldDef("integer", QVariant::Int, QVariant(13)),
|
FieldDef("integer", QVariant::Int, QVariant(13)),
|
||||||
FieldDef("int", QVariant::Int, QVariant(12)),
|
FieldDef("int", QVariant::Int, QVariant(12)),
|
||||||
FieldDef("real", QVariant::String, QVariant(1.234567890123456)),
|
FieldDef("real", QVariant::Double, QVariant(1.234567890123456)),
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
|
@ -219,6 +219,9 @@ private slots:
|
|||||||
void sqlite_constraint_data() { generic_data("QSQLITE"); }
|
void sqlite_constraint_data() { generic_data("QSQLITE"); }
|
||||||
void sqlite_constraint();
|
void sqlite_constraint();
|
||||||
|
|
||||||
|
void sqlite_real_data() { generic_data("QSQLITE"); }
|
||||||
|
void sqlite_real();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// returns all database connections
|
// returns all database connections
|
||||||
void generic_data(const QString &engine=QString());
|
void generic_data(const QString &engine=QString());
|
||||||
@ -3309,5 +3312,32 @@ void tst_QSqlQuery::sqlite_constraint()
|
|||||||
QCOMPARE(q.lastError().databaseText(), QLatin1String("Raised Abort successfully"));
|
QCOMPARE(q.lastError().databaseText(), QLatin1String("Raised Abort successfully"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QSqlQuery::sqlite_real()
|
||||||
|
{
|
||||||
|
QFETCH(QString, dbName);
|
||||||
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
|
CHECK_DATABASE(db);
|
||||||
|
const QString tableName(qTableName("sqliterealtype", __FILE__));
|
||||||
|
tst_Databases::safeDropTable( db, tableName );
|
||||||
|
|
||||||
|
QSqlQuery q(db);
|
||||||
|
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INTEGER, realVal REAL)"));
|
||||||
|
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, realVal) VALUES (1, 2.3)"));
|
||||||
|
QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName));
|
||||||
|
QVERIFY(q.next());
|
||||||
|
QCOMPARE(q.value(0).toDouble(), 2.3);
|
||||||
|
QCOMPARE(q.record().field(0).type(), QVariant::Double);
|
||||||
|
|
||||||
|
q.prepare("INSERT INTO " + tableName + " (id, realVal) VALUES (?, ?)");
|
||||||
|
QVariant var((double)5.6);
|
||||||
|
q.addBindValue(4);
|
||||||
|
q.addBindValue(var);
|
||||||
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
|
QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName + " WHERE ID=4"));
|
||||||
|
QVERIFY(q.next());
|
||||||
|
QCOMPARE(q.value(0).toDouble(), 5.6);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN( tst_QSqlQuery )
|
QTEST_MAIN( tst_QSqlQuery )
|
||||||
#include "tst_qsqlquery.moc"
|
#include "tst_qsqlquery.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user