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 ");
16 AllDataType::printVal(&id
, typeTime
,0);
17 printf(" %s \n", name
);
27 DbRetVal rv
= conn
.open("praba", "manager");
30 printf("Error during connection %d\n", rv
);
33 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
34 if (dbMgr
== NULL
) { printf("Auth failed\n"); return 2;}
36 tabDef
.addField("f1", typeTime
, 0, NULL
, true, true );
37 tabDef
.addField("f2", typeString
, 196);
38 rv
= dbMgr
->createTable("t1", tabDef
);
39 if (rv
!= OK
) { printf("Table creation failed\n"); return 3; }
40 printf("Table created\n");
42 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
43 strcpy(idxInfo
->tableName
, "t1");
44 idxInfo
->list
.append("f1");
45 idxInfo
->indType
= hashIndex
;
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();
59 for(i
= 10; i
< 15; i
++)
61 if (rv
!= OK
) exit(5);
62 for (int j
=29 ; j
<34; j
++) {
64 strcpy(name
, "PRABAKARAN0123456750590");
65 ret
= table
->insertTuple();
71 conn
.startTransaction();
72 select(table
, OpEquals
);
75 conn
.startTransaction();
76 select(table
, OpNotEquals
);
79 conn
.startTransaction();
80 select(table
, OpLessThan
);
83 conn
.startTransaction();
84 select( table
, OpLessThanEquals
);
87 conn
.startTransaction();
88 select( table
, OpGreaterThan
);
91 conn
.startTransaction();
92 select( table
, OpGreaterThanEquals
);
97 p1
.setTerm("f1", OpEquals
, &val1
);
98 table
->setCondition(&p1
);
99 rv
= conn
.startTransaction();
100 if (rv
!= OK
) exit (1);
101 val1
.set(12, 30, 30);
103 tuple
= (char*)table
->fetch() ;
105 strcpy(name
, "My value is updated");
106 table
->updateTuple();
111 rv
= conn
.startTransaction();
112 for(i
= 0; i
< 5; i
++)
114 if (rv
!= OK
) exit (1);
115 val1
.set(12, 29+i
, 30);
118 tuple
= (char*)table
->fetch() ;
119 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
120 printf("deleting tuple ");
121 AllDataType::printVal(&id
, typeTime
,0);
122 printf(" %s \n", name
);
123 table
->deleteTuple();
128 table
->setCondition(NULL
);
129 rv
= conn
.startTransaction();
131 while ((tuple
= (char*) table
->fetch())) {
132 printf("after delete tuple value is ");
133 AllDataType::printVal(&id
, typeTime
,0);
134 printf(" %s \n", name
);
139 dbMgr
->closeTable(table
);
140 dbMgr
->dropTable("t1");