1 // DBAPI Demo: delete 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 deletion\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",OpGreaterThan
, &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; }
84 conn
.startTransaction();
85 table
->setCondition(NULL
);
86 rv
= table
->execute();
89 dbMgr
->closeTable(table
);
90 dbMgr
->dropTable("EMP");
94 printf("Scan after deletion\n");
95 printf("********************\n");
96 printf("EmpId | name\t| salary\n");
97 printf("--------------------------\n");
101 tuple
= (char*)table
->fetch() ;
102 if (tuple
== NULL
) {break;}
103 printf("%d | %s\t| %6.2f\n", id1
, name
, sal
);
107 dbMgr
->closeTable(table
);
108 dbMgr
->dropTable("EMP");