From f5213ab799be73ef7e0c5fee9828d4fbcf238d95 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 13 Oct 2019 13:51:19 +0200 Subject: [PATCH] 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 --- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 1 + .../sql/kernel/qsqlquery/tst_qsqlquery.cpp | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index d3e37f11d65..a641935dc55 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -294,6 +294,7 @@ static QMetaType::Type qDecodeMYSQLType(int mysqltype, uint flags) case FIELD_TYPE_TINY_BLOB : case FIELD_TYPE_MEDIUM_BLOB : case FIELD_TYPE_LONG_BLOB : + case FIELD_TYPE_GEOMETRY : type = (flags & BINARY_FLAG) ? QMetaType::QByteArray : QMetaType::QString; break; default: diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 4533284a0fe..3aa23c504da 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 );