6 DbRetVal rv
= conn
.open("praba", "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, true );
16 tabDef
.addField("f2", typeInt
);
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 table
->bindFld("f1", &id1
);
40 table
->bindFld("f2", &id2
);
45 rv
= conn
.startTransaction();
46 if (rv
!= OK
) exit(1);
47 for(i
= 0; i
< 10; i
++)
51 ret
= table
->insertTuple();
56 printf("Total tuples inserted: %d\n", icount
);
59 p1
.setTerm("f1", OpEquals
, &val1
);
60 p2
.setTerm("f2", OpEquals
, &val1
);
61 table
->setCondition(&p1
);
62 rv
=conn
.startTransaction();
63 if (rv
!= OK
) exit(1);
64 for(i
= 0; i
< 10; i
++)
68 tuple
= (char*)table
->fetch() ;
69 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
70 printf("I:tuple value is %d %d \n", id1
, id2
);
74 table
->setCondition(&p2
);
75 for(i
= 0; i
< 10; i
++)
79 tuple
= (char*)table
->fetch() ;
80 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
81 printf("II:tuple value is %d %d \n", id1
, id2
);
86 rv
= conn
.startTransaction();
87 if (rv
!= OK
) exit (1);
88 table
->setCondition(&p1
);
91 tuple
= (char*)table
->fetch() ;
97 table
->setCondition(&p2
);
100 tuple
= (char*)table
->fetch() ;
103 table
->updateTuple();
109 rv
= conn
.startTransaction();
110 if (rv
!= OK
) exit (1);
111 table
->setCondition(&p1
);
114 tuple
= (char*)table
->fetch() ;
116 table
->deleteTuple();
119 table
->setCondition(&p2
);
122 tuple
= (char*)table
->fetch() ;
124 table
->deleteTuple();
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");