modified to accept hostname and connect to the network
[csql.git] / test / dbapi / Table / bindtest3.c
blob08db4250cab500114851825c07240ca647aca2ff
1 /* create table with two fields f1(not null) and f2
2 * f1 field in not binded
3 * when fetching count variable should be zero.
5 * Author : Jitendra Lenka
6 */
8 #include<CSql.h>
9 int main()
11 Connection conn;
12 DbRetVal rv = conn.open("root","manager");
13 if(rv!=OK)return 1;
14 DatabaseManager *dbMgr = conn.getDatabaseManager();
15 if(dbMgr == NULL)
17 printf("Auth failed\n");
18 return 2;
21 TableDef tabDef;
22 tabDef.addField("f1",typeInt,0,NULL,true);
23 tabDef.addField("f2",typeInt);
25 rv = dbMgr->createTable("t1",tabDef);
26 if(rv!=OK)
28 printf("Table creation failed\n");
29 return 3;
31 printf("Table created\n");
33 Table *table = dbMgr->openTable("t1");
34 if(table == NULL)
36 printf("Unable to open table\n");
37 dbMgr->dropTable("t1");
38 conn.close();
39 return -1;
42 int id1=0;
43 table->bindFld("f2",&id1);
44 int count=0;
45 for(int i=0;i<5;i++)
47 conn.startTransaction();
48 id1=i;
49 rv = table->insertTuple();
50 if(rv!=OK)break;
51 count++;
52 conn.commit();
55 printf("Total row inserted=%d\n",count);
57 void *tuple, *fld;
58 count=0;
59 table->setCondition(NULL);
60 rv = table->execute();
61 if(rv!=OK)
63 dbMgr->closeTable(table);
64 dbMgr->dropTable("t1");
65 conn.close();
67 while(1)
69 tuple = (char*)table->fetch();
70 if(tuple == NULL){break;}
71 fld = (char*)tuple + os::align(sizeof(int));
72 printf("Tuple value is %d %d\n",*((int*)tuple),*((int*)fld));
74 table->close();
75 dbMgr->closeTable(table);
76 dbMgr->dropTable("t1");
77 conn.close();
78 return 0;