Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "prissql.h"
- // PrisSql class defn
- bool PrisSql::m_InitFlag = false;
- PrisSql* PrisSql::m_Instance = NULL;
- PrisSql* PrisSql::Instance()
- {
- if (!m_InitFlag)
- {
- m_Instance = new PrisSql();
- m_InitFlag = true;
- return m_Instance;
- }
- else
- { return m_Instance; }
- }
- void PrisSql::SetFilePath(QString filePath)
- {
- // set filePath
- m_filePath = filePath;
- // check if file exists
- (QFile::exists(m_filePath)) ? m_SettingsFileEmpty = false : m_SettingsFileEmpty = true;
- // connect to database file
- if (sqlite3_open_v2(m_filePath.toLocal8Bit(), &sqlite_db, SQLITE_OPEN_READONLY, NULL) == SQLITE_OK)
- { qDebug() << "Connected to Db!"; }
- else
- {
- qDebug() << "Could not connect to Db!";
- qDebug() << "Error: " << QString(sqlite3_errmsg(sqlite_db));
- sqlite3_close(sqlite_db);
- }
- }
- void PrisSql::RunTest()
- {
- QString sqlQuery = "SELECT name FROM Sections";
- // try preparing a statement
- if (sqlite3_prepare_v2(sqlite_db,sqlQuery.toLocal8Bit().data(), -1, &sqlite_stmt, NULL) == SQLITE_OK)
- { qDebug() << "Prepared Query"; }
- else
- { qDebug() << "Could not prepare query"; }
- // execute the statement
- while (sqlite3_step(sqlite_stmt) == SQLITE_ROW)
- {
- qDebug() << QString::fromLocal8Bit((const char*)sqlite3_column_text(sqlite_stmt,0));
- }
- // destroy/clean-up the statement
- if (sqlite3_finalize(sqlite_stmt) == SQLITE_OK)
- { qDebug() << "Finalized Query"; }
- else
- {
- qDebug() << "Could not finalize query";
- }
- }
- PrisSql::PrisSql()
- {}
Advertisement
Add Comment
Please, Sign In to add comment