My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <MySql/MySql.h>

using namespace Upp;

#define SCHEMADIALECT <MySql/MySqlSchema.h>
#define MODEL <SQL_MySql/schema.sch>
#include <Sql/sch_header.h>
#include <Sql/sch_source.h>
#include <Sql/sch_schema.h>

CONSOLE_APP_MAIN
{
MySqlSession session;
// edit the connection parameters if necessary
if(session.Connect("root", "Passw0rd", "test")) {
Cout() << "Connected\n";
SQL = session;

SqlSchema sch(MY_SQL);
All_Tables(sch);
// create the table if necessary
SqlPerformScript(sch.Upgrade());
SqlPerformScript(sch.Attributes());
SQL.ClearError();

try {
// insert some random data
SQL & Insert(TEST_TABLE)(VALUE, Uuid::Create().ToString());
// fetch some data
Sql sql;
sql * Select(ID, VALUE).From(TEST_TABLE)
.OrderBy(Descending(ID))
.Limit(5);
while(sql.Fetch())
Cout() << AsString(sql[0]) << ": " << AsString(sql[VALUE]) << "\n";
}
catch(SqlExc &ex) {
Cerr() << "ERROR: " << ex << "\n";
SetExitCode(1);
}
}
else {
Cerr() <<"ERROR: Unable to connect to database\n";
SetExitCode(1);
}
}

Change log

r4792 by cxl on Apr 16, 2012   Diff
reference: GuiWebCrawler
Go to: 
Project members, sign in to write a code review

Older revisions

r4168 by cxl on Nov 12, 2011   Diff
.reference
r4165 by cxl on Nov 12, 2011   Diff
.reference: replace SQL_MySql example
(thanks dolik.rce)
r281 by mdelfede on Jun 7, 2008   Diff
changed svn layout
All revisions of this file

File info

Size: 1112 bytes, 46 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting