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
);
14 strcpy(statement
, "CREATE TABLE t1 (f1 int, f2 int, f3 char(20), primary key (f2));");
16 rv
= stmt
->prepare(statement
);
17 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
18 rv
= stmt
->execute(rows
);
19 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
21 printf("AFTER CREATE TABLE operation\n");
25 strcpy(statement
,"INSERT INTO t1 VALUES(1234,?,'CSQL');");
26 rv
= stmt
->prepare(statement
);
27 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
28 printf("AFTER INSERT PREPARE operation\n");
34 rv
= con
->beginTrans();
35 //stmt->setIntParam(1, rnd);
36 stmt
->setIntParam(1, i
);
37 rv
= stmt
->execute(rows
);
38 if (rv
== ErrUnique
) {
39 printf("Unique Key Violation Error\n");
41 } else if (rv
!= OK
) {
42 printError(rv
, "Insert failed with ret val %d", rv
);
47 printf("AFTER INSERT EXECUTE operation\n");
50 printf("AFTER STMT FREE operation\n");
53 printf("AFTER DROP TABLE\n");
54 strcpy(statement
, "DROP TABLE t1");
55 rv
= stmt
->prepare(statement
);
56 if (rv
!= OK
) {con
->disconnect();delete stmt
; delete con
; return -1; }
61 printf("AFTER disconnect\n");