2 DbRetVal
createIndex(DatabaseManager
*dbMgr
, char *fldname
, char *indname
)
4 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
5 strcpy(idxInfo
->tableName
, "t1");
6 idxInfo
->list
.append(fldname
);
7 idxInfo
->indType
= hashIndex
;
8 idxInfo
->isUnique
= true;
9 idxInfo
->isPrimary
= 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
)
19 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
20 tabDef
.addField("f2", typeInt
, 0, NULL
, true);
21 tabDef
.addField("f3", typeInt
);
22 tabDef
.addField("f4", typeInt
);
23 tabDef
.addField("f5", typeInt
);
24 DbRetVal rv
= dbMgr
->createTable("t1", tabDef
);
25 if (rv
!= OK
) { printf("Table creation failed\n"); return rv
; }
26 printf("Table created\n");
29 int insertTuple(DatabaseManager
*dbMgr
, Connection
&conn
)
31 Table
*table
= dbMgr
->openTable("t1");
34 printf("Unable to open table\n");
38 table
->bindFld("f1", &id1
);
39 table
->bindFld("f2", &id1
);
40 table
->bindFld("f3", &id1
);
41 table
->bindFld("f4", &id1
);
42 table
->bindFld("f5", &id1
);
45 rv
= conn
.startTransaction();
46 if (rv
!= OK
) { dbMgr
->closeTable(table
); return 1; }
47 for (int i
= 0 ; i
< 10 ; i
++)
50 rv
= table
->insertTuple();
56 printf("Total Tuples inserted is %d\n", icount
);
57 dbMgr
->closeTable(table
);
60 DbRetVal
execAndPrint(Table
*table
)
64 while ((tuple
= (char*) table
->fetch())) {
65 char *t
= (char*) tuple
;
66 printf("tuple value is %d %d %d %d %d\n", *(int*)t
, *(int*)(t
+4),
67 *(int*)(t
+8),*(int*)(t
+12),*(int*)(t
+16));