*** empty log message ***
[csql.git] / test / adapter / Connect / conntest10.c
blob8932da103505e3220a6284ffc43fbef305474fd0
1 // Create table t1, INSERT, UPDATE AND COMMIT.
2 // FETCH UPDATED RECORDS.
4 #include"common.h"
5 int main()
7 DbRetVal rv = OK;
8 AbsSqlConnection *con = createConnection();
9 rv = con->connect("root","manager");
10 if(rv !=OK)return 1;
11 printf("Connection opened\n");
13 AbsSqlStatement *stmt = createStatement();
14 stmt->setConnection(con);
15 char statement[200];
16 if(strcmp(getenv("DSN"),"oracle")==0)
17 strcpy(statement,"CREATE TABLE t1(f1 number(9),f2 number(9));");
18 else if(strcmp(getenv("DSN"),"psql")==0)
19 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT);");
20 else if(strcmp(getenv("DSN"),"sybase")==0)
21 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT);");
22 else if(strcmp(getenv("DSN"),"db2")==0)
23 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT)");
24 else
25 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT) engine='innodb';");
27 int rows = 0;
28 rv = stmt->prepare(statement);
29 if(rv!=OK) { delete stmt; delete con; return 2; }
31 rv = stmt->execute(rows);
32 if(rv!=OK) { delete stmt; delete con; return 3; }
33 stmt->free();
34 printf("Table t1 CREATED\n");
35 con->commit();
36 // insert into statement
37 strcpy(statement,"INSERT INTO t1 VALUES(1,1);");
38 if(strcmp(getenv("DSN"),"db2")==0){
39 strcpy(statement,"INSERT INTO t1 VALUES(1,1)");
41 rv = stmt->prepare(statement);
42 if(rv!=OK) { delete stmt; delete con; return 4; }
44 rv = con->beginTrans();
45 if(rv!=OK) { delete stmt; delete con; return 5; }
47 rv = stmt->execute(rows); if(rv!=OK) return 6;
48 stmt->free();
49 printf("One record inserted\n");
51 // update statement
53 printf("update t1 set f2=100\n");
54 strcpy(statement,"UPDATE t1 SET f2=100;");
55 if(strcmp(getenv("DSN"),"db2")==0){
56 strcpy(statement,"UPDATE t1 SET f2=100");
58 rv = stmt->prepare(statement);
59 if(rv !=OK) { delete stmt; delete con; return 7; }
61 rv = stmt->execute(rows);
62 if(strcmp(getenv("DSN"),"db2")!=0){
63 if(rv!=OK){ printf ("Hello\n"); return 8; }
65 rv = con->commit(); if(rv!=OK)return 9;
66 printf("One row updated\n");
68 strcpy(statement,"SELECT f2 FROM t1 ;");
69 if(strcmp(getenv("DSN"),"db2")==0){
70 strcpy(statement,"SELECT f2 FROM t1");
72 rv = stmt->prepare(statement);
73 if(rv!=OK) { delete stmt; delete con; return 10; }
75 int id=10;
76 stmt->bindField(1,&id);
77 rv = con->beginTrans();
78 if(rv!=OK)return 11;
79 stmt->execute(rows);
80 int count=0;
81 while(stmt->fetch()!=NULL)
83 printf("f2= %d\n",id);
84 count++;
86 stmt->close();
87 rv = con->commit();
88 if(rv!=OK)return 12;
89 printf("Total reccord fetchec=%d\n",count);
90 stmt->free();
91 strcpy(statement,"DROP TABLE t1;");
92 if(strcmp(getenv("DSN"),"db2")==0){
93 strcpy(statement,"DROP TABLE t1;");
95 rv = stmt->prepare(statement);
96 if(rv!=OK) { delete stmt; delete con; return 13; }
97 rv = stmt->execute(rows);
98 if(rv!=OK) { delete stmt; delete con; return 14; }
99 con->commit();
100 printf("TABLE t1 DROPPED SUCCESSFULLY\n");
101 stmt->free();
102 delete stmt;
103 delete con;
104 printf("Connection closed successfully\n");
105 return 0;