fixing timing issue in test script
[csql.git] / test / dbapi / Connection / conntest12.c
blob24858d43dade6b988df01715a344ae60a7f5d7a2
1 //Update a tuple in a transation and commit it.
2 // Next scan should display the update tuple.
4 #include<CSql.h>
5 #include<NanoTimer.h>
6 int main()
9 Connection conn;
10 DbRetVal rv = conn.open("root", "manager");
11 if (rv != OK)
13 printf("Error during connection %d\n", rv);
14 return 1;
18 DatabaseManager *dbMgr = conn.getDatabaseManager();
19 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
22 TableDef tabDef;
23 tabDef.addField("f1", typeInt);
24 tabDef.addField("f2", typeString, 196);
25 rv = dbMgr->createTable("t1", tabDef);
26 if (rv != OK) { printf("Table creation failed\n"); return 3; }
27 printf("Table created\n");
29 Table *table = dbMgr->openTable("t1");
30 if (table == NULL) { printf("Unable to open table\n"); return 3; }
31 int id;
32 char name[200]="PRABA";
33 table->bindFld("f1", &id);
34 table->bindFld("f2", name);
35 int icount = 0;
36 int i;
38 conn.startTransaction();
39 for (i=0;i<10;i++)
41 id=i;
42 rv=table->insertTuple();
43 if(rv!=OK)
45 printf("Insertion failed at %d th tuple",i);
46 dbMgr->closeTable(table);
47 dbMgr->dropTable("t1");
48 conn.close();
49 return 4;
52 conn.commit();
54 conn.startTransaction();
55 table->setCondition(NULL);
56 rv = table->execute();
57 if (rv != OK)
59 dbMgr->closeTable(table);
60 dbMgr->dropTable("t1");
61 conn.close();
62 return 6;
64 printf("Scan before Deletion\n");
65 printf("********************\n");
66 void *fld2ptr, *tuple;
67 while(true)
69 tuple = (char*)table->fetch() ;
70 if (tuple == NULL) {break;}
71 printf("Binded Tuple value is %d %s \n", id, name);
74 conn.commit();
75 rv=table->closeScan();
76 if(rv!=OK){ printf("Error in closing the table\n"); return 3;}
78 Condition p1;
79 int val1 = 5;
80 p1.setTerm("f1",OpEquals, &val1);
81 table->setCondition(&p1);
82 conn.startTransaction();
83 rv=table->execute();
84 if (rv != OK)
86 dbMgr->closeTable(table);
87 dbMgr->dropTable("t1");
88 conn.close();
89 return 4;
92 // char *tuple;
93 //printf("Scan After:\n");
94 while(true)
96 tuple = (char*)table->fetch() ;
97 if (tuple == NULL) { break; }
98 //strcpy(name,"Kanchana");
99 table->deleteTuple();
101 conn.commit();
102 table->closeScan();
105 conn.startTransaction();
107 table->setCondition(NULL);
108 rv = table->execute();
109 if (rv != OK)
111 dbMgr->closeTable(table);
112 dbMgr->dropTable("t1");
113 conn.close();
114 return 6;
116 printf("Scan After Deletion\n");
117 printf("********************\n");
118 while(true)
120 tuple = (char*)table->fetch() ;
121 if (tuple == NULL) {break;}
122 printf("Binded Tuple value is %d %s \n", id, name);
125 conn.commit();
127 //unset the condtion set as we need to delete all rows
128 table->setCondition(NULL);
129 table->closeScan();
130 dbMgr->closeTable(table);
131 dbMgr->dropTable("t1");
132 conn.close();
133 printf("Test script passed ");
134 return 0;