Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.

Fixes #9742.
(cherry picked from commit eda0880)
  • Loading branch information...
commit 4fe108c258777901c49d069267de3202653fea26 1 parent 8c6ee70
@sphery sphery authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 mythtv/libs/libmythdb/mythdbcon.cpp
View
22 mythtv/libs/libmythdb/mythdbcon.cpp
@@ -123,7 +123,27 @@ bool MSqlDatabase::OpenDatabase()
// 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();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.