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
);
17 strcpy(statement
,"INSERT INTO t1 VALUES(1234,?);");
18 rv
= stmt
->prepare(statement
);
19 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
21 rv
= con
->beginTrans();
22 stmt
->setIntParam(1, 100);
23 rv
= stmt
->execute(rows
);
24 stmt
->setIntParam(1, 200);
25 rv
= stmt
->execute(rows
);
27 printError(rv
, "Insert failed with ret val %d", rv
);
32 strcpy(statement
, "UPDATE t1 set f1=? where f2=200;");
33 rv
= stmt
->prepare(statement
);
34 stmt
->setIntParam(1, 200);
35 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
36 rv
= con
->beginTrans();
37 rv
= stmt
->execute(rows
);
39 printError(rv
, "Update failed with ret val %d", rv
);
44 strcpy(statement
, "DELETE from t1 where f2=?;");
45 rv
= stmt
->prepare(statement
);
46 stmt
->setIntParam(1, 100);
47 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
48 rv
= con
->beginTrans();
49 rv
= stmt
->execute(rows
);
51 printError(rv
, "Delete failed with ret val %d", rv
);
56 strcpy(statement
, "SELECT f1 from t1 where f2=200;");
57 rv
= stmt
->prepare(statement
);
58 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
59 rv
= con
->beginTrans();
61 stmt
->bindField(1, &val
);
62 rv
= stmt
->execute(rows
);
63 while (stmt
->fetch() != NULL
)
65 printf("Tuple value %d\n", val
);