1 //Delete a tuple in a transaction and abort it
2 //scan should not display the inserted tuple.
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;}
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; }
21 char name
[196] = "ARVIND KOTHI";
22 table
->bindFld("f1", &id
);
23 table
->bindFld("f2", name
);
28 conn
.startTransaction();
29 rv
= table
->insertTuple();
32 printf("Insertion failed at %d th tuple", i
+1);
33 dbMgr
->closeTable(table
);
34 dbMgr
->dropTable("t1");
39 printf("%d tuples are inserted into the dababase\n", i
);
41 conn
.startTransaction();
44 p
.setTerm("f1", OpEquals
, &val
);
45 table
->setCondition(&p
);
50 tuple
=(char*)table
->fetch();
51 if (tuple
== NULL
) break;
52 // strcpy(name,"Kanchana");
53 rv
= table
->deleteTuple();
56 printf("Deletion failed ");
57 dbMgr
->closeTable(table
);
58 dbMgr
->dropTable("t1");
61 // printf("Updated tuple value is %d %s",id,name);
65 table
->setCondition(NULL
);
69 tuple
= (char*)table
->fetch() ;
70 if (tuple
== NULL
) {break;}
71 printf("\nBinded Tuple value is %d %s", id
, name
);
75 dbMgr
->closeTable(table
);
76 dbMgr
->dropTable("t1");