string suport <= and >=
[csql.git] / test / dbapi / Connection / conntest16.c
blob744f46e13f52040736a1a6c0b01799837c467d43
1 //Delete a tuple in a transaction and abort it
2 //scan should not display the inserted tuple.
4 #include<CSql.h>
5 int main()
7 Connection conn;
8 DbRetVal rv = conn.open("root", "manager");
9 if (rv != OK) { printf("Unable to open database\n"); return 1;}
10 DatabaseManager *dbMgr = conn.getDatabaseManager();
11 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
12 TableDef tabDef;
13 tabDef.addField("f1", typeInt);
14 tabDef.addField("f2", typeString, 196);
15 rv = dbMgr->createTable("t1", tabDef);
16 if (rv != OK) { printf("Table creation failed\n"); return 3; }
17 printf("Table created\n");
18 Table *table = dbMgr->openTable("t1");
19 if (table == NULL) { printf("Unable to open table\n"); return 4; }
20 int id = 0;
21 char name[196] = "ARVIND KOTHI";
22 table->bindFld("f1", &id);
23 table->bindFld("f2", name);
24 int i;
25 for (i=0; i<10; i++)
27 id=i;
28 conn.startTransaction();
29 rv = table->insertTuple();
30 if (rv != OK)
32 printf("Insertion failed at %d th tuple", i+1);
33 dbMgr->closeTable(table);
34 dbMgr->dropTable("t1");
35 return 5;
37 conn.commit();
39 printf("%d tuples are inserted into the dababase\n", i);
41 conn.startTransaction();
42 Condition p;
43 int val = 3;
44 p.setTerm("f1", OpEquals, &val);
45 table->setCondition(&p);
46 table->execute();
47 void *tuple;
48 while(true)
50 tuple=(char*)table->fetch();
51 if (tuple == NULL) break;
52 // strcpy(name,"Kanchana");
53 rv = table->deleteTuple();
54 if (rv != OK)
56 printf("Deletion failed ");
57 dbMgr->closeTable(table);
58 dbMgr->dropTable("t1");
59 return 6;
61 // printf("Updated tuple value is %d %s",id,name);
63 table->closeScan();
64 conn.rollback();
65 table->setCondition(NULL);
66 table->execute();
67 while(true)
69 tuple = (char*)table->fetch() ;
70 if (tuple == NULL) {break;}
71 printf("\nBinded Tuple value is %d %s", id, name);
74 table->closeScan();
75 dbMgr->closeTable(table);
76 dbMgr->dropTable("t1");
77 conn.close();
78 return 0;