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
;
27 rv
= dbMgr
->createIndex("indx1", idxInfo
);
28 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
29 printf("Index created for f1\n");
30 printf("size of index field list %d\n", idxInfo
->list
.size());
31 idxInfo
->list
.remove("f1");
32 printf("size of index field list %d\n", idxInfo
->list
.size());
33 idxInfo
->list
.append("f2");
34 printf("size of index field list %d\n", idxInfo
->list
.size());
35 idxInfo
->indType
= hashIndex
;
37 idxInfo
->indType
= treeIndex
;
39 rv
= dbMgr
->createIndex("indx2", idxInfo
);
40 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
41 printf("Index created for f2\n");
43 Table
*table
= dbMgr
->openTable("t1");
44 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
46 char id2
[50] ="Aruna";
47 table
->bindFld("f1", &id1
);
48 table
->bindFld("f2", id2
);
53 rv
= conn
.startTransaction();
54 if (rv
!= OK
) exit(1);
55 for(i
= 0; i
< 10; i
++)
58 sprintf(id2
, "Aruna:%d", i
);
59 ret
= table
->insertTuple();
64 printf("Total tuples inserted: %d\n", icount
);
68 p1
.setTerm("f1", OpEquals
, &val1
);
69 p2
.setTerm("f2", OpEquals
, &val2
);
70 table
->setCondition(&p1
);
71 rv
=conn
.startTransaction();
72 if (rv
!= OK
) exit(1);
73 for(i
= 0; i
< 10; i
++)
77 tuple
= (char*)table
->fetch() ;
78 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->closeScan();break;}
79 printf("I:tuple value is %d %s \n", id1
, id2
);
83 table
->setCondition(&p2
);
84 for(i
= 0; i
< 10; i
++)
86 sprintf(val2
, "Aruna:%d", i
);
88 tuple
= (char*)table
->fetch() ;
89 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->closeScan();break;}
90 printf("II:tuple value is %d %s \n", id1
, id2
);
95 rv
=conn
.startTransaction();
96 if (rv
!= OK
) exit(1);
97 table
->setCondition(&p1
);
100 tuple
= (char*)table
->fetch() ;
102 table
->deleteTuple();
105 table
->setCondition(&p2
);
106 sprintf(val2
, "Aruna:%d", 2);
108 tuple
= (char*)table
->fetch() ;
110 table
->deleteTuple();
116 rv
= conn
.startTransaction();
117 table
->setCondition(NULL
);
118 if (rv
!= OK
) exit (1);
120 while((tuple
= (char*)table
->fetch())!= NULL
) {
121 printf("tuple value is %d %s \n", id1
, id2
);
126 printf("Total rows selected %d\n", count
);
127 dbMgr
->closeTable(table
);
128 dbMgr
->dropTable("t1");