From 9070a0772ca126060bf3e35ab701f8ad2ceceadb Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 30 Jan 2020 14:26:37 +0000 Subject: [PATCH] .upptst git-svn-id: svn://ultimatepp.org/upp/trunk@13956 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- upptst/SQL_Name/SQL_Name.upp | 11 ++++ upptst/SQL_Name/simple.cpp | 112 +++++++++++++++++++++++++++++++++++ upptst/SQL_Name/simple.h | 12 ++++ upptst/SQL_Name/simple.sch | 6 ++ 4 files changed, 141 insertions(+) create mode 100644 upptst/SQL_Name/SQL_Name.upp create mode 100644 upptst/SQL_Name/simple.cpp create mode 100644 upptst/SQL_Name/simple.h create mode 100644 upptst/SQL_Name/simple.sch diff --git a/upptst/SQL_Name/SQL_Name.upp b/upptst/SQL_Name/SQL_Name.upp new file mode 100644 index 000000000..35666f9c1 --- /dev/null +++ b/upptst/SQL_Name/SQL_Name.upp @@ -0,0 +1,11 @@ +uses + plugin\sqlite3; + +file + simple.h, + simple.cpp, + simple.sch; + +mainconfig + "" = ""; + diff --git a/upptst/SQL_Name/simple.cpp b/upptst/SQL_Name/simple.cpp new file mode 100644 index 000000000..c340adf6d --- /dev/null +++ b/upptst/SQL_Name/simple.cpp @@ -0,0 +1,112 @@ +#include "simple.h" + +#ifdef _DEBUG +#include +#endif + +#include + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + LOG("-- Starting new run of Sqlite3 simple test"); +#ifdef _DEBUG + LOG("Debug mode!"); +#endif + + DDUMP(~SIMPLE_TEST1); + DDUMP(~NAME); + + Sqlite3Session sqlite3; + sqlite3.LogErrors(true); + sqlite3.SetTrace(); + if(!sqlite3.Open(ConfigFile("simple.db"))) { + LOG("Can't create or open database file\n"); + return; + } + + SQL = sqlite3; + + // Update the schema to match the schema described in "simple.sch" +#ifdef _DEBUG + SqlSchema sch(SQLITE3); + All_Tables(sch); +// if(sch.ScriptChanged(SqlSchema::UPGRADE)) + SqlPerformScript(sch.Upgrade()); + if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) { + SqlPerformScript(sch.Attributes()); + } + if(sch.ScriptChanged(SqlSchema::CONFIG)) { + SqlPerformScript(sch.ConfigDrop()); + SqlPerformScript(sch.Config()); + } + sch.SaveNormal(); +#endif + + // Now test out some functionality: + //-------------------------------------------------------------------- + // Get the list of tables + Vector table_list = sqlite3.EnumTables(""); + LOG(Format("Tables: (%d)",table_list.GetCount())); + for (int i = 0; i < table_list.GetCount(); ++i) + LOG(Format(" #%d: %s",i+1,table_list[i])); + + DDUMP(~SIMPLE_TEST1); + DDUMP(~NAME); + + + S_SIMPLE_TEST1 row; + Sql sql; + + // Test basic insertion: + // (check buglog for errors about duplicate entries if you run this more + // than once on the same db!) + sql*Insert(SIMPLE_TEST1)(ID,0)(NAME,"Joe")(LASTNAME,"Smith")(BDATE,20000101); + LOG(sql.ToString()); + sql*Insert(SIMPLE_TEST1)(ID,1)(NAME,"Mike")(LASTNAME,"Smith")(BDATE,20000102); + LOG(sql.ToString()); + sql*Insert(SIMPLE_TEST1)(ID,2)(NAME,"Jon")(LASTNAME,"Goober")(BDATE,20000103); + LOG(sql.ToString()); + + // Test deletion + sql*Delete(SIMPLE_TEST1).Where(ID > 3); + LOG(sql.ToString()); + + // Test insertion + sql*Insert(SIMPLE_TEST1)(ID,5)(NAME,"wrongname")(LASTNAME,"wronglastname")(BDATE,20010604); + LOG(sql.ToString()); + + // Test update + sql*SqlUpdate(SIMPLE_TEST1)(NAME,"rightname")(LASTNAME,"rightlastname")(BDATE,20010604).Where(ID==5); + LOG(sql.ToString()); + + // Test insertion with args + Sql insert("insert into SIMPLE_TEST1(name,bdate) values(?,?)",sqlite3); + insert.Run("joseph",19990101); + insert.Run( "neel",19990102); + insert.Run( "bob",19990103); + insert.Run( "al",19990104); + + // Test selection: + sql*Select(row).From(SIMPLE_TEST1); + LOG(sql.ToString()); + while (sql.Fetch()) { + LOG(Format("%d %s %s %d",sql[0],sql[1],sql[2],sql[3])); + LOG(Format("%s %s %s %s",sql[ID],sql[NAME],sql[LASTNAME],sql[BDATE])); + } + + // Test selection using * + sql*Select(SqlAll()).From(SIMPLE_TEST1); + LOG(sql.ToString()); + while (sql.Fetch()) { + LOG(Format("%d %s %s %d",sql[0],sql[1],sql[2],sql[3])); + LOG(Format("blank: %s %s %s %s",sql[ID],sql[NAME],sql[LASTNAME],sql[BDATE])); + } + + DDUMP(GetSchAll()); + DDUMP(GetSchTables()); + DDUMP(GetSchColumns("TEST")); + + LOG("-- Normal exit of Sqlite3 simple test"); +} diff --git a/upptst/SQL_Name/simple.h b/upptst/SQL_Name/simple.h new file mode 100644 index 000000000..094e7a5ed --- /dev/null +++ b/upptst/SQL_Name/simple.h @@ -0,0 +1,12 @@ +#ifndef _SQL_Sqlite3_simple_h_ +#define _SQL_Sqlite3_simple_h_ + +#include + +using namespace Upp; + +#define SCHEMADIALECT +#define MODEL +#include "Sql/sch_header.h" + +#endif diff --git a/upptst/SQL_Name/simple.sch b/upptst/SQL_Name/simple.sch new file mode 100644 index 000000000..e4e39b441 --- /dev/null +++ b/upptst/SQL_Name/simple.sch @@ -0,0 +1,6 @@ +TABLE_(SIMPLE_TEST1) SQL_NAME("TEST") + INT_ (ID) PRIMARY_KEY + STRING_ (NAME, 200) SQL_NAME("FIRST_NAME") + STRING_ (LASTNAME, 200) + INT_ (BDATE) +END_TABLE