code reorg for Transactionw!
[csql.git] / test / dbapi / Table / bindtest3.c
blob26c54491695b0bea0d96ba23821390f020b46bda
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) { conn.rollback(); 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 conn.startTransaction();
61 rv = table->execute();
62 if(rv!=OK)
64 dbMgr->closeTable(table);
65 dbMgr->dropTable("t1");
66 conn.close();
68 while(1)
70 tuple = (char*)table->fetch();
71 if(tuple == NULL){break;}
72 fld = (char*)tuple + os::align(sizeof(int));
73 printf("Tuple value is %d %d\n",*((int*)tuple),*((int*)fld));
75 table->closeScan();
76 conn.commit();
77 dbMgr->closeTable(table);
78 dbMgr->dropTable("t1");
79 conn.close();
80 return 0;