mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
.tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@5187 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
11ac38b665
commit
76f9917269
7 changed files with 265 additions and 95 deletions
|
|
@ -1,95 +1,95 @@
|
|||
#include <Skylark/Skylark.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define MODEL <Skylark09/myapp.sch>
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#include <Sql/sch_header.h>
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
SKYLARK(HomePage, "")
|
||||
{
|
||||
Sql sql;
|
||||
sql * Select(ID, NAME, LASTNAME)
|
||||
.From(PERSON)
|
||||
.OrderBy(LASTNAME, NAME);
|
||||
ValueArray person;
|
||||
ValueMap vm;
|
||||
while(sql.Fetch(vm))
|
||||
person.Add(vm);
|
||||
http("PERSON", person)
|
||||
.RenderResult("Skylark09/index");
|
||||
}
|
||||
|
||||
struct MyApp : SkylarkApp {
|
||||
virtual void WorkThread();
|
||||
|
||||
MyApp() {
|
||||
root = "myapp";
|
||||
threads = 1; // Sqlite3 does not like threads...
|
||||
#ifdef _DEBUG
|
||||
prefork = 0;
|
||||
use_caching = false;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
void InitModel()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
sch.SaveNormal();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenSQL(Sqlite3Session& sqlite3)
|
||||
{
|
||||
if(!sqlite3.Open(ConfigFile("db"))) {
|
||||
LOG("Can't create or open database file\n");
|
||||
Exit(1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
sqlite3.LogErrors();
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
SQL = sqlite3;
|
||||
}
|
||||
|
||||
void MyApp::WorkThread()
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
OpenSQL(sqlite3);
|
||||
RunThread();
|
||||
}
|
||||
|
||||
void InitDB()
|
||||
{
|
||||
Sqlite3Session sqlsession;
|
||||
OpenSQL(sqlsession);
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
|
||||
SQL * Insert(PERSON)(NAME,"Joe")(LASTNAME,"Smith");
|
||||
SQL * Insert(PERSON)(NAME,"Mike")(LASTNAME,"Carpenter");
|
||||
SQL * Insert(PERSON)(NAME,"Jon")(LASTNAME,"Goober");
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
StdLogSetup(LOG_FILE|LOG_COUT);
|
||||
Ini::skylark_log = true;
|
||||
#endif
|
||||
|
||||
DeleteFile(ConfigFile("db")); // for this example, always create a new DB
|
||||
InitDB();
|
||||
|
||||
MyApp().Run();
|
||||
}
|
||||
#include <Skylark/Skylark.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define MODEL <Skylark09/myapp.sch>
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#include <Sql/sch_header.h>
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
SKYLARK(HomePage, "")
|
||||
{
|
||||
Sql sql;
|
||||
sql * Select(ID, NAME, LASTNAME)
|
||||
.From(PERSON)
|
||||
.OrderBy(LASTNAME, NAME);
|
||||
ValueArray person;
|
||||
ValueMap vm;
|
||||
while(sql.Fetch(vm))
|
||||
person.Add(vm);
|
||||
http("PERSON", person)
|
||||
.RenderResult("Skylark09/index");
|
||||
}
|
||||
|
||||
struct MyApp : SkylarkApp {
|
||||
virtual void WorkThread();
|
||||
|
||||
MyApp() {
|
||||
root = "myapp";
|
||||
threads = 1; // Sqlite3 does not like threads...
|
||||
#ifdef _DEBUG
|
||||
prefork = 0;
|
||||
use_caching = false;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
void InitModel()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
sch.SaveNormal();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenSQL(Sqlite3Session& sqlite3)
|
||||
{
|
||||
if(!sqlite3.Open(ConfigFile("db"))) {
|
||||
LOG("Can't create or open database file\n");
|
||||
Exit(1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
sqlite3.LogErrors();
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
SQL = sqlite3;
|
||||
}
|
||||
|
||||
void MyApp::WorkThread()
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
OpenSQL(sqlite3);
|
||||
RunThread();
|
||||
}
|
||||
|
||||
void InitDB()
|
||||
{
|
||||
Sqlite3Session sqlsession;
|
||||
OpenSQL(sqlsession);
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
|
||||
SQL * Insert(PERSON)(NAME,"Joe")(LASTNAME,"Smith");
|
||||
SQL * Insert(PERSON)(NAME,"Mike")(LASTNAME,"Carpenter");
|
||||
SQL * Insert(PERSON)(NAME,"Jon")(LASTNAME,"Goober");
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
StdLogSetup(LOG_FILE|LOG_COUT);
|
||||
Ini::skylark_log = true;
|
||||
#endif
|
||||
|
||||
DeleteFile(ConfigFile("db")); // for this example, always create a new DB
|
||||
InitDB();
|
||||
|
||||
MyApp().Run();
|
||||
}
|
||||
|
|
|
|||
16
tutorial/Skylark10/Skylark10.upp
Normal file
16
tutorial/Skylark10/Skylark10.upp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
description "Advanced SQL\377";
|
||||
|
||||
uses
|
||||
Core,
|
||||
Skylark,
|
||||
plugin/sqlite3;
|
||||
|
||||
file
|
||||
index.witz,
|
||||
dialog.witz,
|
||||
myapp.sch,
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2 MT";
|
||||
|
||||
13
tutorial/Skylark10/dialog.witz
Normal file
13
tutorial/Skylark10/dialog.witz
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
<body>
|
||||
<FORM action=$ACTION method="post" accept-charset="utf-8" enctype="multipart/form-data">
|
||||
$post_identity()
|
||||
<P>
|
||||
First name: <INPUT type="text" name="name" value="$NAME"><BR>
|
||||
Last name: <INPUT type="text" name="lastname" value="$LASTNAME"><BR>
|
||||
<INPUT type="submit" value="Send" name="OK"/><BR>
|
||||
</P>
|
||||
</FORM>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
20
tutorial/Skylark10/index.witz
Normal file
20
tutorial/Skylark10/index.witz
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<html>
|
||||
<body>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>No.</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
</tr>
|
||||
$for(i in PERSON)
|
||||
<tr>
|
||||
<td>$(i._index + 1).</td>
|
||||
<td>$i.NAME</td>
|
||||
<td>$i.LASTNAME</td>
|
||||
<td><a href=$Edit(i.ID)>Edit</a></td>
|
||||
</tr>
|
||||
$/
|
||||
</table>
|
||||
<a href=$New>Create new</a>
|
||||
</body>
|
||||
</html>
|
||||
6
tutorial/Skylark10/init
Normal file
6
tutorial/Skylark10/init
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _Skylark10_icpp_init_stub
|
||||
#define _Skylark10_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "Skylark/init"
|
||||
#include "plugin/sqlite3/init"
|
||||
#endif
|
||||
110
tutorial/Skylark10/main.cpp
Normal file
110
tutorial/Skylark10/main.cpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#include <Skylark/Skylark.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define MODEL <Skylark09/myapp.sch>
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#include <Sql/sch_header.h>
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
SKYLARK(HomePage, "")
|
||||
{
|
||||
http("PERSON", Select(SqlAll()).From(PERSON).OrderBy(LASTNAME, NAME))
|
||||
.RenderResult("Skylark10/index");
|
||||
}
|
||||
|
||||
SKYLARK(SubmitNew, "create/submit:POST")
|
||||
{
|
||||
SQL * http.Insert(PERSON);
|
||||
http.Redirect(HomePage);
|
||||
}
|
||||
|
||||
SKYLARK(New, "create")
|
||||
{
|
||||
http("ACTION", SubmitNew)
|
||||
.RenderResult("Skylark10/Dialog");
|
||||
}
|
||||
|
||||
SKYLARK(SubmitEdit, "edit/submit/*:POST")
|
||||
{
|
||||
SQL * http.Update(PERSON).Where(ID == http.Int(0));
|
||||
http.Redirect(HomePage);
|
||||
}
|
||||
|
||||
SKYLARK(Edit, "edit/*")
|
||||
{
|
||||
int id = http.Int(0);
|
||||
http
|
||||
(Select(SqlAll()).From(PERSON).Where(ID == id))
|
||||
("ID", id)
|
||||
("ACTION", SubmitEdit, id)
|
||||
.RenderResult("Skylark10/Dialog");
|
||||
}
|
||||
|
||||
struct MyApp : SkylarkApp {
|
||||
virtual void WorkThread();
|
||||
|
||||
MyApp() {
|
||||
root = "myapp";
|
||||
threads = 1; // Sqlite3 does not like threads...
|
||||
#ifdef _DEBUG
|
||||
prefork = 0;
|
||||
use_caching = false;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
void InitModel()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
sch.SaveNormal();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenSQL(Sqlite3Session& sqlite3)
|
||||
{
|
||||
if(!sqlite3.Open(ConfigFile("db"))) {
|
||||
LOG("Can't create or open database file\n");
|
||||
Exit(1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
sqlite3.LogErrors();
|
||||
sqlite3.SetTrace();
|
||||
#endif
|
||||
SQL = sqlite3;
|
||||
}
|
||||
|
||||
void MyApp::WorkThread()
|
||||
{
|
||||
Sqlite3Session sqlite3;
|
||||
OpenSQL(sqlite3);
|
||||
RunThread();
|
||||
}
|
||||
|
||||
void InitDB()
|
||||
{
|
||||
Sqlite3Session sqlsession;
|
||||
OpenSQL(sqlsession);
|
||||
SqlSchema sch(SQLITE3);
|
||||
All_Tables(sch);
|
||||
SqlPerformScript(sch.Upgrade());
|
||||
SqlPerformScript(sch.Attributes());
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
StdLogSetup(LOG_FILE|LOG_COUT);
|
||||
Ini::skylark_log = true;
|
||||
#endif
|
||||
|
||||
InitDB();
|
||||
|
||||
MyApp().Run();
|
||||
}
|
||||
5
tutorial/Skylark10/myapp.sch
Normal file
5
tutorial/Skylark10/myapp.sch
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TABLE_(PERSON)
|
||||
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
|
||||
STRING_ (NAME, 200)
|
||||
STRING_ (LASTNAME, 200)
|
||||
END_TABLE
|
||||
Loading…
Add table
Add a link
Reference in a new issue