aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-01-10 21:47:42 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:44 +0100
commit98bdc2079442b79780db04bb8d05a2c329577e10 (patch)
tree22438186f1287101ad057e620386cbc96dc4637e /src
parent872459a7cc525eb87a2dc5a82f1b137493186080 (diff)
downloadusdx-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 'src')
-rw-r--r--src/base/database.cpp25
-rw-r--r--src/base/database.hpp9
2 files changed, 34 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);
diff --git a/src/base/database.hpp b/src/base/database.hpp
index d5313609..c7bb00b8 100644
--- a/src/base/database.hpp
+++ b/src/base/database.hpp
@@ -80,6 +80,15 @@ namespace usdx
*/
const bool sqlite_table_exists(const std::string table);
+ /**
+ * Check if the given table has the given column by name.
+ *
+ * @param table Table to examine
+ * @param column Name of the column to check if exists
+ * @return true, if column exists in that table, false if not
+ */
+ const bool sqlite_table_contains_column(const std::string table, const std::string column);
+
// Singleton
StatDatabase(std::string filename);