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 %g %s \n", id
, name
);
25 DbRetVal rv
= conn
.open("praba", "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", typeFloat
, 0, NULL
, true, 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 rv
= dbMgr
->createIndex("indx1", idxInfo
);
45 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
46 printf("Index created\n");
49 Table
*table
= dbMgr
->openTable("t1");
50 if (table
== NULL
) { printf("Unable to open table\n"); return 4; }
51 table
->bindFld("f1", &id
);
52 table
->bindFld("f2", name
);
56 rv
=conn
.startTransaction();
57 for(i
= 1.0; i
< 1.5; i
= i
+ 0.1)
59 if (rv
!= OK
) exit(5);
61 strcpy(name
, "PRABAKARAN0123456750590");
62 ret
= table
->insertTuple();
64 printf("Tuple inserted %g\n", i
);
68 conn
.startTransaction();
69 select(table
, OpEquals
);
72 conn
.startTransaction();
73 select(table
, OpNotEquals
);
76 conn
.startTransaction();
77 select(table
, OpLessThan
);
80 conn
.startTransaction();
81 select( table
, OpLessThanEquals
);
84 conn
.startTransaction();
85 select( table
, OpGreaterThan
);
88 conn
.startTransaction();
89 select( table
, OpGreaterThanEquals
);
94 p1
.setTerm("f1", OpEquals
, &val1
);
95 table
->setCondition(&p1
);
96 rv
= conn
.startTransaction();
97 for(i
= 1.0; i
< 1.5; i
= i
+0.1)
99 if (rv
!= OK
) exit (1);
102 tuple
= (char*)table
->fetch() ;
103 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
104 strcpy(name
, "PRABAKARAN0950576543210");
105 table
->updateTuple();
109 rv
= conn
.startTransaction();
110 for(i
= 1; i
< 1.5; i
++)
112 if (rv
!= OK
) exit (1);
115 tuple
= (char*)table
->fetch() ;
116 if (tuple
== NULL
) {printf("loop break in %d\n", i
);table
->close();break;}
117 printf("deleting tuple %g %s \n", id
, name
);
118 table
->deleteTuple();
123 table
->setCondition(NULL
);
124 rv
= conn
.startTransaction();
126 while ((tuple
= (char*) table
->fetch())) {
127 printf("after delete tuple present. Its value is %g %s \n", id
, name
);
132 dbMgr
->closeTable(table
);
133 dbMgr
->dropTable("t1");