1 // DBAPI Demo: update and read
6 // Connect to the database
8 DbRetVal rv
= conn
.open("root", "manager");
9 if (rv
!= OK
) return 1;
11 // get database manager
12 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
13 if (dbMgr
== NULL
) { printf("Auth failed\n"); return 2;}
16 Table
*table
= dbMgr
->openTable("EMP");
19 printf("Unable to open table\n");
20 dbMgr
->dropTable("EMP");
25 // allocate fields to bind
31 // bind the allocated fields
32 table
->bindFld("empId", &id1
);
33 table
->bindFld("name", name
);
34 table
->bindFld("salary", &sal
);
36 conn
.startTransaction();
37 table
->setCondition(NULL
);
38 rv
= table
->execute();
41 dbMgr
->closeTable(table
);
42 dbMgr
->dropTable("EMP");
46 printf("Scan before updation\n");
47 printf("********************\n");
48 printf("EmpId | name\t| salary\n");
49 printf("--------------------------\n");
51 void *fld2ptr
, *tuple
;
54 tuple
= (char*)table
->fetch() ;
55 if (tuple
== NULL
) {break;}
56 printf("%d | %s\t| %6.2f\n", id1
, name
, sal
);
63 p1
.setTerm("empId",OpLessThan
, &val1
);
64 table
->setCondition(&p1
);
65 conn
.startTransaction();
69 dbMgr
->closeTable(table
);
70 dbMgr
->dropTable("EMP");
77 tuple
= (char*)table
->fetch() ;
78 if (tuple
== NULL
) { break; }
80 strcpy(name
,"Shubha");
84 else if (id1
== 1003) {
85 strcpy(name
,"Champak");
89 else if (id1
== 1005) {
90 strcpy(name
,"Poonam");
98 conn
.startTransaction();
99 table
->setCondition(NULL
);
100 rv
= table
->execute();
103 dbMgr
->closeTable(table
);
104 dbMgr
->dropTable("EMP");
108 printf("Scan after updation\n");
109 printf("********************\n");
110 printf("EmpId | name\t| salary\n");
111 printf("--------------------------\n");
115 tuple
= (char*)table
->fetch() ;
116 if (tuple
== NULL
) {break;}
117 printf("%d | %s\t| %6.2f\n", id1
, name
, sal
);
121 dbMgr
->closeTable(table
);