diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-01-10 21:47:42 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-05 17:17:44 +0100 |
commit | 98bdc2079442b79780db04bb8d05a2c329577e10 (patch) | |
tree | 22438186f1287101ad057e620386cbc96dc4637e /src/base/database.cpp | |
parent | 872459a7cc525eb87a2dc5a82f1b137493186080 (diff) | |
download | usdx-98bdc2079442b79780db04bb8d05a2c329577e10.tar.gz usdx-98bdc2079442b79780db04bb8d05a2c329577e10.tar.xz usdx-98bdc2079442b79780db04bb8d05a2c329577e10.zip |
added function for testing weather a table contains a column or not
Diffstat (limited to '')
-rw-r--r-- | src/base/database.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/base/database.cpp b/src/base/database.cpp index ec2e8493..ae097be4 100644 --- a/src/base/database.cpp +++ b/src/base/database.cpp @@ -102,6 +102,31 @@ namespace usdx return result; } + const bool StatDatabase::sqlite_table_contains_column(const std::string table, const std::string column) + { + std::string sqlStatement = "PRAGMA TABLE_INFO(["; + sqlStatement += table; + sqlStatement += "]);"; + + sqlite3_stmt *sqliteStatement = sqlite_prepare(sqlStatement); + bool result = false; + + int rc = sqlite3_step(sqliteStatement); + while (rc == SQLITE_ROW) { + const char *column_name = (const char*)sqlite3_column_blob(sqliteStatement, 1); + + if (column == std::string(column_name)) { + result = true; + break; + } + + rc = sqlite3_step(sqliteStatement); + } + + sqlite3_finalize(sqliteStatement); + return result; + } + void StatDatabase::init(const std::string filename) { LOG4CXX_DEBUG(log, "Initializing Database: " << filename); |