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 (f1));");
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,5,'CSQL');");
26 rv
= stmt
->prepare(statement
);
27 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
28 printf("AFTER INSERT PREPARE operation\n");
31 rv
= con
->beginTrans();
32 rv
= stmt
->execute(rows
);
34 printError(rv
, "Insert failed with ret val %d", rv
);
38 printf("AFTER INSERT EXECUTE operation\n");
41 printf("AFTER STMT FREE operation\n");
44 strcpy(statement
, "UPDATE t1 set f2=10 where f1=1234;");
45 rv
= stmt
->prepare(statement
);
46 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
47 printf("AFTER UPDATE PREPARE operation\n");
49 rv
= con
->beginTrans();
50 rv
= stmt
->execute(rows
);
52 printError(rv
, "Update failed with ret val %d", rv
);
57 printf("AFTER STMT FREE operation\n");
60 strcpy(statement
, "DELETE from t1 where f2=10;");
61 rv
= stmt
->prepare(statement
);
62 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
63 printf("AFTER DELETE PREPARE operation\n");
65 rv
= con
->beginTrans();
66 rv
= stmt
->execute(rows
);
68 printError(rv
, "Delete failed with ret val %d", rv
);
73 printf("AFTER STMT FREE operation\n");
76 strcpy(statement
, "SELECT f1 from t1 where f2=1;");
77 rv
= stmt
->prepare(statement
);
78 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
79 printf("AFTER SELECT PREPARE operation\n");
81 rv
= con
->beginTrans();
83 stmt
->bindField(1, &val
);
84 rv
= stmt
->execute(rows
);
85 while (stmt
->fetch() != NULL
)
87 printf("Tuple value %d\n", val
);
91 printf("AFTER STMT FREE operation\n");
94 strcpy(statement
, "DROP TABLE t1");
95 rv
= stmt
->prepare(statement
);
96 if (rv
!= OK
) {con
->disconnect();delete stmt
; delete con
; return -1; }
102 printf("AFTER disconnect\n");