1 /* create table t1 with 10 fields,( f2 NOT NULL , f3 CHAR(20) DEFAULT 'LAKSHYA')
2 * insert 10 rows for 9 Fields except f3 Field into the table
3 * noofprojFields should return 5.
4 * getProjFldInfo() for all fields.
5 * select with 5 parameters withIwhere clause.(WHERE f1=100)
12 AbsSqlConnection
*con
= createConnection();
13 rv
= con
->connect("root","manager");
16 AbsSqlStatement
*stmt
= createStatement();
17 stmt
->setConnection(con
);
19 if(strcmp(getenv("DSN"),"oracle")==0)
20 strcpy(statement
,"CREATE TABLE t1(f1 number(9),f2 number(4),f3 CHAR(30) DEFAULT 'LAKSHYA',f4 FLOAT,f5 FLOAT,f6 DATE,f8 TIMESTAMP,f9 number(9),f10 number(18));");
21 else if(strcmp(getenv("DSN"),"psql")==0)
22 strcpy(statement
,"CREATE TABLE t1(f1 INT,f2 SMALLINT,f3 CHAR(30) DEFAULT 'LAKSHYA',f4 FLOAT4,f5 FLOAT4,f6 DATE,f7 TIME,f8 TIMESTAMP,f9 INT,f10 BIGINT);");
23 else if(strcmp(getenv("DSN"),"sybase")==0)
24 strcpy(statement
,"CREATE TABLE t1(f1 INT,f2 SMALLINT,f3 CHAR(30) DEFAULT 'LAKSHYA',f4 REAL,f5 REAL,f6 DATE,f7 TIME,f8 DATETIME,f9 INT,f10 BIGINT);");
25 else if(strcmp(getenv("DSN"),"db2")==0)
26 strcpy(statement
,"CREATE TABLE t1(f1 INT,f2 SMALLINT,f3 CHAR(30) DEFAULT 'LAKSHYA',f4 REAL,f5 REAL,f6 DATE,f7 TIME,f8 TIMESTAMP,f9 INT,f10 BIGINT)");
28 strcpy(statement
,"CREATE TABLE t1(f1 INT,f2 SMALLINT,f3 CHAR(30) DEFAULT 'LAKSHYA',f4 FLOAT,f5 FLOAT,f6 DATE,f7 TIME,f8 TIMESTAMP,f9 INT,f10 BIGINT);");
31 rv
= stmt
->prepare(statement
);
39 rv
= stmt
->execute(rows
);
48 printf("'t1' Table created\n");
51 if(strcmp(getenv("DSN"),"oracle")==0)
52 strcpy(statement
,"INSERT INTO t1(f1,f2,f4,f5,f6,f8,f9,f10)VALUES(?,?,?,?,?,?,?,?);");
53 else if(strcmp(getenv("DSN"),"db2")==0)
54 strcpy(statement
,"INSERT INTO t1(f1,f2,f4,f5,f6,f7,f8,f9,f10)VALUES(?,?,?,?,?,?,?,?,?)");
56 strcpy(statement
,"INSERT INTO t1(f1,f2,f4,f5,f6,f7,f8,f9,f10)VALUES(?,?,?,?,?,?,?,?,?);");
60 // char f3var[20] = "prabakaran";
70 f8var
.setDate(2008,1,21);
71 f8var
.setTime(12,29,30);
74 long long f10var
= 12000;
76 rv
= stmt
->prepare(statement
);
91 rv
= con
->beginTrans();
95 stmt
->setIntParam(1,f1var
);
96 stmt
->setShortParam(2,f2var
);
97 //stmt->setStringParam(3,f3var);
98 stmt
->setFloatParam(3,f4var
);
99 stmt
->setFloatParam(4,f5var
);
100 stmt
->setDateParam(5,f6var
);
101 if(strcmp(getenv("DSN"),"oracle")==0){
102 stmt
->setTimeStampParam(6,f8var
);
103 stmt
->setIntParam(7,f9var
);
104 stmt
->setLongLongParam(8,f10var
);
106 stmt
->setTimeParam(6,f7var
);
107 stmt
->setTimeStampParam(7,f8var
);
108 stmt
->setIntParam(8,f9var
);
109 stmt
->setLongLongParam(9,f10var
);
112 rv
= stmt
->execute(rows
);
120 printf("%d Rows Inserted\n",count
);
123 //*******************************************
125 strcpy(statement
,"SELECT f8,f10,f2,f6,f3 FROM t1 WHERE f1=100;");
126 if(strcmp(getenv("DSN"),"db2")==0)
127 strcpy(statement
,"SELECT f8,f10,f2,f6,f3 FROM t1 WHERE f1=100");
128 rv
= stmt
->prepare(statement
);
131 nop
= stmt
->noOfProjFields();
133 printf("Total number of projection fields in the select statement=%d\n",nop
);
136 FieldInfo
*field
= new FieldInfo();
142 char defaultValueBuf
[10];
153 char f3var
[32]="jitu";
155 stmt
->bindField(1,&f8var
);
156 stmt
->bindField(2,&f10var
);
157 stmt
->bindField(3,&f2var
);
158 stmt
->bindField(4,&f6var
);
159 stmt
->bindField(5,f3var
);
163 rv
= con
->beginTrans();
166 while(stmt
->fetch()!=NULL
)
169 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
);
183 printf("Total row fetched=%d\n",count
);
187 strcpy(statement
,"DROP TABLE t1;");
188 if(strcmp(getenv("DSN"),"db2")==0)
189 strcpy(statement
,"DROP TABLE t1");
190 rv
= stmt
->prepare(statement
);
197 rv
= stmt
->execute(rows
);
206 printf("Table dropped\n");