Commit f1d4d76b authored by Ronan's avatar Ronan
Browse files

feat(AbstractDb): add checkTableExists func

parent 057c4ca3
......@@ -205,4 +205,22 @@ void AbstractDb::enableForeignKeys (bool status) {
#endif // ifdef SOCI_ENABLED
}
bool AbstractDb::checkTableExists (const string &table) const {
#ifdef SOCI_ENABLED
L_D();
soci::session *session = d->dbSession.getBackendSession<soci::session>();
switch (d->backend) {
case Mysql:
*session << "SHOW TABLES LIKE :table", soci::use(table);
return session->got_data() > 0;
case Sqlite3:
*session << "SELECT name FROM sqlite_master WHERE type='table' AND name=:table", soci::use(table);
return session->got_data() > 0;
}
#endif // ifdef SOCI_ENABLED
L_ASSERT(false);
return false;
}
LINPHONE_END_NAMESPACE
......@@ -63,6 +63,8 @@ protected:
void enableForeignKeys (bool status);
bool checkTableExists (const std::string &table) const;
private:
L_DECLARE_PRIVATE(AbstractDb);
L_DISABLE_COPY(AbstractDb);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment