2 DbRetVal
createIndex(DatabaseManager
*dbMgr
, char *fldname
, char *indname
, bool flag
=false)
4 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
5 strcpy(idxInfo
->tableName
, "t1");
6 idxInfo
->list
.append(fldname
);
8 idxInfo
->indType
= treeIndex
;
10 idxInfo
->indType
= hashIndex
;
11 DbRetVal rv
= dbMgr
->createIndex(indname
, idxInfo
);
12 if (rv
!= OK
) { printf("Index creation failed\n"); return rv
; }
13 printf("Index created for %s\n", fldname
);
17 DbRetVal
createTable(DatabaseManager
*dbMgr
)
20 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
21 tabDef
.addField("f2", typeInt
, 0, NULL
, true);
22 tabDef
.addField("f3", typeInt
);
23 tabDef
.addField("f4", typeInt
);
24 tabDef
.addField("f5", typeInt
);
25 DbRetVal rv
= dbMgr
->createTable("t1", tabDef
);
26 if (rv
!= OK
) { printf("Table creation failed\n"); return rv
; }
27 printf("Table created\n");
30 int insertTuple(DatabaseManager
*dbMgr
, Connection
&conn
)
32 Table
*table
= dbMgr
->openTable("t1");
35 printf("Unable to open table\n");
39 table
->bindFld("f1", &id1
);
40 table
->bindFld("f2", &id1
);
41 table
->bindFld("f3", &id1
);
42 table
->bindFld("f4", &id1
);
43 table
->bindFld("f5", &id1
);
46 rv
= conn
.startTransaction();
47 if (rv
!= OK
) { dbMgr
->closeTable(table
); return 1; }
48 for (int i
= 0 ; i
< 10 ; i
++)
51 rv
= table
->insertTuple();
57 printf("Total Tuples inserted is %d\n", icount
);
58 dbMgr
->closeTable(table
);
61 DbRetVal
execAndPrint(Table
*table
)
65 while ((tuple
= (char*) table
->fetch())) {
66 char *t
= (char*) tuple
;
67 printf("tuple value is %d %d %d %d %d\n", *(int*)t
, *(int*)(t
+4),
68 *(int*)(t
+8),*(int*)(t
+12),*(int*)(t
+16));