File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,18 @@ TARGET = qsqlmysql
33HEADERS += $$PWD /qsql_mysql_p.h
44SOURCES += $$PWD /qsql_mysql.cpp $$PWD /main.cpp
55
6- QMAKE_USE += mysql
6+ # QMAKE_USE += mysql
77
88OTHER_FILES += mysql.json
9-
9+ load(qt_build_config)
1010PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
11- include (../qsqldriverbase.pri )
11+ include ($$PWD/../qsqldriverbase.pri )
12+ message ($$QT_ARCH )
13+
14+ contains (QT_ARCH, i386 ) {
15+ INCLUDEPATH += $$PWD /../../mysql-connector-c-6.1.11-win32 \ include
16+ LIBS += -L $$PWD /../../mysql-connector-c-6.1.11-win32 \ lib -llibmysql
17+ } else {
18+ INCLUDEPATH += $$PWD /../../mysql-connector-c-6.1.11-winx64 \ include
19+ LIBS += -L $$PWD /../../mysql-connector-c-6.1.11-winx64 \ lib -llibmysql
20+ }
Original file line number Diff line number Diff line change @@ -158,6 +158,20 @@ static inline QVariant qDateTimeFromString(QString &val)
158158#endif
159159}
160160
161+ // check if this client and server version of MySQL/MariaDB support prepared statements
162+ static inline bool checkPreparedQueries (MYSQL *mysql)
163+ {
164+ std::unique_ptr<MYSQL_STMT, decltype (&mysql_stmt_close)> stmt (mysql_stmt_init (mysql), &mysql_stmt_close);
165+ if (!stmt)
166+ return false ;
167+
168+ static const char dummyQuery[] = " SELECT ? + ?" ;
169+ if (mysql_stmt_prepare (stmt.get (), dummyQuery, sizeof (dummyQuery) - 1 ))
170+ return false ;
171+
172+ return mysql_stmt_param_count (stmt.get ()) == 2 ;
173+ }
174+
161175class QMYSQLResultPrivate ;
162176
163177class QMYSQLResult : public QSqlResult
@@ -1371,8 +1385,7 @@ bool QMYSQLDriver::open(const QString& db,
13711385 }
13721386#endif // MYSQL_VERSION_ID >= 50007
13731387
1374- d->preparedQuerysEnabled = mysql_get_client_version () >= 40108
1375- && mysql_get_server_version (d->mysql ) >= 40100 ;
1388+ d->preparedQuerysEnabled = checkPreparedQueries (d->mysql );
13761389
13771390#if QT_CONFIG(thread)
13781391 mysql_thread_init ();
You can’t perform that action at this time.
0 commit comments