2 int createIndex(DatabaseManager
*dbMgr
, bool unique
)
4 //Creating hash index on field f1 of table t1
5 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
6 strcpy(idxInfo
->tableName
, "t1");
7 idxInfo
->list
.append("f1");
9 idxInfo
->indType
= treeIndex
;
11 idxInfo
->indType
= trieIndex
;
13 idxInfo
->indType
= hashIndex
;
16 idxInfo
->isUnique
= unique
;
18 DbRetVal rv
= dbMgr
->createIndex("indx1", idxInfo
);
19 if (rv
!= OK
) { printf("Index creation failed\n"); return 1; }
20 printf("Index created\n");
24 int createTable(DatabaseManager
*dbMgr
)
27 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
28 tabDef
.addField("f2", typeInt
);
29 tabDef
.addField("f3", typeString
, 20);
30 DbRetVal rv
= dbMgr
->createTable("t1", tabDef
);
31 if (rv
!= OK
) { printf("Table creation failed\n"); return 1; }
32 printf("Table created\n");
35 int insertTupleWithSameValue(DatabaseManager
*dbMgr
, Connection
&conn
)
37 Table
*table
= dbMgr
->openTable("t1");
40 printf("Unable to open table\n");
44 char name
[20] = "PRAVEEN";
45 table
->bindFld("f1", &id1
);
46 table
->bindFld("f2", &id2
);
47 table
->bindFld("f3", name
);
50 for (int i
= 0 ; i
< 10 ; i
++)
52 conn
.startTransaction();
54 rv
= table
->insertTuple();
60 printf("Total Tuples inserted is %d\n", icount
);
61 dbMgr
->closeTable(table
);
66 int insertTuplef2NUL(DatabaseManager
*dbMgr
, Connection
&conn
)
68 Table
*table
= dbMgr
->openTable("t1");
71 printf("Unable to open table\n");
76 table
->bindFld("f1", &id1
);
77 //table->bindFld("f2", &id2);
79 for( int i
=10;i
<=20;i
=i
+10)
81 conn
.startTransaction();
83 rv
= table
->insertTuple();
84 if (rv
!= OK
) { printf("Insertion failed "); break; }
88 printf("Tuple inserted is %d \n",count
);
89 dbMgr
->closeTable(table
);
93 int creatTable(DatabaseManager
*dbMgr
)
96 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
97 tabDef
.addField("f2", typeInt
);
98 DbRetVal rv
= dbMgr
->createTable("t1", tabDef
);
99 if (rv
!= OK
) { printf("Table creation failed\n"); return 1; }
100 printf("Table created\n");
103 int createIndex(DatabaseManager
*dbMgr
)
105 //Creating hash index on field f1 of table t1
106 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
107 strcpy(idxInfo
->tableName
, "t1");
108 idxInfo
->list
.append("f1");
110 idxInfo
->indType
= treeIndex
;
112 idxInfo
->indType
= trieIndex
;
114 idxInfo
->indType
= hashIndex
;
117 DbRetVal rv
= dbMgr
->createIndex("indx1", idxInfo
);
118 if (rv
!= OK
) { printf("Index creation failed\n"); return 1; }
119 printf("Index created for t1(f1)\n");
121 //Creating hash index on field f2 of table t1
122 strcpy(idxInfo
->tableName
, "t1");
123 idxInfo
->list
.remove("f1");
124 idxInfo
->list
.append("f2");
126 idxInfo
->indType
= treeIndex
;
128 idxInfo
->indType
= trieIndex
;
130 idxInfo
->indType
= hashIndex
;
133 rv
= dbMgr
->createIndex("indx2", idxInfo
);
134 if (rv
!= OK
) { printf("Index creation failed\n"); return 1; }
135 printf("Index created for t1(f2)\n");