4 char name
[196] = "PRABAKARAN";
5 int select(Table
*table
, ComparisionOp op
)
7 printf("Operator test for %d\n", op
);
10 p1
.setTerm("f1", op
, &val1
);
11 table
->setCondition(&p1
);
14 while ((tuple
= (char*) table
->fetch())) {
15 printf("tuple value is %d %s \n", id
, name
);
25 DbRetVal rv
= conn
.open("root", "manager");
28 printf("Error during connection %d\n", rv
);
31 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
32 if (dbMgr
== NULL
) { printf("Auth failed\n"); return 2;}
34 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
35 tabDef
.addField("f2", typeString
, 196);
36 rv
= dbMgr
->createTable("t1", tabDef
);
37 if (rv
!= OK
) { printf("Table creation failed\n"); return 3; }
38 printf("Table created\n");
40 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
41 strcpy(idxInfo
->tableName
, "t1");
42 idxInfo
->list
.append("f1");
43 idxInfo
->indType
= hashIndex
;
44 idxInfo
->isUnique
= true;
45 idxInfo
->isPrimary
= true;
46 rv
= dbMgr
->createIndex("indx1", idxInfo
);
47 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
48 printf("Index created\n");
51 Table
*table
= dbMgr
->openTable("t1");
52 if (table
== NULL
) { printf("Unable to open table\n"); return 4; }
53 table
->bindFld("f1", &id
);
54 table
->bindFld("f2", name
);
58 rv
=conn
.startTransaction();
61 if (rv
!= OK
) exit(5);
63 strcpy(name
, "PRABAKARAN0123456750590");
64 ret
= table
->insertTuple();
69 conn
.startTransaction();
70 select(table
, OpEquals
);
73 conn
.startTransaction();
74 select(table
, OpNotEquals
);
77 conn
.startTransaction();
78 select(table
, OpLessThan
);
81 conn
.startTransaction();
82 select( table
, OpLessThanEquals
);
85 conn
.startTransaction();
86 select( table
, OpGreaterThan
);
89 conn
.startTransaction();
90 select( table
, OpGreaterThanEquals
);
95 p1
.setTerm("f1", OpEquals
, &val1
);
96 table
->setCondition(&p1
);
97 rv
= conn
.startTransaction();
100 if (rv
!= OK
) exit (1);
103 tuple
= (char*)table
->fetch() ;
104 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->closeScan();break;}
105 strcpy(name
, "PRABAKARAN0950576543210");
106 table
->updateTuple();
110 rv
= conn
.startTransaction();
111 for(i
= 0; i
< 5; i
++)
113 if (rv
!= OK
) exit (1);
116 tuple
= (char*)table
->fetch() ;
117 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->closeScan();break;}
118 printf("deleting tuple %d %s \n", id
, name
);
119 table
->deleteTuple();
124 table
->setCondition(NULL
);
125 rv
= conn
.startTransaction();
127 while ((tuple
= (char*) table
->fetch())) {
128 printf("after delete tuple present. Its value is %d %s \n", id
, name
);
129 dbMgr
->dropTable("t1");
135 dbMgr
->closeTable(table
);
136 dbMgr
->dropTable("t1");