diff --git a/dbmanager.cpp b/dbmanager.cpp index 90e34e4..65128a6 100644 --- a/dbmanager.cpp +++ b/dbmanager.cpp @@ -32,6 +32,22 @@ bool DbManager::isOpen() const return m_db.isOpen(); } +bool DbManager::createTable() +{ + bool success = false; + + QSqlQuery query; + query.prepare("CREATE TABLE people(id INTEGER PRIMARY KEY, name TEXT);"); + + if (!query.exec()) + { + qDebug() << "Couldn't create the table 'people': one might already exist."; + success = false; + } + + return success; +} + bool DbManager::addPerson(const QString& name) { bool success = false; diff --git a/dbmanager.h b/dbmanager.h index ef44e95..67b7b97 100644 --- a/dbmanager.h +++ b/dbmanager.h @@ -35,6 +35,12 @@ class DbManager bool isOpen() const; + /** + * @brief Creates a new 'people' table if it doesn't already exist + * @return true - 'people' table created successfully, false - table not created + */ + bool createTable(); + /** * @brief Add person data to db * @param name - name of person to add diff --git a/main.cpp b/main.cpp index 97ad6f5..3c6bc9c 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,7 @@ #include // Set valid db path before first run -static const QString path = "/path/people.db"; +static const QString path = "example.db"; int main(int argc, char *argv[]) { @@ -13,6 +13,7 @@ int main(int argc, char *argv[]) if (db.isOpen()) { + db.createTable(); db.addPerson("A"); db.addPerson("B"); db.addPerson("C"); diff --git a/sqlite_qt.pro.user b/sqlite_qt.pro.user new file mode 100644 index 0000000..9c4024f --- /dev/null +++ b/sqlite_qt.pro.user @@ -0,0 +1,337 @@ + + + + + + EnvironmentId + {a69fc3ad-5348-47ac-bc4f-b6649a7637a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.4.2 clang 64bit + Desktop Qt 5.4.2 clang 64bit + qt.54.clang_64_kit + 0 + 0 + 0 + + /Users/aungmoe/Codes/Backend/build-sqlite_qt-Desktop_Qt_5_4_2_clang_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /Users/aungmoe/Codes/Backend/build-sqlite_qt-Desktop_Qt_5_4_2_clang_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /Users/aungmoe/Codes/Backend/build-sqlite_qt-Desktop_Qt_5_4_2_clang_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + sqlite_qt + + Qt4ProjectManager.Qt4RunConfiguration:/Users/aungmoe/Codes/Backend/sql2/sqlite_qt.pro + true + + sqlite_qt.pro + false + false + + /Users/aungmoe/Codes/Backend/build-sqlite_qt-Desktop_Qt_5_4_2_clang_64bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + +