Set up some db tests with table create.

This commit is contained in:
jmsgrogan 2023-01-27 17:35:52 +00:00
parent 4d2464c1f5
commit a6d92e142f
5 changed files with 110 additions and 28 deletions

View file

@ -1,6 +1,7 @@
#include "SqliteInterface.h"
#include "FileLogger.h"
#include "Directory.h"
SqliteInterface::SqliteInterface()
: mSqliteDb(nullptr)
@ -20,8 +21,10 @@ std::unique_ptr<SqliteInterface> SqliteInterface::Create()
void SqliteInterface::open(Database* db)
{
Directory::createIfNotExisting(db->getPath());
const auto path = db->getPath().string();
int rc = sqlite3_open(path.c_str(), &mSqliteDb);
int rc = ::sqlite3_open(path.c_str(), &mSqliteDb);
if( rc )
{
MLOG_ERROR("Can't open database: %s\n" << sqlite3_errmsg(mSqliteDb));
@ -42,11 +45,19 @@ static int callback(void *, int argc, char **, char **)
void SqliteInterface::run(const std::string& statement)
{
MLOG_INFO("Running statement: " << statement);
char *zErrMsg = 0;
int rc = sqlite3_exec(mSqliteDb, statement.c_str(), callback, 0, &zErrMsg);
if (rc != SQLITE_OK)
{
MLOG_ERROR("SQL error: %s\n" << zErrMsg);
if (zErrMsg == nullptr)
{
MLOG_ERROR("Unknown sql error");
}
else
{
MLOG_ERROR("SQL error: %s\n" << zErrMsg);
}
sqlite3_free(zErrMsg);
}
}