adding test scripts
[csql.git] / test / sqlapi / Select / selecttest1.c
blobf515e71af0e437c3ca852b8f11b1f780cfc0dab0
1 /* create table T1 with 10 fields,
2 * insert 10 rows into the table ,
3 * noofprojFields shoul dreturn 10.
4 * call fetch and count the record.
6 * Author : Jitendra Lenka
7 */
9 #include"common.h"
11 int main()
13 DbRetVal rv = OK;
14 AbsSqlConnection *con = createConnection();
15 rv = con->connect("root","manager");
16 if(rv!=OK)return 1;
17 AbsSqlStatement *stmt = createStatement();
18 stmt->setConnection(con);
19 char statement[200];
20 strcpy(statement,"CREATE TABLE T1(F1 INT,F2 SMALLINT,F3 CHAR(30),F4 FLOAT,F5 FLOAT,F6 DATE,F7 TIME,F8 TIMESTAMP,F9 INT,F10 BIGINT);");
21 int rows=0;
22 rv = stmt->prepare(statement);
23 if(rv!=OK) { delete stmt; delete con; return 2; }
24 rv = stmt->execute(rows);
25 if(rv!=OK) { delete stmt; delete con; return 3; }
26 stmt->free();
27 printf("'T1' table created\n");
28 //insert records
29 strcpy(statement,"INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?,?);");
30 int f1var = 99;
31 short int f2var = 1;
32 char f3var[32] = "lakshya";
33 float f4var = 5.5;
34 float f5var = 10.50;
35 Date f6var;
36 f6var.set(2008,1,21);
37 Time f7var;
38 f7var.set(12,29,30);
39 TimeStamp f8var;
40 f8var.setDate(2008,1,21);
41 f8var.setTime(12,29,30);
42 int f9var = 20;
43 long long f10var = 12000;
44 rv = stmt->prepare(statement);
45 if(rv!=OK) { delete stmt; delete con; return 4; }
46 int count=0;
47 for(int i=0;i<2;i++) {
48 f1var = f1var+i;
49 for(int j=0;j<5;j++) {
50 rv = con->beginTrans();
51 if(rv!=OK)break;
52 stmt->setIntParam(1,f1var);
53 stmt->setShortParam(2,f2var);
54 stmt->setStringParam(3,f3var);
55 stmt->setFloatParam(4,f4var);
56 stmt->setFloatParam(5,f5var);
57 stmt->setDateParam(6,f6var);
58 stmt->setTimeParam(7,f7var);
59 stmt->setTimeStampParam(8,f8var);
60 stmt->setIntParam(9,f9var);
61 stmt->setLongLongParam(10,f10var);
62 rv = stmt->execute(rows);
63 if(rv!=OK)break;
64 rv = con->commit();
65 if(rv!=OK)break;
66 count++;
69 printf("%d Rows Inserted\n",count);
70 stmt->free();
71 //*******************************************
72 strcpy(statement,"SELECT * FROM T1 WHERE F1=100;");
73 rv = stmt->prepare(statement);
74 int nop;
75 nop = stmt->noOfProjFields();
76 printf("noOfProjFields returns=%d\n",nop);
77 if(rv !=OK) { delete stmt; delete con; return 5; }
78 stmt->bindField(1,&f1var);
79 stmt->bindField(2,&f2var);
80 stmt->bindField(3,f3var);
81 stmt->bindField(4,&f4var);
82 stmt->bindField(5,&f5var);
83 stmt->bindField(6,&f6var);
84 stmt->bindField(7,&f7var);
85 stmt->bindField(8,&f8var);
86 stmt->bindField(9,&f9var);
87 stmt->bindField(10,&f10var);
88 count = 0;
89 rv = con->beginTrans();
90 if(rv!=OK)return 6;
91 stmt->execute(rows);
92 printf("Fetching starts on table 'T1' :\n");
93 while(stmt->fetch()!=NULL) {
94 printf("F1=%d | F2=%hd | F3=%s | F4=%f | F5=%f | DATE=%d-%d-%d | TIME=%d:%d:%d | TIMESTAMP=%d-%d-%d %d:%d:%d | F9=%d | F10=%lld \n",f1var,f2var,f3var,f4var,f5var,f6var.year(),f6var.month(),f6var.dayOfMonth(),f7var.hours(),f7var.minutes(),f7var.seconds(),f8var.year(),f8var.month(),f8var.dayOfMonth(),f8var.hours(),f8var.minutes(),f8var.seconds(),f9var,f10var);
95 count++;
97 stmt->close();
98 rv = con->commit();
99 if(rv!=OK) { delete stmt; delete con; return 7; }
100 printf("%d Rows fetched\n",count);
101 stmt->free();
102 strcpy(statement,"DROP TABLE T1;");
103 rv = stmt->prepare(statement);
104 if(rv!=OK) { delete stmt; delete con; return 8; }
105 rv = stmt->execute(rows);
106 if(rv!=OK) { delete stmt; delete con; return 9; }
107 printf("'T1' table dropped\n");
108 stmt->free(); delete stmt; delete con;
109 return 0;