adding test scripts
[csql.git] / test / sqlapi / Select / selecttest3.c
blob4076ebaee9809b0a790a56575e809d46df6f2c59
1 /* create table T1 with two fields,
2 * insert 10 rows into the table ,
3 * select from nonexisting table.
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[32] = "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 T11;");
52 rv = stmt->prepare(statement);
53 if(rv !=OK) {
54 printf("test script passed\n");
55 strcpy(statement,"DROP TABLE T1;");
56 rv = stmt->prepare(statement);
57 rv = stmt->execute(rows);
58 if(rv==OK){printf("Table dropped\n");}
59 stmt->free(); delete stmt; delete con;
60 return 0;
61 } else if(rv==OK) {
62 printf("Test script failed\n");
63 return 5;
64 } else {
65 stmt->bindField(1,&f1var);
66 stmt->bindField(2,f2var);
67 count = 0;
68 rv = con->beginTrans();
69 if(rv!=OK)return 6;
70 stmt->execute(rows);
71 while(stmt->fetch()!=NULL) { count++; }
72 stmt->close();
73 rv = con->commit();
74 if(rv!=OK) { delete stmt; delete con; return 7; }
75 printf("Total row fetched=%d\n",count);
77 stmt->free();
78 rv = stmt->prepare(statement);
79 rv = stmt->execute(rows);
80 if(rv==OK){printf("Table dropped\n");}
81 stmt->free(); delete stmt; delete con;
82 return 0;