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; }
23 strcpy(statement
,"INSERT INTO t1 VALUES(1234,?,'CSQL');");
24 rv
= stmt
->prepare(statement
);
25 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
26 printf("AFTER INSERT PREPARE operation\n");
31 rv
= con
->beginTrans();
32 stmt
->setIntParam(1, i
);
33 rv
= stmt
->execute(rows
);
34 if (rv
== ErrUnique
) {
35 printf("Unique Key Violation Error\n");
37 } else if (rv
!= OK
) {
38 printError(rv
, "Insert failed with ret val %d", rv
);
45 printf("rename TABLE\n");
46 strcpy(statement
, "rename TABLE t1 to t2");
47 rv
= stmt
->prepare(statement
);
48 if (rv
!= OK
) {con
->disconnect();delete stmt
; delete con
; return -1; }
49 rv
= con
->beginTrans();
54 strcpy(statement
,"INSERT INTO t1 VALUES(1234,?,'CSQL');");
55 rv
= stmt
->prepare(statement
);
56 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
57 printf("AFTER INSERT PREPARE operation\n");
61 rv
= con
->beginTrans();
62 stmt
->setIntParam(1, i
);
63 rv
= stmt
->execute(rows
);
64 if (rv
== ErrUnique
) {
65 printf("Unique Key Violation Error\n");
67 } else if (rv
!= OK
) {
68 printError(rv
, "Insert failed with ret val %d", rv
);
75 strcpy(statement
, "drop TABLE t2");
76 rv
= stmt
->prepare(statement
);
77 if (rv
!= OK
) {con
->disconnect();delete stmt
; delete con
; return -1; }