adding test scripts
[csql.git] / test / sql / DDL / droptest4.c
blob85732b2a0553947ea1a2b8cb115e18a2a5b36b23
1 #include <SqlFactory.h>
3 int main(int argc, char **argv)
5 DbRetVal rv = OK;
6 struct timeval timeout;
7 struct timeval timeStamp;
8 AbsSqlConnection *con = SqlFactory::createConnection(CSql);
9 rv = con->connect("root","manager");
10 if(rv!=OK)return 1;
11 AbsSqlStatement *stmt = SqlFactory::createStatement(CSql);
12 stmt->setConnection(con);
13 AbsSqlStatement *dropstmt = SqlFactory::createStatement(CSql);
14 dropstmt->setConnection(con);
15 char statement[200];
16 strcpy(statement, "CREATE TABLE t1 (f1 int, f2 int, f3 char(20), primary key (f1));");
17 int rows =0;
18 rv = stmt->prepare(statement);
19 if (rv != OK) {delete stmt; delete con; return -1; }
20 rv = stmt->execute(rows);
21 if (rv != OK) {delete stmt; delete con; return -1; }
22 stmt->free();
24 // insert into table
25 strcpy(statement,"INSERT INTO t1 VALUES(1234,5,'CSQL');");
26 rv = stmt->prepare(statement);
27 if(rv!=OK) { delete stmt; delete con; return 4; }
29 strcpy(statement, "DROP TABLE t1");
30 rv = dropstmt->prepare(statement);
31 if (rv != OK) {
32 printf("DROP table failed\n");
33 con->disconnect();delete stmt; delete con; return -1;
35 dropstmt->execute(rows);
36 dropstmt->free();
38 rv = con->beginTrans();
39 rv = stmt->execute(rows);
40 if (rv != OK) {
41 printError(rv, "Insert failed with ret val %d", rv);
42 con->rollback();
44 else con->commit();
45 stmt->free();
47 con->disconnect();
48 delete stmt;
49 delete con;