mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 23:45:49 -04:00
Added method "tableExist" to RetroDb.
This commit is contained in:
parent
3665238e61
commit
6ac107a954
2 changed files with 57 additions and 17 deletions
|
@ -557,6 +557,43 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
|
|||
return execSQL_bind(sqlQuery, paramBindings);
|
||||
}
|
||||
|
||||
bool RetroDb::tableExists(const std::string &tableName)
|
||||
{
|
||||
if (!isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string sqlQuery = "PRAGMA table_info(" + tableName + ");";
|
||||
|
||||
bool result = false;
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
|
||||
int rc = sqlite3_prepare_v2(mDb, sqlQuery.c_str(), sqlQuery.length(), &stmt, NULL);
|
||||
if (rc == SQLITE_OK) {
|
||||
rc = sqlite3_step(stmt);
|
||||
switch (rc) {
|
||||
case SQLITE_ROW:
|
||||
result = true;
|
||||
break;
|
||||
case SQLITE_DONE:
|
||||
break;
|
||||
default:
|
||||
std::cerr << "RetroDb::tableExists(): Error executing statement (code: " << rc << ")"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "RetroDb::tableExists(): Error preparing statement\n";
|
||||
std::cerr << "Error code: " << sqlite3_errmsg(mDb)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if (stmt) {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/********************** RetroCursor ************************/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue