adding test scripts
[csql.git] / test / sqlapi / Select / selecttest6.c
blob838ffe1bebd682dd13e428d151929d074389ce19
1 /* create table T1 with two fields,
2 * insert 10 rows into the table ,
3 * fetch without prepare.
5 * Author : Jitendra Lenka
6 */
8 #include"common.h"
10 int main()
12 DbRetVal rv = OK;
13 AbsSqlConnection *con = createConnection();
14 rv = con->connect("root","manager");
15 if(rv!=OK)return 1;
16 AbsSqlStatement *stmt = createStatement();
17 stmt->setConnection(con);
18 char statement[200];
19 strcpy(statement,"CREATE TABLE T1(F1 INT,F2 CHAR(20));");
20 int rows=0;
21 rv = stmt->prepare(statement);
22 if(rv!=OK) { delete stmt; delete con; return 1; }
23 rv = stmt->execute(rows);
24 if(rv!=OK) { delete stmt; delete con; return 2; }
25 stmt->free();
26 printf("Table created\n");
27 // insert records
28 strcpy(statement,"INSERT INTO T1 VALUES(?,?);");
29 int f1var = 1;
30 char f2var[24] = "lakshya";
31 rv = stmt->prepare(statement);
32 if(rv!=OK) { delete stmt; delete con; return 3; }
33 int count=0;
34 for(int i=0;i<2;i++) {
35 for(int j=0;j<5;j++) {
36 f1var = j;
37 rv = con->beginTrans();
38 if(rv!=OK)break;
39 stmt->setIntParam(1,f1var);
40 stmt->setStringParam(2,f2var);
41 rv = stmt->execute(rows);
42 if(rv!=OK)break;
43 rv = con->commit();
44 if(rv!=OK)break;
45 count++;
47 printf("%d rows inserted\n",count);
49 stmt->free();
50 //*******************************************
51 strcpy(statement,"SELECT * FROM T1;");
52 stmt->bindField(1,&f1var);
53 stmt->bindField(2,f2var);
54 void *ret;
55 count = 0;
56 rv = con->beginTrans();
57 if(rv!=OK)return 6;
58 stmt->execute(rows);
59 while(1) {
60 ret = ((char*)stmt->fetch());
61 if(ret ==NULL) {
62 printf("fetch failed without prepare\n");
63 strcpy(statement,"DROP TABLE T1;");
64 rv = stmt->prepare(statement);
65 rv = stmt->execute(rows);
66 if(rv==OK){printf("Table dropped successfully\n");}
67 stmt->free(); delete stmt; delete con; return 0;
69 printf("Test script failed\n");
71 delete stmt; delete con;
72 return 8;