2 Create Tree indexes on the fields which are (TINYINT,SMALLINT,INT,BIGINT,CHAR,VARCHAR,DATE,TIME).
3 CREATE TABLE t1(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);
4 CREATE INDEX idxtiny ON t1(f1) TREE;
5 CREATE INDEX idxsmall ON t1(f2) TREE;
6 CREATE INDEX idxint ON t1(f3) TREE;
7 CREATE INDEX idxbig ON t1(f4) TREE;
8 CREATE INDEX idxchar ON t1(f5) TREE;
9 CREATE INDEX idxvarchar ON t(f6) TREE;
10 CREATE INDEX idxfloat ON t1(f7) TREE;
11 CREATE INDEX idxdouble ON t1(f8) TREE;
12 CREATE INDEX idxdate ON t(f9) TREE;
13 CREATE INDEX idxtime ON t1(f10) TREE;
14 CREATE INDEX idxtimestamp ON t1(f11) TREE;
15 All the indexes needs to be created
23 AbsSqlConnection
*con
= createConnection();
24 rv
= con
->connect("root","manager");
29 printf("Connection opened\n");
30 AbsSqlStatement
*stmt
= createStatement();
31 stmt
->setConnection(con
);
34 strcpy(statement
,"CREATE TABLE t1(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
36 rv
= stmt
->prepare(statement
);
37 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 2; }
38 rv
= stmt
->execute(rows
);
39 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 3; }
40 printf("Table t1 Created\n");
43 strcpy(statement
,"CREATE INDEX idxtiny ON t1(f1) TREE;");
45 rv
= stmt
->prepare(statement
);
46 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 4; }
47 rv
= stmt
->execute(rows
);
48 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 5; }
49 printf("Tree Index Created on TINYINT field f1\n");
52 strcpy(statement
,"CREATE INDEX idxsmall ON t1(f2) TREE;");
54 rv
= stmt
->prepare(statement
);
55 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 6; }
56 rv
= stmt
->execute(rows
);
57 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 7; }
58 printf("Tree Index Created on SMALLINT field f2\n");
61 strcpy(statement
,"CREATE INDEX idxint ON t1(f3) TREE;");
63 rv
= stmt
->prepare(statement
);
64 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 8; }
65 rv
= stmt
->execute(rows
);
66 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 9; }
67 printf("Tree Index Created on INT field f3\n");
70 strcpy(statement
,"CREATE INDEX idxbig ON t1(f4) TREE;");
72 rv
= stmt
->prepare(statement
);
73 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 10; }
74 rv
= stmt
->execute(rows
);
75 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 11; }
76 printf("Tree Index Created on BIGINT field f4\n");
79 strcpy(statement
,"CREATE INDEX idxchar ON t1(f5) TREE;");
81 rv
= stmt
->prepare(statement
);
82 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 12; }
83 rv
= stmt
->execute(rows
);
84 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 13; }
85 printf("Tree Index Created on CHAR field f5\n");
88 strcpy(statement
,"CREATE INDEX idxvarchar ON t1(f6) TREE;");
90 rv
= stmt
->prepare(statement
);
91 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 14; }
92 rv
= stmt
->execute(rows
);
93 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 15; }
94 printf("Tree Index Created on VARCHAR field f6\n");
97 strcpy(statement
,"CREATE INDEX idxfloat ON t1(f7) TREE;");
99 rv
= stmt
->prepare(statement
);
100 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 16; }
101 rv
= stmt
->execute(rows
);
102 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 17; }
103 printf("Tree Index Created on FLOAT field f7\n");
106 strcpy(statement
,"CREATE INDEX idxdouble ON t1(f8) TREE;");
108 rv
= stmt
->prepare(statement
);
109 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 18; }
110 rv
= stmt
->execute(rows
);
111 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 19; }
112 printf("Tree Index Created on DOUBLE field f8\n");
115 strcpy(statement
,"CREATE INDEX idxdate ON t1(f9) TREE;");
117 rv
= stmt
->prepare(statement
);
118 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 20; }
119 rv
= stmt
->execute(rows
);
120 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 21; }
121 printf("Tree Index Created on DATE field f9\n");
124 strcpy(statement
,"CREATE INDEX idxtime ON t1(f10) TREE;");
126 rv
= stmt
->prepare(statement
);
127 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 22; }
128 rv
= stmt
->execute(rows
);
129 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 23; }
130 printf("Tree Index Created on TIME field f10\n");
133 strcpy(statement
,"CREATE INDEX idxtimestamp ON t1(f11) TREE;");
135 rv
= stmt
->prepare(statement
);
136 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 24; }
137 rv
= stmt
->execute(rows
);
138 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 25; }
139 printf("Tree Index Created on TIMESTAMP field f11\n");
143 strcpy(statement
,"GETALLTABLES;");
145 rv
= stmt
->prepare(statement
);
146 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 26; }
148 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 27; }
149 printf("\t TABLES\n");
150 printf("\t--------\n");
151 while(stmt
->next() !=NULL
) {
152 printf("\t%s\n",stmt
->getFieldValuePtr(2)); //stmt->getFieldValuePtr(2) returns the TABLE_NAME (src/sql/SqlStatement.cxx)
157 printf("Connection Closed\n");
159 delete stmt
; delete con
;