6 DbRetVal rv
= conn
.open("root", "manager");
9 printf("Error during connection %d\n", rv
);
12 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
13 if (dbMgr
== NULL
) { printf("Auth failed\n"); return -1;}
15 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
16 tabDef
.addField("f2", typeInt
, 0, NULL
, true);
17 rv
= dbMgr
->createTable("t1", tabDef
);
18 if (rv
!= OK
) { printf("Table creation failed\n"); return -1; }
19 printf("Table created\n");
20 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
21 strcpy(idxInfo
->tableName
, "t1");
22 idxInfo
->list
.append("f1");
23 idxInfo
->isUnique
= true;
24 idxInfo
->isPrimary
= true;
25 idxInfo
->indType
= hashIndex
;
27 idxInfo
->indType
= treeIndex
;
30 idxInfo
->indType
= trieIndex
;
32 rv
= dbMgr
->createIndex("indx1", idxInfo
);
33 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
34 printf("Index created for f1\n");
35 printf("size of index field list %d\n", idxInfo
->list
.size());
36 idxInfo
->list
.remove("f1");
37 printf("size of index field list %d\n", idxInfo
->list
.size());
38 idxInfo
->list
.append("f2");
39 printf("size of index field list %d\n", idxInfo
->list
.size());
40 idxInfo
->indType
= hashIndex
;
42 idxInfo
->indType
= treeIndex
;
45 idxInfo
->indType
= trieIndex
;
47 rv
= dbMgr
->createIndex("indx2", idxInfo
);
48 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
49 printf("Index created for f2\n");
51 Table
*table
= dbMgr
->openTable("t1");
52 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
54 table
->bindFld("f1", &id1
);
55 table
->bindFld("f2", &id2
);
60 rv
= conn
.startTransaction();
61 if (rv
!= OK
) exit(1);
62 for(i
= 0; i
< 10; i
++)
66 ret
= table
->insertTuple();
71 printf("Total tuples inserted: %d\n", icount
);
74 p1
.setTerm("f1", OpEquals
, &val1
);
75 p2
.setTerm("f2", OpEquals
, &val1
);
76 table
->setCondition(&p1
);
77 rv
=conn
.startTransaction();
78 if (rv
!= OK
) exit(1);
79 for(i
= 0; i
< 10; i
++)
83 tuple
= (char*)table
->fetch() ;
84 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->closeScan();break;}
85 printf("I:tuple value is %d %d \n", id1
, id2
);
89 table
->setCondition(&p2
);
90 for(i
= 0; i
< 10; i
++)
94 tuple
= (char*)table
->fetch() ;
95 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->closeScan();break;}
96 printf("II:tuple value is %d %d \n", id1
, id2
);
101 rv
= conn
.startTransaction();
102 if (rv
!= OK
) exit (1);
103 table
->setCondition(&p1
);
106 tuple
= (char*)table
->fetch() ;
108 table
->deleteTuple();
111 printf("deleted record\n");
114 table
->setCondition(&p2
);
117 tuple
= (char*)table
->fetch() ;
119 table
->deleteTuple();
124 dbMgr
->closeTable(table
);
125 table
= dbMgr
->openTable("t1");
126 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
127 table
->bindFld("f1", &id1
);
128 table
->bindFld("f2", &id2
);
130 rv
= conn
.startTransaction();
131 table
->setCondition(NULL
);
132 if (rv
!= OK
) exit (1);
134 while((tuple
= (char*)table
->fetch())!= NULL
) {
135 printf("tuple value is %d %d \n", id1
, id2
);
140 printf("Total rows selected %d\n", count
);
141 dbMgr
->closeTable(table
);
142 dbMgr
->dropTable("t1");