1 /***************************************************************************
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
5 ***************************************************************************/
8 #include<AbsSqlStatement.h>
12 AbsSqlConnection
*con
= SqlFactory::createConnection(CSql
);
13 rv
= con
->connect("root", "manager");
14 if (rv
!= OK
) return 1;
15 AbsSqlStatement
*stmt
= SqlFactory::createStatement(CSql
);
16 stmt
->setConnection(con
);
18 strcpy(statement
, "CREATE TABLE t1 (f1 int, f2 char(20), primary key (f1));");
20 rv
= stmt
->prepare(statement
);
21 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
22 rv
= stmt
->execute(rows
);
23 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
25 printf("Table t1 created\n");
27 strcpy(statement
, "INSERT INTO t1 (f1, f2) VALUES (?, ?);");
30 strcpy(name
, "Rithish");
31 rv
= stmt
->prepare(statement
);
32 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
34 for (int i
= 0 ; i
< 100 ; i
++)
36 rv
= con
->beginTrans();
39 stmt
->setIntParam(1, id1
);
40 sprintf(name
, "Gopika_%d", id1
);
41 stmt
->setStringParam(2, name
);
42 rv
= stmt
->execute(rows
);
48 printf("Total Rows Inserted %d\n", count
);
51 strcpy(statement
, "SELECT * FROM t1 where f1 = ?;");
52 rv
= stmt
->prepare(statement
);
53 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
54 stmt
->bindField(1, &id1
);
55 stmt
->bindField(2, name
);
56 for (int i
= 0 ; i
< 10 ; i
++)
58 rv
= con
->beginTrans();
60 stmt
->setIntParam(1, i
);
62 while (stmt
->fetch() != NULL
) {
63 printf("Row value is %d %s\n", id1
, name
);
72 strcpy(statement
, "DROP TABLE t1;");
73 rv
= stmt
->prepare(statement
);
74 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
75 rv
= stmt
->execute(rows
);
76 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
78 printf("Table dropped\n");