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");
8 idxInfo
->indType
= hashIndex
;
10 idxInfo
->isUnique
= unique
;
12 DbRetVal rv
= dbMgr
->createIndex("indx1", idxInfo
);
13 if (rv
!= OK
) { printf("Index creation failed\n"); return 1; }
14 printf("Index created\n");
18 int createTable(DatabaseManager
*dbMgr
)
21 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
22 tabDef
.addField("f2", typeInt
);
23 tabDef
.addField("f3", typeString
, 20);
24 DbRetVal rv
= dbMgr
->createTable("t1", tabDef
);
25 if (rv
!= OK
) { printf("Table creation failed\n"); return 1; }
26 printf("Table created\n");
29 int insertTupleWithSameValue(DatabaseManager
*dbMgr
, Connection
&conn
)
31 Table
*table
= dbMgr
->openTable("t1");
34 printf("Unable to open table\n");
38 char name
[20] = "PRAVEEN";
39 table
->bindFld("f1", &id1
);
40 table
->bindFld("f2", &id2
);
41 table
->bindFld("f3", name
);
44 for (int i
= 0 ; i
< 10 ; i
++)
46 conn
.startTransaction();
48 rv
= table
->insertTuple();
54 printf("Total Tuples inserted is %d\n", icount
);
55 dbMgr
->closeTable(table
);
60 int insertTuplef2NUL(DatabaseManager
*dbMgr
, Connection
&conn
)
62 Table
*table
= dbMgr
->openTable("t1");
65 printf("Unable to open table\n");
70 table
->bindFld("f1", &id1
);
71 //table->bindFld("f2", &id2);
73 for( int i
=10;i
<=20;i
=i
+10)
75 conn
.startTransaction();
77 rv
= table
->insertTuple();
78 if (rv
!= OK
) { printf("Insertion failed "); break; }
82 printf("Tuple inserted is %d \n",count
);
83 dbMgr
->closeTable(table
);
87 int creatTable(DatabaseManager
*dbMgr
)
90 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
91 tabDef
.addField("f2", typeInt
);
92 DbRetVal rv
= dbMgr
->createTable("t1", tabDef
);
93 if (rv
!= OK
) { printf("Table creation failed\n"); return 1; }
94 printf("Table created\n");
97 int createIndex(DatabaseManager
*dbMgr
)
99 //Creating hash index on field f1 of table t1
100 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
101 strcpy(idxInfo
->tableName
, "t1");
102 idxInfo
->list
.append("f1");
103 idxInfo
->indType
= hashIndex
;
105 DbRetVal rv
= dbMgr
->createIndex("indx1", idxInfo
);
106 if (rv
!= OK
) { printf("Index creation failed\n"); return 1; }
107 printf("Index created for t1(f1)\n");
109 //Creating hash index on field f2 of table t1
110 strcpy(idxInfo
->tableName
, "t1");
111 idxInfo
->list
.remove("f1");
112 idxInfo
->list
.append("f2");
113 idxInfo
->indType
= hashIndex
;
115 rv
= dbMgr
->createIndex("indx2", idxInfo
);
116 if (rv
!= OK
) { printf("Index creation failed\n"); return 1; }
117 printf("Index created for t1(f2)\n");