summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael T. Dean <mdean@mythtv.org>2011-04-20 19:11:50 (GMT)
committer Michael T. Dean <mdean@mythtv.org>2011-04-20 19:11:50 (GMT)
commiteda0880f93f6de4c501ae7304787825fc5cdd588 (patch)
treef3bbe178f0f850849f0b63bb5e333f26e634a2f3
parentfead3ce351d14a6e37b47aef2748c6f77611366d (diff)
Fix the check to see if we have a valid DB schema.
Change the code that checks to see if we have a schema available so that it doesn't use a count of the value returned by QSqlDatabase::tables(). The tables() function returns a list of all tables visible to the user--even tables in other databases--so can result in false positives. Refs #9742.
-rw-r--r--mythtv/libs/libmythbase/mythdbcon.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/mythtv/libs/libmythbase/mythdbcon.cpp b/mythtv/libs/libmythbase/mythdbcon.cpp
index 33a17e6..a890429 100644
--- a/mythtv/libs/libmythbase/mythdbcon.cpp
+++ b/mythtv/libs/libmythbase/mythdbcon.cpp
@@ -169,7 +169,27 @@ bool MSqlDatabase::OpenDatabase(bool skipdb)
// both being called with true, so order is important here.
GetMythDB()->SetHaveDBConnection(true);
if (!GetMythDB()->HaveSchema())
- GetMythDB()->SetHaveSchema(m_db.tables().count() > 1);
+ {
+ // We can't just check the count of QSqlDatabase::tables()
+ // because it returns all tables visible to the user in *all*
+ // databases (not just the current DB).
+ bool have_schema = false;
+ QString sql = "SELECT COUNT( "
+ " INFORMATION_SCHEMA.TABLES.TABLE_NAME "
+ " ) "
+ " FROM INFORMATION_SCHEMA.TABLES "
+ " WHERE INFORMATION_SCHEMA.TABLES.TABLE_SCHEMA "
+ " = DATABASE() "
+ " AND INFORMATION_SCHEMA.TABLES.TABLE_TYPE = "
+ " 'BASE TABLE';";
+ // We can't use MSqlQuery to determine if we have a schema,
+ // since it will open a new connection, which will try to check
+ // if we have a schema
+ QSqlQuery query = m_db.exec(sql); // don't convert to MSqlQuery
+ if (query.next())
+ have_schema = query.value(0).toInt() > 1;
+ GetMythDB()->SetHaveSchema(have_schema);
+ }
GetMythDB()->WriteDelayedSettings();
}
}