{"id":1242,"date":"2015-01-06T15:41:08","date_gmt":"2015-01-06T15:41:08","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=1242"},"modified":"2023-11-24T15:30:15","modified_gmt":"2023-11-24T15:30:15","slug":"creating-tables","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/databases\/sqlite\/tables\/creating-tables","title":{"rendered":"Creating Tables"},"content":{"rendered":"<h4>Good Resources<\/h4>\n<p><a href=\"https:\/\/www.sqlite.org\/lang_createtable.html\">https:\/\/www.sqlite.org\/lang_createtable.html<\/a><\/p>\n<h4>An Example<\/h4>\n<pre><code>\n\tbool DatabaseSqlite::InitialiseDatabase(void)\n\t{\n\t\tSystem::Data::SQLite::SQLiteConnection ^Connection1;\n\t\tString ^sTemp;\n\n\t\ttry\n\t\t{\n\n\t\t\t\/\/----- OPEN THE DATABASE CONNECTION -----\n\t\t\tConnection1 = gcnew System::Data::SQLite::SQLiteConnection(\"data source=\" + Environment::GetFolderPath(Environment::SpecialFolder::ApplicationData) + \"\\\\\" + Application::CompanyName + \"\\\\\" + Application::ProductName + \"\\\\mydatabasefile.db;Password=\" + SQLITE_DATABASE_FILE_PASSWORD);\n\t\t\tConnection1-&gt;Open();\n\n\t\t\tSystem::Data::SQLite::SQLiteCommand ^Command1 = gcnew System::Data::SQLite::SQLiteCommand(Connection1);\n\n\t\t\t\/\/----- CREATE MY TABLE IF NECESSARY -----\n\t\t\tsTemp = \"CREATE TABLE IF NOT EXISTS tblMyTableName ( \\\n\t\t\t\t\t\t\t\t\tId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \\\n\t\t\t\t\t\t\t\t\tMyIntigerField INTEGER, \\\n\t\t\t\t\t\t\t\t\tMyNumericField NUMERIC, \\\n\t\t\t\t\t\t\t\t\tMyRealField REAL, \\\n\t\t\t\t\t\t\t\t\tMyTextField TEXT \\\n\t\t\t\t\t\t\t\t\t)\";\n\t\t\tCommand1-&gt;CommandText = sTemp;\n\t\t\tCommand1-&gt;ExecuteNonQuery();\n\n\t\t\treturn(true);\n\t\t}\n\t\tcatch (Exception ^e)\n\t\t{\n\t\t\tMessageBox::Show(L\"Error:\\n\" + e, L\"Error\", MessageBoxButtons::OK, MessageBoxIcon::Error);\n\t\t\treturn(false);\n\t\t}\n\t\tfinally\n\t\t{\n\t\t\t\/\/----- CLOSE THE DATABASE CONNECTION -----\n\t\t\ttry\n\t\t\t{\n\t\t\t\tif (Connection1 != nullptr)\n\t\t\t\t\tConnection1-&gt;Close();\n\t\t\t}\n\t\t\tcatch (Exception ^)\n\t\t\t{\n\t\t\t}\n\t\t}\n\t}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Good Resources https:\/\/www.sqlite.org\/lang_createtable.html An Example bool DatabaseSqlite::InitialiseDatabase(void) { System::Data::SQLite::SQLiteConnection ^Connection1; String ^sTemp; try { \/\/&#8212;&#8211; OPEN THE DATABASE CONNECTION &#8212;&#8211; Connection1 = gcnew System::Data::SQLite::SQLiteConnection(&#8220;data source=&#8221; + Environment::GetFolderPath(Environment::SpecialFolder::ApplicationData) + &#8220;\\\\&#8221; + Application::CompanyName + &#8220;\\\\&#8221; + Application::ProductName + &#8220;\\\\mydatabasefile.db;Password=&#8221; + SQLITE_DATABASE_FILE_PASSWORD); Connection1-&gt;Open(); System::Data::SQLite::SQLiteCommand ^Command1 = gcnew System::Data::SQLite::SQLiteCommand(Connection1); \/\/&#8212;&#8211; CREATE MY TABLE IF NECESSARY &#8212;&#8211; sTemp = &#8220;CREATE [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107],"tags":[],"class_list":["post-1242","post","type-post","status-publish","format-standard","hentry","category-tables"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=1242"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1242\/revisions"}],"predecessor-version":[{"id":1647,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1242\/revisions\/1647"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=1242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=1242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=1242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}