aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-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);