1 /* create table T1 with 10 fields,( F2 NOT NULL , F3 CHAR(20) DEFAULT 'LAKSHYA')
3 * insert 10 rows for 9 Fields except F3 Field into the table
4 * noofprojFields should return 5.
5 * getProjFldInfo() for all fields.
6 * select with 5 parameters withIwhere clause.(WHERE F1=100)
8 * Author : Jitendra Lenka
16 AbsSqlConnection
*con
= createConnection();
17 rv
= con
->connect("root","manager");
19 AbsSqlStatement
*stmt
= createStatement();
20 stmt
->setConnection(con
);
22 strcpy(statement
,"CREATE TABLE T1(F1 INT,F2 SMALLINT NOT NULL,F3 CHAR(30) DEFAULT 'LAKSHYA',F4 FLOAT,F5 FLOAT,F6 DATE,F7 TIME,F8 TIMESTAMP,F9 INT,F10 BIGINT);");
24 rv
= stmt
->prepare(statement
);
25 if(rv
!=OK
) { delete stmt
; delete con
; return 2; }
26 rv
= stmt
->execute(rows
);
27 if(rv
!=OK
) { delete stmt
; delete con
; return 3; }
29 printf("'T1' Table created\n");
31 strcpy(statement
,"INSERT INTO T1(F1,F2,F4,F5,F6,F7,F8,F9,F10)VALUES(?,?,?,?,?,?,?,?,?);");
34 // char f3var[20] = "prabakaran";
42 f8var
.setDate(2008,1,21);
43 f8var
.setTime(12,29,30);
45 long long f10var
= 12000;
46 rv
= stmt
->prepare(statement
);
47 if(rv
!=OK
) { delete stmt
; delete con
; return 4; }
49 for(int i
=0;i
<2;i
++) {
51 for(int j
=0;j
<5;j
++) {
52 rv
= con
->beginTrans();
54 stmt
->setIntParam(1,f1var
);
55 stmt
->setShortParam(2,f2var
);
56 //stmt->setStringParam(3,f3var);
57 stmt
->setFloatParam(3,f4var
);
58 stmt
->setFloatParam(4,f5var
);
59 stmt
->setDateParam(5,f6var
);
60 stmt
->setTimeParam(6,f7var
);
61 stmt
->setTimeStampParam(7,f8var
);
62 stmt
->setIntParam(8,f9var
);
63 stmt
->setLongLongParam(9,f10var
);
64 rv
= stmt
->execute(rows
);
71 printf("%d Rows Inserted\n",count
);
73 //*******************************************
74 strcpy(statement
,"SELECT F8,F10,F2,F6,F3 FROM T1 WHERE F1=100;");
75 rv
= stmt
->prepare(statement
);
77 nop
= stmt
->noOfProjFields();
79 printf("Total number of projection fields in the select statement=%d\n",nop
);
81 FieldInfo
*field
= new FieldInfo();
82 printf("\nFIELD INFORMATION :\n");
87 char defaultValueBuf
[10];
90 for(int i
=0;i
<=4;i
++) {
91 printf("\n***********************************************\n");
92 rv
= stmt
->getProjFldInfo(i
+1,field
);
94 printf("Field Name :%s\n", field
->fldName
);
95 printf("Data type of the field :%d\n",field
->type
);
96 printf("length of the field :%d\n",field
->length
);
97 printf("Offset :%d\n",field
->offset
);
98 printf("Default value Buffer :%s\n",field
->defaultValueBuf
);
99 printf("Null field :%d\n",field
->isNull
);
100 printf("Default value :%d\n",field
->isDefault
);
101 printf("***********************************************\n");
103 char f3var
[32]="jitu";
104 stmt
->bindField(1,&f8var
);
105 stmt
->bindField(2,&f10var
);
106 stmt
->bindField(3,&f2var
);
107 stmt
->bindField(4,&f6var
);
108 stmt
->bindField(5,f3var
);
110 rv
= con
->beginTrans();
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 \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
);
119 if(rv
!=OK
) { delete stmt
; delete con
; return 6; }
120 printf("Total row fetched=%d\n",count
);
122 strcpy(statement
,"DROP TABLE T1;");
123 rv
= stmt
->prepare(statement
);
124 if(rv
!=OK
) { delete stmt
; delete con
; return 7; }
125 rv
= stmt
->execute(rows
);
126 if(rv
!=OK
) { delete stmt
; delete con
; return 8; }
127 printf("Table dropped\n");
128 stmt
->free(); delete stmt
; delete con
;