ultimatepp/examples/AddressBookWeb/Main.cpp
cxl 611c4e1bef .examples
git-svn-id: svn://ultimatepp.org/upp/trunk@5378 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2012-09-22 07:48:27 +00:00

73 lines
1.3 KiB
C++

#include "AddressBook.h"
#include <Sql/sch_schema.h>
#include <Sql/sch_source.h>
#define IMAGECLASS AdrBookImg
#define IMAGEFILE <AddressBookWeb/AdrBook.iml>
#include <Draw/iml_header.h>
#define IMAGECLASS AdrBookImg
#define IMAGEFILE <AddressBookWeb/AdrBook.iml>
#include <Draw/iml_source.h>
struct AdrBook : SkylarkApp {
void WorkThread();
AdrBook();
};
void OpenSQL(Sqlite3Session& sqlite3)
{
if(!sqlite3.Open(ConfigFile("db.sqlite3"))) {
LOG("Can't create or open database file\n");
Exit(1);
}
#ifdef _DEBUG
sqlite3.LogErrors();
sqlite3.SetTrace();
#endif
SQL = sqlite3;
}
void InitModel()
{
#ifdef _DEBUG
Sqlite3Session sqlsession;
OpenSQL(sqlsession);
SqlSchema sch(SQLITE3);
All_Tables(sch);
SqlPerformScript(sch.Upgrade());
SqlPerformScript(sch.Attributes());
sch.SaveNormal();
#endif
}
void AdrBook::WorkThread()
{
Sqlite3Session sqlite3;
OpenSQL(sqlite3);
RunThread();
}
AdrBook::AdrBook()
{
prefork = 0;
threads = 1; // Sqlite3 is not good with threads or concurrency...
#ifdef _DEBUG
use_caching = false;
#endif
}
// After starting the server, enter "127.0.0.1:8001" in your browser
CONSOLE_APP_MAIN
{
#ifdef _DEBUG
StdLogSetup(LOG_FILE|LOG_COUT);
Ini::skylark_log = true;
SKYLARKLOG("Active");
#endif
InitModel();
AdrBook().Run();
}