modified to accept host and connect to the network
[csql.git] / test / sqlnetwork / Select / selecttest4.c
blobfcbcb6d9ceea7f8e2d6fbdcf93c4499fcc699cbe
1 /* create table T1 with two fields,
2 * insert 10 rows into the table ,
3 * select with nonexisting fields.
5 * Author : Jitendra Lenka
6 */
7 #include<SqlNwConnection.h>
8 #include<SqlNwStatement.h>
9 #include<SqlFactory.h>
11 int main()
13 DbRetVal rv = OK;
14 AbsSqlConnection *con = new SqlNwConnection();
15 con->setInnerConnection(NULL);
16 SqlNwConnection *conn = (SqlNwConnection *)con;
17 conn->setHost("localhost", 5678);
18 rv = con->connect("root","manager");
19 if(rv!=OK)return 1;
21 AbsSqlStatement *stmt = new SqlNwStatement();
22 stmt->setInnerStatement(NULL);
23 stmt->setConnection(con);
24 char statement[200];
26 strcpy(statement,"CREATE TABLE T1(F1 INT,F2 INT);");
28 int rows=0;
29 rv = stmt->prepare(statement);
30 if(rv!=OK) { delete stmt; delete con; return 1; }
32 rv = stmt->execute(rows);
33 if(rv!=OK) { delete stmt; delete con; return 2; }
34 printf("Table created\n");
36 // insert records
38 strcpy(statement,"INSERT INTO T1 VALUES(?,?);");
40 int f1var = 1;
41 int f2var= 110;
43 rv = stmt->prepare(statement);
44 if(rv!=OK) { delete stmt; delete con; return 3; }
46 int count=0;
48 for(int i=0;i<2;i++)
51 for(int j=0;j<5;j++)
53 f1var = j;
54 rv = con->beginTrans();
55 if(rv!=OK)break;
58 stmt->setIntParam(1,f1var);
59 stmt->setIntParam(2,f2var);
61 rv = stmt->execute(rows);
62 if(rv!=OK)break;
63 rv = con->commit();
64 if(rv!=OK)break;
65 count++;
67 printf("%d rows inserted\n",count);
70 //*******************************************
72 strcpy(statement,"SELECT F3 ,F2 FROM T1;");
73 rv = stmt->prepare(statement);
74 if(rv !=OK)
76 printf("Test script passed\n");
77 strcpy(statement,"DROP TABLE T1;");
78 rv = stmt->prepare(statement);
79 if(rv!=OK)printf("Table drop prepare failed\n");
80 rv = stmt->execute(rows);
81 if(rv==OK)printf("Table dropped\n");
82 delete stmt;
83 delete con;
84 return 0;
86 else
88 printf("Test script failed\n");
89 delete stmt;
90 delete con;
91 return 4;