2 DbRetVal
createIndex(DatabaseManager
*dbMgr
, char *tblname
, char *fldname
, char *indname
)
4 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
5 strcpy(idxInfo
->tableName
, tblname
);
6 idxInfo
->list
.append(fldname
);
7 idxInfo
->indType
= hashIndex
;
8 idxInfo
->isPrimary
= true;
9 idxInfo
->isUnique
= true;
10 DbRetVal rv
= dbMgr
->createIndex(indname
, idxInfo
);
11 if (rv
!= OK
) { printf("Index creation failed\n"); return rv
; }
12 printf("Index created for %s\n", fldname
);
16 DbRetVal
createTable(DatabaseManager
*dbMgr
, char *tblname
)
19 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
20 tabDef
.addField("f2", typeInt
);
21 DbRetVal rv
= dbMgr
->createTable(tblname
, tabDef
);
22 if (rv
!= OK
) { printf("Table creation failed\n"); return rv
; }
23 printf("Table created\n");
26 DbRetVal
dropTable(DatabaseManager
*dbMgr
, char *tblname
)
28 DbRetVal rv
= dbMgr
->dropTable(tblname
);
29 if (rv
!= OK
) { printf("Table drop failed\n"); return rv
; }
30 printf("Table Dropped\n");
33 int insertTuple(DatabaseManager
*dbMgr
, Connection
&conn
, char *tblname
, int count
)
35 Table
*table
= dbMgr
->openTable(tblname
);
38 printf("Unable to open table\n");
42 table
->bindFld("f1", &id1
);
43 table
->bindFld("f2", &id1
);
46 for (int i
= 0 ; i
< count
; i
++)
49 rv
= table
->insertTuple();
54 printf("Total Tuples inserted is %d\n", icount
);
55 dbMgr
->closeTable(table
);
59 int selectTuple(DatabaseManager
*dbMgr
, Connection
&conn
, char *tblname
, int count
)
61 Table
*table
= dbMgr
->openTable(tblname
);
64 printf("Unable to open table\n");
71 p1
.setTerm("f1", OpEquals
, &val1
);
72 table
->setCondition(&p1
);
75 for (i
= 0 ; i
< count
; i
++)
80 tuple
= (char*)table
->fetch() ;
81 if (tuple
== NULL
) break;
84 printf("Total Tuples selected is %d\n", i
);
85 dbMgr
->closeTable(table
);
88 int updateTuple(DatabaseManager
*dbMgr
, Connection
&conn
, char *tblname
, int count
)
90 Table
*table
= dbMgr
->openTable(tblname
);
93 printf("Unable to open table\n");
99 table
->bindFld("f1", &id1
);
100 table
->bindFld("f2", &id2
);
103 p1
.setTerm("f1", OpEquals
, &val1
);
104 table
->setCondition(&p1
);
107 for (i
= 0 ; i
< count
; i
++)
112 tuple
= (char*)table
->fetch() ;
113 if (tuple
== NULL
) break;
115 rv
= table
->updateTuple();
119 printf("Total Tuples updated is %d\n", i
);
120 dbMgr
->closeTable(table
);
123 int deleteTuple(DatabaseManager
*dbMgr
, Connection
&conn
, char *tblname
, int count
)
125 Table
*table
= dbMgr
->openTable(tblname
);
128 printf("Unable to open table\n");
135 p1
.setTerm("f1", OpEquals
, &val1
);
136 table
->setCondition(&p1
);
139 for (i
= 0 ; i
< count
; i
++)
144 tuple
= (char*)table
->fetch() ;
145 if (tuple
== NULL
) break;
146 rv
= table
->deleteTuple();
150 printf("Total Tuples deleted is %d\n", i
);
151 dbMgr
->closeTable(table
);