show table through network supported
[csql.git] / test / sqlnetwork / Select / selecttest3.c
blobf2b645cbde14ceb6b4b3dfaf0536e7da34a417a2
1 /* create table T1 with two fields,
2 * insert 10 rows into the table ,
3 * select from nonexisting table.
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 CHAR(20));");
28 int rows=0;
29 rv = stmt->prepare(statement);
30 if(rv!=OK)
32 delete stmt;
33 delete con;
34 return 1;
37 rv = stmt->execute(rows);
38 if(rv!=OK)
40 delete stmt;
41 delete con;
42 return 2;
44 printf("Table created\n");
46 // insert records
48 strcpy(statement,"INSERT INTO T1 VALUES(?,?);");
50 int f1var = 1;
51 char f2var[21] = "lakshya";
54 rv = stmt->prepare(statement);
55 if(rv!=OK)
57 delete stmt;
58 delete con;
59 return 3;
62 int count=0;
64 for(int i=0;i<2;i++)
67 for(int j=0;j<5;j++)
69 f1var = j;
70 rv = con->beginTrans();
71 if(rv!=OK)break;
74 stmt->setIntParam(1,f1var);
75 stmt->setStringParam(2,f2var);
77 rv = stmt->execute(rows);
78 if(rv!=OK)break;
79 rv = con->commit();
80 if(rv!=OK)break;
81 count++;
83 printf("%d rows inserted\n",count);
86 //*******************************************
88 strcpy(statement,"SELECT * FROM T11;");
89 rv = stmt->prepare(statement);
91 if(rv !=OK)
93 printf("test script passed\n");
94 strcpy(statement,"DROP TABLE T1;");
95 rv = stmt->prepare(statement);
96 rv = stmt->execute(rows);
97 if(rv==OK){printf("Table dropped\n");}
98 delete stmt;
99 delete con;
100 return 0;
103 else if(rv==OK)
106 printf("Test script failed\n");
107 return 5;
110 else
112 stmt->bindField(1,&f1var);
113 stmt->bindField(2,f2var);
116 count = 0;
117 rv = con->beginTrans();
118 if(rv!=OK)return 6;
119 stmt->execute(rows);
120 while(stmt->fetch()!=NULL)
122 count++;
125 stmt->close();
126 rv = con->commit();
127 if(rv!=OK)
129 delete stmt;
130 delete con;
131 return 7;
134 printf("Total row fetched=%d\n",count);
138 delete stmt;
139 delete con;
140 return 0;