feat(AbstractDb): add checkTableExists func

This commit is contained in:
Ronan Abhamon 2018-01-08 10:09:30 +01:00
parent 057c4ca3b9
commit f1d4d76b1b
2 changed files with 20 additions and 0 deletions

View file

@ -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

View file

@ -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);