Guest User

Untitled

a guest
Aug 12th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include "prissql.h"
  2.  
  3. // PrisSql class defn
  4. bool PrisSql::m_InitFlag = false;
  5. PrisSql* PrisSql::m_Instance = NULL;
  6.  
  7. PrisSql* PrisSql::Instance()
  8. {
  9. if (!m_InitFlag)
  10. {
  11. m_Instance = new PrisSql();
  12. m_InitFlag = true;
  13. return m_Instance;
  14. }
  15.  
  16. else
  17. { return m_Instance; }
  18. }
  19.  
  20. void PrisSql::SetFilePath(QString filePath)
  21. {
  22. // set filePath
  23. m_filePath = filePath;
  24.  
  25. // check if file exists
  26. (QFile::exists(m_filePath)) ? m_SettingsFileEmpty = false : m_SettingsFileEmpty = true;
  27.  
  28. // connect to database file
  29. if (sqlite3_open_v2(m_filePath.toLocal8Bit(), &sqlite_db, SQLITE_OPEN_READONLY, NULL) == SQLITE_OK)
  30. { qDebug() << "Connected to Db!"; }
  31. else
  32. {
  33. qDebug() << "Could not connect to Db!";
  34. qDebug() << "Error: " << QString(sqlite3_errmsg(sqlite_db));
  35. sqlite3_close(sqlite_db);
  36. }
  37. }
  38.  
  39. void PrisSql::RunTest()
  40. {
  41. QString sqlQuery = "SELECT name FROM Sections";
  42.  
  43. // try preparing a statement
  44. if (sqlite3_prepare_v2(sqlite_db,sqlQuery.toLocal8Bit().data(), -1, &sqlite_stmt, NULL) == SQLITE_OK)
  45. { qDebug() << "Prepared Query"; }
  46. else
  47. { qDebug() << "Could not prepare query"; }
  48.  
  49. // execute the statement
  50. while (sqlite3_step(sqlite_stmt) == SQLITE_ROW)
  51. {
  52. qDebug() << QString::fromLocal8Bit((const char*)sqlite3_column_text(sqlite_stmt,0));
  53. }
  54.  
  55. // destroy/clean-up the statement
  56. if (sqlite3_finalize(sqlite_stmt) == SQLITE_OK)
  57. { qDebug() << "Finalized Query"; }
  58. else
  59. {
  60. qDebug() << "Could not finalize query";
  61. }
  62. }
  63.  
  64. PrisSql::PrisSql()
  65. {}
Advertisement
Add Comment
Please, Sign In to add comment