mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
feat(AbstractDb): add checkTableExists func
This commit is contained in:
parent
057c4ca3b9
commit
f1d4d76b1b
2 changed files with 20 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue