adding test scripts
[csql.git] / test / sqlapi / Parameter / paratest2.c
bloba1fe6764417fb7e02ff15e0a7640cb9c28f9dcd3
1 /* create table T1 with 10 fields.
2 * insert some records into it.
3 * select * from T1 with where clause;
4 */
6 #include"common.h"
8 int main()
10 DbRetVal rv = OK;
11 AbsSqlConnection *con= createConnection();
12 rv = con->connect("root","manager");
13 if(rv!=OK)return 1;
14 AbsSqlStatement *stmt = createStatement();
15 stmt->setConnection(con);
16 char statement[200];
17 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, F11 BINARY(4));");
18 int rows = 0;
19 rv = stmt->prepare(statement);
20 if(rv!=OK) { delete stmt; delete con; return 1; }
21 rv = stmt->execute(rows);
22 if(rv!=OK) { delete stmt; delete con; return 2; }
23 stmt->free();
24 printf("Table created\n");
25 // insert into table
26 strcpy(statement,"INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?,?,?);");
27 int f1var = 100;
28 short int f2var = 10;
29 char f3var[32]="jitendra";
30 float f4var = 5.5;
31 float f5var = 10.50;
32 Date f6var;
33 f6var.set(2007,01,21);
34 Time f7var;
35 f7var.set(12,29,30);
36 TimeStamp f8var;
37 f8var.setDate(2007,01,21);
38 f8var.setTime(12,29,30);
39 int f9var = 20;
40 long long f10var = 12000;
41 char f11var[8]="23fe";
42 rv = stmt->prepare(statement);
43 if(rv!=OK) { delete stmt; delete con; return 3; }
44 int count=0;
45 for(int i=0;i<10;i++) {
46 rv = con->beginTrans();
47 if (rv!=OK) break;
48 stmt->setIntParam(1,f1var);
49 stmt->setShortParam(2,f2var);
50 stmt->setStringParam(3,f3var);
51 stmt->setFloatParam(4,f4var);
52 stmt->setFloatParam(5,f5var);
53 stmt->setDateParam(6,f6var);
54 stmt->setTimeParam(7,f7var);
55 stmt->setTimeStampParam(8,f8var);
56 stmt->setIntParam(9,f9var);
57 stmt->setLongLongParam(10,f10var);
58 stmt->setBinaryParam(11,f11var, 8);
59 rv = stmt->execute(rows);
60 if(rv!=OK)break;
61 rv = con->commit();
62 if (rv != OK) break;
63 count++;
65 printf("Total rows inserted %d\n",count);
66 stmt->free();
67 //**********************************************************
68 // SELECT * FROM T1;
69 strcpy(statement,"SELECT * FROM T1 WHERE F1=? AND F2=? AND F3=? AND F4=? AND F5=? AND F6=? AND F7=? AND F8=? AND F9=? AND F10=? AND F11=?;");
70 rv = stmt->prepare(statement);
71 if(rv!=OK) { delete stmt; delete con; return 4; }
72 stmt->bindField(1,&f1var);
73 stmt->bindField(2,&f2var);
74 stmt->bindField(3,f3var);
75 stmt->bindField(4,&f4var);
76 stmt->bindField(5,&f5var);
77 stmt->bindField(6,&f6var);
78 stmt->bindField(7,&f7var);
79 stmt->bindField(8,&f8var);
80 stmt->bindField(9,&f9var);
81 stmt->bindField(10,&f10var);
82 stmt->bindField(11,f11var);
83 int f1var1=100;
84 short int f2var1=10;
85 char f3var1[20]="jitendra";
86 float f4var1=5.5;
87 float f5var1=10.50;
88 Date f6var1;
89 f6var1.set(2007,1,21);
90 Time f7var1;
91 f7var1.set(12,29,30);
92 TimeStamp f8var1;
93 f8var1.setDate(2007,1,21);
94 f8var1.setTime(12,29,30);
95 int f9var1=20;
96 long long f10var1=12000;
97 char f11var1[8]="23fe";
98 count=0;
99 rv = con->beginTrans();
100 if(rv!=OK)return 5;
101 stmt->setIntParam(1,f1var1);
102 stmt->setShortParam(2,f2var1);
103 stmt->setStringParam(3,f3var1);
104 stmt->setFloatParam(4,f4var1);
105 stmt->setFloatParam(5,f5var1);
106 stmt->setDateParam(6,f6var1);
107 stmt->setTimeParam(7,f7var1);
108 stmt->setTimeStampParam(8,f8var1);
109 stmt->setIntParam(9,f9var1);
110 stmt->setLongLongParam(10,f10var1);
111 stmt->setBinaryParam(11,f11var1, 8);
112 stmt->execute(rows);
113 while(stmt->fetch()!=NULL) {
114 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",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);
115 printf(" | ");
116 AllDataType::printVal(f11var,typeBinary,4);
117 printf("\n");
118 count++;
120 stmt->close();
121 rv = con->commit();
122 if(rv!=OK)return 6;
123 stmt->free();
124 printf("%d Tuples fetched\n",count);
125 strcpy(statement,"DROP TABLE T1;");
126 rv = stmt->prepare(statement);
127 if(rv!=OK){delete stmt; delete con; return -1;}
128 rv = stmt->execute(rows);
129 if(rv!=OK){delete stmt;delete con;return -1;}
130 printf("Table dropped\n");
131 stmt->free(); delete stmt; delete con;
132 return 0;