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
;
24 rv
= dbMgr
->createIndex("indx1", idxInfo
);
25 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
26 printf("Index created for f1\n");
27 printf("size of index field list %d\n", idxInfo
->list
.size());
28 idxInfo
->list
.remove("f1");
29 printf("size of index field list %d\n", idxInfo
->list
.size());
30 idxInfo
->list
.append("f2");
31 printf("size of index field list %d\n", idxInfo
->list
.size());
32 rv
= dbMgr
->createIndex("indx2", idxInfo
);
33 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
34 printf("Index created for f2\n");
36 Table
*table
= dbMgr
->openTable("t1");
37 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
39 char id2
[50] ="Aruna";
40 table
->bindFld("f1", &id1
);
41 table
->bindFld("f2", id2
);
46 rv
= conn
.startTransaction();
47 if (rv
!= OK
) exit(1);
48 for(i
= 0; i
< 10; i
++)
51 sprintf(id2
, "Aruna:%d", i
);
52 ret
= table
->insertTuple();
57 printf("Total tuples inserted: %d\n", icount
);
61 p1
.setTerm("f1", OpEquals
, &val1
);
62 p2
.setTerm("f2", OpEquals
, &val2
);
63 table
->setCondition(&p1
);
64 rv
=conn
.startTransaction();
65 if (rv
!= OK
) exit(1);
66 for(i
= 0; i
< 10; i
++)
70 tuple
= (char*)table
->fetch() ;
71 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
72 printf("I:tuple value is %d %s \n", id1
, id2
);
76 table
->setCondition(&p2
);
77 for(i
= 0; i
< 10; i
++)
79 sprintf(val2
, "Aruna:%d", i
);
81 tuple
= (char*)table
->fetch() ;
82 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
83 printf("II:tuple value is %d %s \n", id1
, id2
);
88 rv
= conn
.startTransaction();
89 if (rv
!= OK
) exit (1);
90 table
->setCondition(&p1
);
93 tuple
= (char*)table
->fetch() ;
95 sprintf(id2
,"Aruna:%d", 99);
99 table
->setCondition(&p2
);
100 sprintf(val2
, "Aruna:%d", 10);
102 tuple
= (char*)table
->fetch() ;
105 table
->updateTuple();
111 rv
= conn
.startTransaction();
112 if (rv
!= OK
) exit (1);
113 table
->setCondition(&p1
);
116 tuple
= (char*)table
->fetch() ;
118 table
->deleteTuple();
121 table
->setCondition(&p2
);
122 sprintf(val2
, "Aruna:%d", 101);
124 tuple
= (char*)table
->fetch() ;
126 table
->deleteTuple();
132 rv
= conn
.startTransaction();
133 table
->setCondition(NULL
);
134 if (rv
!= OK
) exit (1);
136 while((tuple
= (char*)table
->fetch())!= NULL
) {
137 printf("tuple value is %d %s \n", id1
, id2
);
142 printf("Total rows selected %d\n", count
);
143 dbMgr
->closeTable(table
);
144 dbMgr
->dropTable("t1");