*** empty log message ***
[csql.git] / test / sqlapi / Csql / DDLStmt / createtablewithalldatatype.c
blob2ec8b85288bb72f6590407466a6196be593d924e
1 /*
2 Creating table using all Datatypes.
3 Create table t1 with all datatypes(TINYINT,SMALLINT,INT,BIGINT,CHAR,VARCHAR,FLOAT,DOUBLE,DATE,TIME,TIMESTAMP).
4 It should pass.
5 */
7 #include"common.h"
9 int main()
11 DbRetVal rv = OK;
12 AbsSqlConnection *con = createConnection();
13 rv = con->connect("root","manager");
14 if(rv !=OK) {
15 delete con;
16 return 1;
18 printf("Connection opened\n");
19 AbsSqlStatement *stmt = createStatement();
20 stmt->setConnection(con);
21 //Creating Table
22 char statement[400];
23 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);");
24 int rows=0;
25 rv = stmt->prepare(statement);
26 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 2; }
27 rv = stmt->execute(rows);
28 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 3; }
29 stmt->free();
30 // Show all tables
31 strcpy(statement,"GETALLTABLES;");
32 rows=0;
33 rv = stmt->prepare(statement);
34 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 4; }
35 stmt->execute(rows);
36 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 5; }
37 while(stmt->next() !=NULL) {
38 printf("Table Name is %s\n",stmt->getFieldValuePtr(2)); //stmt->getFieldValuePtr(2) returns the TABLE_NAME (src/sql/SqlStatement.cxx)
40 stmt->free();
41 //Dropping table
42 strcpy(statement,"DROP TABLE t1;");
43 rv = stmt->prepare(statement);
44 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 6; }
45 rv = stmt->execute(rows);
46 if(rv!=OK) { delete stmt; con->disconnect(); delete con; return 7; }
47 printf("Table dropped\n");
48 stmt->free();
49 con->disconnect();
50 printf("Connection Closed\n");
51 delete stmt; delete con;
52 return 0;