*** empty log message ***
[csql.git] / test / adapter / Connect / conntest12.c
blob15527f63eb60589503dc2bcc9ca8079a69008e04
1 //Test for primary key in TDB
2 //
4 #include"common.h"
5 #include <SqlOdbcStatement.h>
6 int main()
8 DbRetVal rv = OK;
9 AbsSqlConnection *con = createConnection();
10 rv = con->connect("root","manager");
11 if(rv !=OK)return 1;
12 printf("Connection opened\n");
14 AbsSqlStatement *stmt = createStatement();
15 stmt->setConnection(con);
16 char statement[200];
17 if(strcmp(getenv("DSN"),"oracle")==0)
18 strcpy(statement,"CREATE TABLE t1(f1 number(9),f2 number(9),primary key(f1));");
19 else if(strcmp(getenv("DSN"),"db2")==0)
20 strcpy(statement,"CREATE TABLE t1(f1 INT NOT NULL,f2 INT,primary key(f1))");
21 else
22 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT,primary key(f1));");
24 int rows = 0;
25 rv = stmt->prepare(statement);
26 if(rv!=OK) { delete stmt; delete con; return 2; }
28 rv = stmt->execute(rows);
29 if(rv!=OK) { delete stmt; delete con; return 3; }
30 stmt->free();
31 printf("Table t1 CREATED\n");
32 con->commit();
33 // insert into statement
34 printf("Primary Key Testing Starts Here\n");
35 char pkfield[200];
36 SqlOdbcStatement *oStmt= (SqlOdbcStatement *)stmt;
37 oStmt->getPrimaryKeyFieldName("t1",pkfield);
38 printf("Primary key in table %s is %s \n","t1",pkfield);
40 strcpy(statement,"DROP TABLE t1;");
41 if(strcmp(getenv("DSN"),"db2")==0){
42 strcpy(statement,"DROP TABLE t1");
44 rv = stmt->prepare(statement);
45 if(rv!=OK)
47 delete stmt;
48 delete con;
49 return 4;
51 rv = stmt->execute(rows);
52 if(rv!=OK)
54 delete stmt;
55 delete con;
56 return 5;
58 con->commit();
59 printf("Table droped\n");
61 delete stmt;
62 delete con;
63 return 0;