adding test scripts
[csql.git] / test / sqlapi / Csql / DDLStmt / autoincreonalldatatype.c
blob5b6aff07f3a5ffa104bb3364463bbff6dd9077f0
1 /*
2 Autoincrement key should not be allowed for the datatypes other than all int types.
3 */
5 #include"common.h"
7 int main()
9 DbRetVal rv = OK;
10 AbsSqlConnection *con = createConnection();
11 rv = con->connect("root","manager");
12 if(rv !=OK) {
13 delete con;
14 return 1;
16 printf("Connection opened\n");
17 AbsSqlStatement *stmt = createStatement();
18 stmt->setConnection(con);
19 //Creating Table
20 char statement[400];
21 strcpy(statement,"CREATE TABLE AUTOINCTINY(f1 TINYINT AUTO_INCREMENT,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
22 int rows=0;
23 rv = stmt->prepare(statement);
24 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 2; }
25 rv = stmt->execute(rows);
26 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 3; }
27 stmt->free();
29 strcpy(statement,"CREATE TABLE AUTOINCSMALL(f1 TINYINT ,f2 SMALLINT AUTO_INCREMENT,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
30 rows=0;
31 rv = stmt->prepare(statement);
32 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 3; }
33 rv = stmt->execute(rows);
34 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 4; }
35 stmt->free();
37 strcpy(statement,"CREATE TABLE AUTOINCINT(f1 TINYINT ,f2 SMALLINT ,f3 INT AUTO_INCREMENT,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
38 rows=0;
39 rv = stmt->prepare(statement);
40 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 5; }
41 rv = stmt->execute(rows);
42 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 6; }
43 stmt->free();
45 strcpy(statement,"CREATE TABLE AUTOINCBIG(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT AUTO_INCREMENT,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
46 rows=0;
47 rv = stmt->prepare(statement);
48 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 7; }
49 rv = stmt->execute(rows);
50 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 8; }
51 stmt->free();
53 strcpy(statement,"CREATE TABLE AUTOINCCHAR(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) AUTO_INCREMENT,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
54 rows=0;
55 rv = stmt->prepare(statement);
56 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 9; }
57 printf("Auto_increment can not be applied on char datatype\n");
58 stmt->free();
60 strcpy(statement,"CREATE TABLE AUTOINCVARCHAR(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) AUTO_INCREMENT,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
61 rows=0;
62 rv = stmt->prepare(statement);
63 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 11; }
64 printf("Auto_increment can not be applied on varchar datatype\n");
65 stmt->free();
67 strcpy(statement,"CREATE TABLE AUTOINCFLOAT(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT AUTO_INCREMENT,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
68 rows=0;
69 rv = stmt->prepare(statement);
70 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 13; }
71 printf("Auto_increment can not be applied on float datatype\n");
72 stmt->free();
74 strcpy(statement,"CREATE TABLE AUTOINCDOUBLE(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE AUTO_INCREMENT,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
75 rows=0;
76 rv = stmt->prepare(statement);
77 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 15; }
78 printf("Auto_increment can not be applied on double datatype\n");
79 stmt->free();
81 strcpy(statement,"CREATE TABLE AUTOINCDATE(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE AUTO_INCREMENT,f10 TIME ,f11 TIMESTAMP);");
82 rows=0;
83 rv = stmt->prepare(statement);
84 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 17; }
85 printf("Auto_increment can not be applied on date datatype\n");
86 stmt->free();
88 strcpy(statement,"CREATE TABLE AUTOINCTIME(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME AUTO_INCREMENT,f11 TIMESTAMP);");
89 rows=0;
90 rv = stmt->prepare(statement);
91 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 19; }
92 printf("Auto_increment can not be applied on time datatype\n");
93 stmt->free();
95 strcpy(statement,"CREATE TABLE AUTOINCTIMESTAMP(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP AUTO_INCREMENT);");
96 rows=0;
97 rv = stmt->prepare(statement);
98 if(rv==OK) { delete stmt; con->disconnect(); delete con; return 21; }
99 printf("Auto_increment can not be applied on timestamp datatype\n");
100 stmt->free();
102 // Show all tables
103 strcpy(statement,"GETALLTABLES;");
104 rows=0;
105 rv = stmt->prepare(statement);
106 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 23; }
107 stmt->execute(rows);
108 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 24; }
109 printf("\t TABLES\n");
110 printf("\t--------\n");
111 while(stmt->next() !=NULL) {
112 printf("\t%s\n",stmt->getFieldValuePtr(2)); //stmt->getFieldValuePtr(2) returns the TABLE_NAME (src/sql/SqlStatement.cxx)
114 stmt->free();
116 //Droping tables
117 rv = stmt->prepare("DROP TABLE AUTOINCTINY;");
118 rv = stmt->execute(rows);
119 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 25; }
120 printf("AUTOINCTINY Table Dropped\n");
121 stmt->free();
122 rv = stmt->prepare("DROP TABLE AUTOINCSMALL;");
123 rv = stmt->execute(rows);
124 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 26; }
125 printf("AUTOINCSMALL Table Dropped\n");
126 stmt->free();
127 rv = stmt->prepare("DROP TABLE AUTOINCINT;");
128 rv = stmt->execute(rows);
129 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 27; }
130 printf("AUTOINCINT Table Dropped\n");
131 stmt->free();
132 rv = stmt->prepare("DROP TABLE AUTOINCBIG;");
133 rv = stmt->execute(rows);
134 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 28; }
135 printf("AUTOINCBIG Table Dropped\n");
136 stmt->free();
137 /* rv = stmt->prepare("DROP TABLE AUTOINCCHAR;");
138 rv = stmt->execute(rows);
139 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 53; }
140 printf("AUTOINCCHAR Table Dropped\n");
141 stmt->free();
142 rv = stmt->prepare("DROP TABLE AUTOINCVARCHAR;");
143 rv = stmt->execute(rows);
144 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 55; }
145 printf("AUTOINCVARCHAR Table Dropped\n");
146 stmt->free();
147 rv = stmt->prepare("DROP TABLE AUTOINCDATE;");
148 rv = stmt->execute(rows);
149 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 57; }
150 printf("AUTOINCDATE Table Dropped\n");
151 stmt->free();
152 rv = stmt->prepare("DROP TABLE AUTOINCTIME;");
153 rv = stmt->execute(rows);
154 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 59; }
155 printf("AUTOINCTIME Table Dropped\n");
156 stmt->free();*/
158 // Show all tables
159 strcpy(statement,"GETALLTABLES;");
160 rows=0;
161 rv = stmt->prepare(statement);
162 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 29; }
163 stmt->execute(rows);
164 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 30; }
165 while(stmt->next() !=NULL) {
166 printf("Table Name is %s\n",stmt->getFieldValuePtr(2)); //stmt->getFieldValuePtr(2) returns the TABLE_NAME (src/sql/SqlStatement.cxx)
169 stmt->free();
170 con->disconnect();
171 printf("Connection Closed\n");
173 delete stmt; delete con;
174 return 0;