*** empty log message ***
[csql.git] / test / sqlgw / Select / selecttest4.c
blobfd1b8155ac2d321e8f7d4bfe16ad21372469f897
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];
17 int rows = 0;
18 // insert records
20 strcpy(statement,"INSERT INTO t1 VALUES(?,?);");
21 if(strcmp(getenv("DSN"),"db2")==0)
22 strcpy(statement,"INSERT INTO t1 VALUES(?,?)");
24 int f1var = 1;
25 int f2var= 110;
27 rv = stmt->prepare(statement);
28 if(rv!=OK) { delete stmt; delete con; return 3; }
30 int count=0;
32 for( int i = 0; i < 2; i++ ) {
33 for( int j = 0; j < 5; j++ ) {
34 f1var = j;
35 rv = con->beginTrans();
36 if(rv != OK) break;
37 stmt->setIntParam(1,f1var);
38 stmt->setIntParam(2,f2var);
39 rv = stmt->execute(rows);
40 if(rv!=OK)break;
41 rv = con->commit();
42 if(rv!=OK)break;
43 count++;
45 printf("%d rows inserted\n",count);
47 stmt->free();
49 //*******************************************
50 strcpy(statement,"SELECT F3 ,f2 FROM t1;");
51 if(strcmp(getenv("DSN"),"db2")==0)
52 strcpy(statement,"SELECT F3 ,f2 FROM t1");
53 rv = stmt->prepare(statement);
54 if(rv !=OK) {
55 printf("Test script passed\n");
56 delete stmt; delete con; return 0;
57 } else {
58 if(strcmp(getenv("DSN"),"oracle")==0 || strcmp(getenv("DSN"),"psql")==0 || strcmp(getenv("DSN"),"sybase")==0)
60 printf("Test script Passed\n");
61 delete stmt; delete con; return 0;
62 } else {
63 printf("Test script failed\n");
64 delete stmt; delete con; return 4; }