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", typeString
, 50);
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
->indType
= hashIndex
;
25 idxInfo
->indType
= treeIndex
;
28 idxInfo
->indType
= trieIndex
;
30 rv
= dbMgr
->createIndex("indx1", idxInfo
);
31 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
32 printf("Index created for f1\n");
33 printf("size of index field list %d\n", idxInfo
->list
.size());
34 idxInfo
->list
.remove("f1");
35 printf("size of index field list %d\n", idxInfo
->list
.size());
36 idxInfo
->list
.append("f2");
37 printf("size of index field list %d\n", idxInfo
->list
.size());
38 idxInfo
->indType
= hashIndex
;
40 idxInfo
->indType
= treeIndex
;
43 idxInfo
->indType
= trieIndex
;
45 rv
= dbMgr
->createIndex("indx2", idxInfo
);
46 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
47 printf("Index created for f2\n");
49 Table
*table
= dbMgr
->openTable("t1");
50 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
52 char id2
[50] ="Aruna";
53 table
->bindFld("f1", &id1
);
54 table
->bindFld("f2", id2
);
59 rv
= conn
.startTransaction();
60 if (rv
!= OK
) exit(1);
61 for(i
= 0; i
< 10; i
++)
64 sprintf(id2
, "Aruna:%d", i
);
65 ret
= table
->insertTuple();
70 printf("Total tuples inserted: %d\n", icount
);
74 p1
.setTerm("f1", OpEquals
, &val1
);
75 p2
.setTerm("f2", OpEquals
, &val2
);
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 %s \n", id1
, id2
);
89 table
->setCondition(&p2
);
90 for(i
= 0; i
< 10; i
++)
92 sprintf(val2
, "Aruna:%d", 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 %s \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 table
->setCondition(&p2
);
112 sprintf(val2
, "Aruna:%d", 2);
114 tuple
= (char*)table
->fetch() ;
116 table
->deleteTuple();
122 rv
= conn
.startTransaction();
123 table
->setCondition(NULL
);
124 if (rv
!= OK
) exit (1);
126 while((tuple
= (char*)table
->fetch())!= NULL
) {
127 printf("tuple value is %d %s \n", id1
, id2
);
132 printf("Total rows selected %d\n", count
);
133 dbMgr
->closeTable(table
);
134 dbMgr
->dropTable("t1");