From f5213ab799be73ef7e0c5fee9828d4fbcf238d95 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 13 Oct 2019 13:51:19 +0200 Subject: QMySQL: return QVariant::ByteArray for POINT column qDecodeMYSQLType() did not handle FIELD_TYPE_GEOMETRY and therefore the type for a POINT column was incorrectly treated as QVariant::String. Even the type can not (yet) be properly decoded to a QPoint, treating it as QVariant::ByteArray is the better option here. Fixes: QTBUG-72140 Change-Id: I12e75b326ae3acb75cb36f2e650464528bd43c0e Reviewed-by: Andy Shaw --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/auto/sql') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 4533284a0f..3aa23c504d 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -238,6 +238,9 @@ private slots: void QTBUG_53969_data() { generic_data("QMYSQL"); } void QTBUG_53969(); + void gisPointDatatype_data() { generic_data("QMYSQL"); } + void gisPointDatatype(); + void sqlite_constraint_data() { generic_data("QSQLITE"); } void sqlite_constraint(); @@ -4080,6 +4083,25 @@ void tst_QSqlQuery::QTBUG_53969() } } +void tst_QSqlQuery::gisPointDatatype() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlQuery sqlQuery(db); + const auto tableName = qTableName("qtbug72140", __FILE__, db); + tst_Databases::safeDropTable(db, tableName); + QString sqlCommand = QStringLiteral("CREATE TABLE %1 (`lonlat_point` POINT NULL) ENGINE = InnoDB;").arg(tableName); + QVERIFY(sqlQuery.exec(sqlCommand)); + sqlCommand = QStringLiteral("INSERT INTO %1(lonlat_point) VALUES(ST_GeomFromText('POINT(1 1)'));").arg(tableName); + QVERIFY(sqlQuery.exec(sqlCommand)); + sqlCommand = QStringLiteral("SELECT * FROM %1;").arg(tableName); + QVERIFY(sqlQuery.exec(sqlCommand)); + QCOMPARE(sqlQuery.record().field(0).type(), QVariant::Type::ByteArray); + QVERIFY(sqlQuery.next()); +} + void tst_QSqlQuery::oraOCINumber() { QFETCH( QString, dbName ); -- cgit v1.2.3