1 #include <SqlFactory.h>
3 int main(int argc
, char **argv
)
6 struct timeval timeout
;
7 struct timeval timeStamp
;
8 AbsSqlConnection
*con
= SqlFactory::createConnection(CSql
);
9 rv
= con
->connect("root","manager");
11 AbsSqlStatement
*stmt
= SqlFactory::createStatement(CSql
);
12 stmt
->setConnection(con
);
13 AbsSqlStatement
*dropstmt
= SqlFactory::createStatement(CSql
);
14 dropstmt
->setConnection(con
);
18 strcpy(statement
,"INSERT INTO t1 VALUES(?, ?, 'CSQL');");
19 rv
= stmt
->prepare(statement
);
20 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
21 rv
= con
->beginTrans();
22 stmt
->setIntParam(1, 100);
23 stmt
->setIntParam(2, 100);
24 rv
= stmt
->execute(rows
);
26 printError(rv
, "Insert failed with ret val %d", rv
);
31 printf("creating index\n");
32 strcpy(statement
, "create index idx1 on t1(f2);");
33 rv
= dropstmt
->prepare(statement
);
35 printf("create index on table failed\n");
36 con
->disconnect();delete stmt
; delete con
; return -1;
38 dropstmt
->execute(rows
);
40 printf("After create index \n");
43 rv
= con
->beginTrans();
44 stmt
->setIntParam(1, 200);
45 stmt
->setIntParam(2, 200);
46 rv
= stmt
->execute(rows
);
48 printError(rv
, "Insert failed with ret val %d", rv
);
53 printf("After reusing cached insert stmt\n");
55 strcpy(statement
,"INSERT INTO t1 VALUES(?, ?, 'CSQL');");
56 rv
= stmt
->prepare(statement
);
57 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
58 rv
= con
->beginTrans();
59 stmt
->setIntParam(1, 300);
60 stmt
->setIntParam(2, 300);
61 rv
= stmt
->execute(rows
);
63 printError(rv
, "Insert failed with ret val %d", rv
);