summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp47
-rw-r--r--tests/auto/qsqldatabase/tst_qsqldatabase.cpp8
2 files changed, 31 insertions, 24 deletions
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp
index fa79460..b29e742 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -1310,23 +1310,38 @@ QSqlResult *QMYSQLDriver::createResult() const
QStringList QMYSQLDriver::tables(QSql::TableType type) const
{
QStringList tl;
- if (!isOpen())
- return tl;
- if (!(type & QSql::Tables))
- return tl;
-
- MYSQL_RES* tableRes = mysql_list_tables(d->mysql, NULL);
- MYSQL_ROW row;
- int i = 0;
- while (tableRes) {
- mysql_data_seek(tableRes, i);
- row = mysql_fetch_row(tableRes);
- if (!row)
- break;
- tl.append(toUnicode(d->tc, row[0]));
- i++;
+ if( mysql_get_server_version(d->mysql) < 50000)
+ {
+ if (!isOpen())
+ return tl;
+ if (!(type & QSql::Tables))
+ return tl;
+
+ MYSQL_RES* tableRes = mysql_list_tables(d->mysql, NULL);
+ MYSQL_ROW row;
+ int i = 0;
+ while (tableRes) {
+ mysql_data_seek(tableRes, i);
+ row = mysql_fetch_row(tableRes);
+ if (!row)
+ break;
+ tl.append(toUnicode(d->tc, row[0]));
+ i++;
+ }
+ mysql_free_result(tableRes);
+ } else {
+ QSqlQuery q(createResult());
+ if(type & QSql::Tables) {
+ q.exec(QLatin1String("select table_name from information_schema.tables where table_type = 'BASE TABLE'"));
+ while(q.next())
+ tl.append(q.value(0).toString());
+ }
+ if(type & QSql::Views) {
+ q.exec(QLatin1String("select table_name from information_schema.tables where table_type = 'VIEW'"));
+ while(q.next())
+ tl.append(q.value(0).toString());
+ }
}
- mysql_free_result(tableRes);
return tl;
}
diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
index e9a0670..a6d2c26 100644
--- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
@@ -513,10 +513,6 @@ void tst_QSqlDatabase::tables()
QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive));
QVERIFY(!tables.contains("sql_features", Qt::CaseInsensitive)); //check for postgres 7.4 internal tables
if (views) {
- if (db.driverName().startsWith("QMYSQL"))
- // MySQL doesn't differentiate between tables and views when calling QSqlDatabase::tables()
- // May be fixable by doing a select on informational_schema.tables instead of using the client library api
- QEXPECT_FAIL("", "MySQL driver thinks that views are tables", Continue);
QVERIFY(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive));
}
if (tempTables)
@@ -524,10 +520,6 @@ void tst_QSqlDatabase::tables()
tables = db.tables(QSql::Views);
if (views) {
- if (db.driverName().startsWith("QMYSQL"))
- // MySQL doesn't give back anything when calling QSqlDatabase::tables() with QSql::Views
- // May be fixable by doing a select on informational_schema.views instead of using the client library api
- QEXPECT_FAIL("", "MySQL driver thinks that views are tables", Continue);
if(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive))
qDebug() << "failed to find" << qTableName("qtest_view") << "in" << tables;
QVERIFY(tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive));