*** empty log message ***
[csql.git] / test / adapter / Select / selecttest4.c
blob687eae29084d5111c3fb29913d94d07091961c0d
1 /* create table t1 with two fields,
2 * insert 10 rows into the table ,
3 * select with nonexisting fields.It Should be failed in Mysql, Passed in postgres and oracle
4 */
6 #include "common.h"
7 int main()
9 DbRetVal rv = OK;
10 AbsSqlConnection *con = createConnection();
11 rv = con->connect("root","manager");
12 if(rv!=OK)return 1;
14 AbsSqlStatement *stmt = createStatement();
15 stmt->setConnection(con);
16 char statement[200];
18 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT);");
19 if(strcmp(getenv("DSN"),"db2")==0)
20 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT)");
22 int rows=0;
23 rv = stmt->prepare(statement);
24 if(rv!=OK)
26 delete stmt;
27 delete con;
28 return 1;
31 rv = stmt->execute(rows);
32 if(rv!=OK)
34 delete stmt;
35 delete con;
36 return 2;
38 stmt->free();
39 printf("Table created\n");
40 con->commit();
41 // insert records
43 strcpy(statement,"INSERT INTO t1 VALUES(?,?);");
44 if(strcmp(getenv("DSN"),"db2")==0)
45 strcpy(statement,"INSERT INTO t1 VALUES(?,?)");
47 int f1var = 1;
48 int f2var= 110;
50 rv = stmt->prepare(statement);
51 if(rv!=OK)
53 delete stmt;
54 delete con;
55 return 3;
58 int count=0;
60 for(int i=0;i<2;i++)
63 for(int j=0;j<5;j++)
65 f1var = j;
66 rv = con->beginTrans();
67 if(rv!=OK)break;
70 stmt->setIntParam(1,f1var);
71 stmt->setIntParam(2,f2var);
73 rv = stmt->execute(rows);
74 if(rv!=OK)break;
75 rv = con->commit();
76 if(rv!=OK)break;
77 count++;
79 printf("%d rows inserted\n",count);
81 stmt->free();
83 //*******************************************
85 strcpy(statement,"SELECT F3 ,f2 FROM t1;");
86 if(strcmp(getenv("DSN"),"db2")==0)
87 strcpy(statement,"SELECT F3 ,f2 FROM t1");
88 rv = stmt->prepare(statement);
90 if(rv !=OK)
92 printf("Test script passed\n");
94 strcpy(statement,"DROP TABLE t1;");
95 if(strcmp(getenv("DSN"),"db2")==0)
96 strcpy(statement,"DROP TABLE t1");
97 rv = stmt->prepare(statement);
98 rv = stmt->execute(rows);
99 if(rv==OK)printf("Table dropped\n");
100 con->commit();
101 stmt->free();
102 delete stmt;
103 delete con;
104 return 0;
106 else
108 if(strcmp(getenv("DSN"),"oracle")==0 || strcmp(getenv("DSN"),"psql")==0 || strcmp(getenv("DSN"),"sybase")==0 )
110 printf("Test script Passed\n");
111 strcpy(statement,"DROP TABLE t1;");
112 if(strcmp(getenv("DSN"),"db2")==0)
113 strcpy(statement,"DROP TABLE t1");
114 rv = stmt->prepare(statement);
115 rv = stmt->execute(rows);
116 if(rv==OK){printf("Table dropped\n");}
117 stmt->free();
118 con->commit();
119 delete stmt;
120 delete con;
121 return 0;
123 else
125 printf("Test script failed\n");
126 strcpy(statement,"DROP TABLE t1;");
127 if(strcmp(getenv("DSN"),"db2")==0)
128 strcpy(statement,"DROP TABLE t1");
129 rv = stmt->prepare(statement);
130 rv = stmt->execute(rows);
131 if(rv==OK)printf("Table dropped\n");
132 con->commit();
133 stmt->free();
134 delete stmt;
135 delete con;
136 return 4;