diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-01-10 21:46:58 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-05 17:17:44 +0100 |
commit | 872459a7cc525eb87a2dc5a82f1b137493186080 (patch) | |
tree | 594be565ed9bcc2243ac6fdfbcf7424b0cf3eb95 /src/base/database.cpp | |
parent | e2d74a920c3d6a8250d3b3e2f08d9f29f6d6cea7 (diff) | |
download | usdx-872459a7cc525eb87a2dc5a82f1b137493186080.tar.gz usdx-872459a7cc525eb87a2dc5a82f1b137493186080.tar.xz usdx-872459a7cc525eb87a2dc5a82f1b137493186080.zip |
added function for testing if table exists in database
Diffstat (limited to 'src/base/database.cpp')
-rw-r--r-- | src/base/database.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/base/database.cpp b/src/base/database.cpp index 96f40745..ec2e8493 100644 --- a/src/base/database.cpp +++ b/src/base/database.cpp @@ -82,6 +82,26 @@ namespace usdx sqlite3_finalize(sqliteStatement); } + const bool StatDatabase::sqlite_table_exists(const std::string table) + { + std::string sql = "select [name] from [sqlite_master] where [type] = 'table' and [tbl_name] = ?1;"; + sqlite3_stmt *sqliteStatement = sqlite_prepare(sql); + + // bind table name to parameter 1 and execute statement + sqlite3_bind_text(sqliteStatement, 1, table.c_str(), table.length(), SQLITE_TRANSIENT); + int rc = sqlite3_step(sqliteStatement); + + // if rc is SQLITE_ROW, than result has at lease one row and so + // the table exists + bool result = false; + if (rc == SQLITE_ROW) { + result = true; + } + + sqlite3_finalize(sqliteStatement); + return result; + } + void StatDatabase::init(const std::string filename) { LOG4CXX_DEBUG(log, "Initializing Database: " << filename); |