1 /* create table T1 with 10 fields.
2 * insert some records into it.
3 * update T1 WITH ALL 8 PARAMETERS.
4 noOfParamFields() should return 8.
7 * Author : Jitendra Lenka.
10 #include<AbsSqlStatement.h>
11 #include<SqlFactory.h>
17 AbsSqlConnection
*con
= SqlFactory :: createConnection(CSql
);
18 rv
= con
->connect("root","manager");
21 AbsSqlStatement
*stmt
= SqlFactory :: createStatement(CSql
);
22 stmt
->setConnection(con
);
24 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));");
27 rv
= stmt
->prepare(statement
);
35 rv
= stmt
->execute(rows
);
44 printf("Table created\n");
48 strcpy(statement
,"INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?,?,?);");
52 char f3var
[20]="jitendra";
56 f6var
.set(2008,01,21);
62 f8var
.setDate(2008,01,21);
63 f8var
.setTime(12,29,30);
66 long long f10var
= 12000;
67 char f11var
[8]="23fe";
68 rv
= stmt
->prepare(statement
);
80 rv
= con
->beginTrans();
84 stmt
->setIntParam(1,f1var
);
85 stmt
->setShortParam(2,f2var
);
86 stmt
->setStringParam(3,f3var
);
87 stmt
->setFloatParam(4,f4var
);
88 stmt
->setFloatParam(5,f5var
);
89 stmt
->setDateParam(6,f6var
);
90 stmt
->setTimeParam(7,f7var
);
91 stmt
->setTimeStampParam(8,f8var
);
92 stmt
->setIntParam(9,f9var
);
93 stmt
->setLongLongParam(10,f10var
);
94 stmt
->setBinaryParam(11,f11var
);
95 rv
= stmt
->execute(rows
);
101 printf("%d Rows inserted \n",count
);
106 //**********************************************************
109 strcpy(statement
,"UPDATE T1 SET F10=?,F8=?,F6=?,F5=?,F4=?,F3=?,F11=? WHERE F2=?;");
110 rv
= stmt
->prepare(statement
);
113 nop
= stmt
->noOfParamFields();
114 printf("noOfParamFields return=%d\n",nop
);
117 long long f10var1
=15000;
119 f8var1
.setDate(2007,3,30);
120 f8var1
.setTime(10,25,55);
123 f6var1
.set(2007,3,30);
127 char f3var1
[10]="lakshya";
128 char f11var1
[8]="ab12";
135 rv
= con
->beginTrans();
139 stmt
->setShortParam(8,f2var1
);
140 stmt
->setLongLongParam(1,f10var1
);
141 stmt
->setTimeStampParam(2,f8var1
);
142 stmt
->setDateParam(3,f6var1
);
143 stmt
->setFloatParam(4,f5var1
);
144 stmt
->setFloatParam(5,f4var1
);
145 stmt
->setStringParam(6,f3var1
);
146 stmt
->setBinaryParam(7,f11var1
);
148 //stmt->setShortParam(7,f2var1);
150 rv
= stmt
->execute(rows
);
159 printf("%d Rows updated\n",count
);
161 //**********************************************************
164 strcpy(statement
,"SELECT * FROM T1;");
165 rv
= stmt
->prepare(statement
);
173 stmt
->bindField(1,&f1var
);
174 stmt
->bindField(2,&f2var
);
175 stmt
->bindField(3,f3var
);
176 stmt
->bindField(4,&f4var
);
177 stmt
->bindField(5,&f5var
);
178 stmt
->bindField(6,&f6var
);
179 stmt
->bindField(7,&f7var
);
180 stmt
->bindField(8,&f8var
);
181 stmt
->bindField(9,&f9var
);
182 stmt
->bindField(10,&f10var
);
183 stmt
->bindField(11,f11var
);
185 rv
= con
->beginTrans();
188 while(stmt
->fetch() !=NULL
)
190 if(f1var
==5)printf("\n");
191 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
);
193 AllDataType::printVal(f11var
,typeBinary
,4);
209 printf("%d Rows fetched=%d\n",count
);
213 strcpy(statement
,"DROP TABLE T1;");
214 rv
= stmt
->prepare(statement
);
221 rv
= stmt
->execute(rows
);
229 printf("Table dropped\n");