1 //Update a tuple in a transation and commit it.
2 // Next scan should display the update tuple.
10 DbRetVal rv
= conn
.open("root", "manager");
13 printf("Error during connection %d\n", rv
);
18 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
19 if (dbMgr
== NULL
) { printf("Auth failed\n"); return 2;}
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; }
32 char name
[200]="PRABA";
33 table
->bindFld("f1", &id
);
34 table
->bindFld("f2", name
);
38 conn
.startTransaction();
42 rv
=table
->insertTuple();
45 printf("Insertion failed at %d th tuple",i
);
46 dbMgr
->closeTable(table
);
47 dbMgr
->dropTable("t1");
54 conn
.startTransaction();
55 table
->setCondition(NULL
);
56 rv
= table
->execute();
59 dbMgr
->closeTable(table
);
60 dbMgr
->dropTable("t1");
64 printf("Scan before updation\n");
65 printf("********************\n");
66 void *fld2ptr
, *tuple
;
69 tuple
= (char*)table
->fetch() ;
70 if (tuple
== NULL
) {break;}
71 printf("Binded Tuple value is %d %s \n", id
, name
);
75 rv
=table
->closeScan();
76 if(rv
!=OK
){ printf("Error in closing the table\n"); return 3;}
80 p1
.setTerm("f1",OpEquals
, &val1
);
81 table
->setCondition(&p1
);
82 conn
.startTransaction();
86 dbMgr
->closeTable(table
);
87 dbMgr
->dropTable("t1");
93 //printf("Scan After:\n");
96 tuple
= (char*)table
->fetch() ;
97 if (tuple
== NULL
) { break; }
98 strcpy(name
,"Kanchana");
100 printf(" f1=%d f2=%s\n", id
, name
);
107 conn
.startTransaction();
109 table
->setCondition(NULL
);
110 rv
= table
->execute();
113 dbMgr
->closeTable(table
);
114 dbMgr
->dropTable("t1");
118 printf("Scan After updation\n");
119 printf("********************\n");
122 tuple
= (char*)table
->fetch() ;
123 if (tuple
== NULL
) {break;}
124 printf("Binded Tuple value is %d %s \n", id
, name
);
129 //unset the condtion set as we need to delete all rows
130 table
->setCondition(NULL
);
132 dbMgr
->closeTable(table
);
133 dbMgr
->dropTable("t1");
135 // printf("Test script passed ");