*** empty log message ***
[csql.git] / test / sqlapi / Csql / DDLStmt / treeindexonalldatatype.c
blobe1a4867481a98e0327d9ef7f4a5411d9c4b9fd18
1 /*
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
18 #include"common.h"
20 int main()
22 DbRetVal rv = OK;
23 AbsSqlConnection *con = createConnection();
24 rv = con->connect("root","manager");
25 if(rv !=OK) {
26 delete con;
27 return 1;
29 printf("Connection opened\n");
30 AbsSqlStatement *stmt = createStatement();
31 stmt->setConnection(con);
32 //Creating Table
33 char statement[400];
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);");
35 int rows=0;
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");
41 stmt->free();
43 strcpy(statement,"CREATE INDEX idxtiny ON t1(f1) TREE;");
44 rows=0;
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");
50 stmt->free();
52 strcpy(statement,"CREATE INDEX idxsmall ON t1(f2) TREE;");
53 rows=0;
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");
59 stmt->free();
61 strcpy(statement,"CREATE INDEX idxint ON t1(f3) TREE;");
62 rows=0;
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");
68 stmt->free();
70 strcpy(statement,"CREATE INDEX idxbig ON t1(f4) TREE;");
71 rows=0;
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");
77 stmt->free();
79 strcpy(statement,"CREATE INDEX idxchar ON t1(f5) TREE;");
80 rows=0;
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");
86 stmt->free();
88 strcpy(statement,"CREATE INDEX idxvarchar ON t1(f6) TREE;");
89 rows=0;
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");
95 stmt->free();
97 strcpy(statement,"CREATE INDEX idxfloat ON t1(f7) TREE;");
98 rows=0;
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");
104 stmt->free();
106 strcpy(statement,"CREATE INDEX idxdouble ON t1(f8) TREE;");
107 rows=0;
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");
113 stmt->free();
115 strcpy(statement,"CREATE INDEX idxdate ON t1(f9) TREE;");
116 rows=0;
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");
122 stmt->free();
124 strcpy(statement,"CREATE INDEX idxtime ON t1(f10) TREE;");
125 rows=0;
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");
131 stmt->free();
133 strcpy(statement,"CREATE INDEX idxtimestamp ON t1(f11) TREE;");
134 rows=0;
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");
140 stmt->free();
142 // Show all tables
143 strcpy(statement,"GETALLTABLES;");
144 rows=0;
145 rv = stmt->prepare(statement);
146 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 26; }
147 stmt->execute(rows);
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)
154 stmt->free();
156 con->disconnect();
157 printf("Connection Closed\n");
159 delete stmt; delete con;
160 return 0;