adding test scripts
[csql.git] / test / adapter / Select / selecttest6.c
blob368e445b6580f6a616e6921be62e7f8ecd5ae08e
1 /* create table t1 with two fields,
2 * insert 10 rows into the table ,
3 * fetch without prepare.
4 */
6 #include "common.h"
7 int main()
9 DbRetVal rv = OK;
10 AbsSqlConnection *con = createConnection();
11 rv = con->connect("root","manager");
12 if(rv!=OK)return 1;
14 AbsSqlStatement *stmt = createStatement();
15 stmt->setConnection(con);
16 char statement[200];
18 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 CHAR(20));");
19 if(strcmp(getenv("DSN"),"db2")==0)
20 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 CHAR(20))");
22 int rows=0;
23 rv = stmt->prepare(statement);
24 if(rv!=OK)
26 delete stmt;
27 delete con;
28 return 1;
31 rv = stmt->execute(rows);
32 if(rv!=OK)
34 delete stmt;
35 delete con;
36 return 2;
38 stmt->free();
39 printf("Table created\n");
40 con->commit();
41 // insert records
43 strcpy(statement,"INSERT INTO t1 VALUES(?,?);");
44 if(strcmp(getenv("DSN"),"db2")==0)
45 strcpy(statement,"INSERT INTO t1 VALUES(?,?)");
47 int f1var = 1;
48 char f2var[20] = "lakshya";
51 rv = stmt->prepare(statement);
52 if(rv!=OK)
54 delete stmt;
55 delete con;
56 return 3;
59 int count=0;
61 for(int i=0;i<2;i++)
64 for(int j=0;j<5;j++)
66 f1var = j;
67 rv = con->beginTrans();
68 if(rv!=OK)break;
71 stmt->setIntParam(1,f1var);
72 stmt->setStringParam(2,f2var);
74 rv = stmt->execute(rows);
75 if(rv!=OK)break;
76 rv = con->commit();
77 if(rv!=OK)break;
78 count++;
80 printf("%d rows inserted\n",count);
82 stmt->free();
84 //*******************************************
86 strcpy(statement,"SELECT * FROM t1;");
87 if(strcmp(getenv("DSN"),"db2")==0)
88 strcpy(statement,"SELECT * FROM t1");
89 /*rv = stmt->prepare(statement);
90 if(rv!=OK)
92 delete stmt;
93 delete con;
94 return 1;
95 } */
96 stmt->bindField(1,&f1var);
97 stmt->bindField(2,f2var);
99 void *ret;
100 count = 0;
101 rv = con->beginTrans();
102 if(rv!=OK)return 6;
103 stmt->execute(rows);
107 while(1)
109 ret = ((char*)stmt->fetch());
110 if(ret ==NULL)
113 printf("fetch failed without prepare\n");
114 strcpy(statement,"DROP TABLE t1;");
115 if(strcmp(getenv("DSN"),"db2")==0)
116 strcpy(statement,"DROP TABLE t1;");
117 rv = stmt->prepare(statement);
118 rv = stmt->execute(rows);
119 if(rv==OK){printf("Table dropped successfully\n");}
120 stmt->free();
121 con->commit();
122 delete stmt;
123 delete con;
124 return 0;
126 printf("Test script failed\n");
128 delete stmt;
129 delete con;
130 return 8;