mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Sql tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@1257 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
326cc95d3f
commit
2c2f38d746
24 changed files with 342 additions and 0 deletions
10
tutorial/Sql01/Sql01.upp
Normal file
10
tutorial/Sql01/Sql01.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core,
|
||||
plugin\sqlite3;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
5
tutorial/Sql01/init
Normal file
5
tutorial/Sql01/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Sql01_icpp_init_stub
|
||||
#define _Sql01_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "plugin\sqlite3/init"
|
||||
#endif
|
||||
22
tutorial/Sql01/main.cpp
Normal file
22
tutorial/Sql01/main.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <Core/Core.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
if(!sqlite3.Open(ConfigFile("simple.db"))) {
|
||||
Cout() << "Can't create or open database file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
|
||||
Sql sql(sqlite3);
|
||||
sql.Execute("select date('now')");
|
||||
while(sql.Fetch())
|
||||
Cout() << sql[0];
|
||||
}
|
||||
10
tutorial/Sql02/Sql02.upp
Normal file
10
tutorial/Sql02/Sql02.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core,
|
||||
plugin\sqlite3;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
5
tutorial/Sql02/init
Normal file
5
tutorial/Sql02/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Sql02_icpp_init_stub
|
||||
#define _Sql02_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "plugin\sqlite3/init"
|
||||
#endif
|
||||
33
tutorial/Sql02/main.cpp
Normal file
33
tutorial/Sql02/main.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include <Core/Core.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
if(!sqlite3.Open(ConfigFile("simple.db"))) {
|
||||
Cout() << "Can't create or open database file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
|
||||
SQL = sqlite3;
|
||||
|
||||
SQL.Execute("drop table TEST");
|
||||
SQL.ClearError();
|
||||
SQL.Execute("create table TEST (A INTEGER, B TEXT)");
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
SQL.Execute("insert into TEST(A, B) values (?, ?)", i, AsString(3 * i));
|
||||
|
||||
Sql sql;
|
||||
sql.Execute("select * from TEST");
|
||||
for(int i = 0; i < sql.GetColumns(); i++)
|
||||
Cout() << sql.GetColumnInfo(i).name << '\n';
|
||||
while(sql.Fetch())
|
||||
Cout() << sql[0] << " \'" << sql[1] << "\'\n";
|
||||
}
|
||||
10
tutorial/Sql03/Sql03.upp
Normal file
10
tutorial/Sql03/Sql03.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core,
|
||||
plugin\sqlite3;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
5
tutorial/Sql03/init
Normal file
5
tutorial/Sql03/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Sql03_icpp_init_stub
|
||||
#define _Sql03_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "plugin\sqlite3/init"
|
||||
#endif
|
||||
33
tutorial/Sql03/main.cpp
Normal file
33
tutorial/Sql03/main.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include <Core/Core.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
if(!sqlite3.Open(ConfigFile("simple.db"))) {
|
||||
Cout() << "Can't create or open database file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
|
||||
SQL = sqlite3;
|
||||
|
||||
SQL.Execute("drop table TEST");
|
||||
SQL.ClearError();
|
||||
SQL.Execute("create table TEST (A INTEGER, B TEXT)");
|
||||
|
||||
SqlId A("A"), B("B"), TEST("TEST");
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
SQL * Insert(TEST)(A, i)(B, AsString(3 * i));
|
||||
|
||||
Sql sql;
|
||||
sql * Select(A, B).From(TEST);
|
||||
while(sql.Fetch())
|
||||
Cout() << sql[A] << " \'" << sql[B] << "\'\n";
|
||||
}
|
||||
13
tutorial/Sql04/MyApp.h
Normal file
13
tutorial/Sql04/MyApp.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _MyApp_h_
|
||||
#define _MyApp_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#define MODEL <Sql05/MyApp.sch>
|
||||
#include "Sql/sch_header.h"
|
||||
|
||||
#endif
|
||||
4
tutorial/Sql04/MyApp.sch
Normal file
4
tutorial/Sql04/MyApp.sch
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
TABLE(TEST)
|
||||
INT (A)
|
||||
STRING (B, 200)
|
||||
END_TABLE
|
||||
12
tutorial/Sql04/Sql04.upp
Normal file
12
tutorial/Sql04/Sql04.upp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
uses
|
||||
Core,
|
||||
plugin\sqlite3;
|
||||
|
||||
file
|
||||
MyApp.h,
|
||||
main.cpp,
|
||||
MyApp.sch;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
5
tutorial/Sql04/init
Normal file
5
tutorial/Sql04/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Sql05_icpp_init_stub
|
||||
#define _Sql05_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "plugin\sqlite3/init"
|
||||
#endif
|
||||
35
tutorial/Sql04/main.cpp
Normal file
35
tutorial/Sql04/main.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "MyApp.h"
|
||||
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
if(!sqlite3.Open(ConfigFile("simple.db"))) {
|
||||
Cout() << "Can't create or open database file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
|
||||
SQL = sqlite3;
|
||||
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
SQL.ClearError();
|
||||
|
||||
SqlId A("A"), B("B"), TEST("TEST");
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
SQL * Insert(TEST)(A, i)(B, AsString(3 * i));
|
||||
|
||||
Sql sql;
|
||||
sql * Select(A, B).From(TEST);
|
||||
while(sql.Fetch())
|
||||
Cout() << sql[A] << " \'" << sql[B] << "\'\n";
|
||||
}
|
||||
13
tutorial/Sql05/MyApp.h
Normal file
13
tutorial/Sql05/MyApp.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _MyApp_h_
|
||||
#define _MyApp_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#define MODEL <Sql06/MyApp.sch>
|
||||
#include "Sql/sch_header.h"
|
||||
|
||||
#endif
|
||||
9
tutorial/Sql05/MyApp.sch
Normal file
9
tutorial/Sql05/MyApp.sch
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
TABLE_(TEST)
|
||||
INT_ (A)
|
||||
STRING_ (B, 200)
|
||||
END_TABLE
|
||||
|
||||
TABLE_(TEST2)
|
||||
INT (A)
|
||||
STRING (B, 200)
|
||||
END_TABLE
|
||||
12
tutorial/Sql05/Sql05.upp
Normal file
12
tutorial/Sql05/Sql05.upp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
uses
|
||||
Core,
|
||||
plugin\sqlite3;
|
||||
|
||||
file
|
||||
MyApp.h,
|
||||
main.cpp,
|
||||
MyApp.sch;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
5
tutorial/Sql05/init
Normal file
5
tutorial/Sql05/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Sql06_icpp_init_stub
|
||||
#define _Sql06_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "plugin\sqlite3/init"
|
||||
#endif
|
||||
33
tutorial/Sql05/main.cpp
Normal file
33
tutorial/Sql05/main.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "MyApp.h"
|
||||
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
if(!sqlite3.Open(ConfigFile("simple.db"))) {
|
||||
Cout() << "Can't create or open database file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
|
||||
SQL = sqlite3;
|
||||
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
SQL.ClearError();
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
SQL * Insert(TEST)(A, i)(B, AsString(3 * i));
|
||||
|
||||
Sql sql;
|
||||
sql * Select(A, B).From(TEST);
|
||||
while(sql.Fetch())
|
||||
Cout() << sql[A] << " \'" << sql[B] << "\'\n";
|
||||
}
|
||||
13
tutorial/Sql06/MyApp.h
Normal file
13
tutorial/Sql06/MyApp.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _MyApp_h_
|
||||
#define _MyApp_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#define MODEL <Sql06/MyApp.sch>
|
||||
#include "Sql/sch_header.h"
|
||||
|
||||
#endif
|
||||
4
tutorial/Sql06/MyApp.sch
Normal file
4
tutorial/Sql06/MyApp.sch
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
TABLE_(TEST)
|
||||
INT_ (A)
|
||||
STRING_ (B, 200)
|
||||
END_TABLE
|
||||
12
tutorial/Sql06/Sql06.upp
Normal file
12
tutorial/Sql06/Sql06.upp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
uses
|
||||
Core,
|
||||
plugin\sqlite3;
|
||||
|
||||
file
|
||||
MyApp.h,
|
||||
main.cpp,
|
||||
MyApp.sch;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
5
tutorial/Sql06/init
Normal file
5
tutorial/Sql06/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Sql06_icpp_init_stub
|
||||
#define _Sql06_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "plugin\sqlite3/init"
|
||||
#endif
|
||||
34
tutorial/Sql06/main.cpp
Normal file
34
tutorial/Sql06/main.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "MyApp.h"
|
||||
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
if(!sqlite3.Open(ConfigFile("simple.db"))) {
|
||||
Cout() << "Can't create or open database file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
|
||||
SQL = sqlite3;
|
||||
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
SQL.ClearError();
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
SQL * Insert(TEST)(A, i)(B, AsString(3 * i));
|
||||
|
||||
Sql sql;
|
||||
S_TEST x;
|
||||
sql * Select(x).From(TEST);
|
||||
while(sql.Fetch(x))
|
||||
Cout() << x.A << " \'" << x.B << "\'\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue