4 char name
[196] = "PRABAKARAN";
5 int select(Table
*table
, ComparisionOp op
)
7 printf("Operator test for %d\n", op
);
9 TimeStamp
val1(1981, 12, 24, 12, 30, 30);
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
, typeTimeStamp
,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", typeTimeStamp
, 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 if (rv
!= OK
) exit(5);
60 for(i
= 1; i
< 10; i
++) {
61 id
.setDate(1981, 12, 21+i
);
62 id
.setTime(12, 30, 27 +i
);
63 strcpy(name
, "PRABAKARAN0123456750590");
64 ret
= table
->insertTuple();
67 AllDataType::printVal(&id
, typeTimeStamp
,0);
68 printf(" %s \n", name
);
72 conn
.startTransaction();
73 select(table
, OpEquals
);
76 conn
.startTransaction();
77 select(table
, OpNotEquals
);
80 conn
.startTransaction();
81 select(table
, OpLessThan
);
84 conn
.startTransaction();
85 select( table
, OpLessThanEquals
);
88 conn
.startTransaction();
89 select( table
, OpGreaterThan
);
92 conn
.startTransaction();
93 select( table
, OpGreaterThanEquals
);
98 p1
.setTerm("f1", OpEquals
, &val1
);
99 table
->setCondition(&p1
);
100 rv
= conn
.startTransaction();
101 if (rv
!= OK
) exit (1);
102 val1
.setDate(1981, 12, 24);
103 val1
.setTime(12, 30, 30);
105 tuple
= (char*)table
->fetch() ;
107 strcpy(name
, "My value is updated");
108 table
->updateTuple();
113 rv
= conn
.startTransaction();
114 if (rv
!= OK
) exit (1);
115 val1
.setDate(1981, 12, 28);
116 val1
.setTime(12, 30, 34);
120 tuple
= (char*)table
->fetch() ;
123 AllDataType::printVal(&id
, typeTimeStamp
,0);
124 printf(" %s \n", name
);
125 table
->deleteTuple();
130 table
->setCondition(NULL
);
131 rv
= conn
.startTransaction();
133 while ((tuple
= (char*) table
->fetch())) {
134 printf("after delete ");
135 AllDataType::printVal(&id
, typeTimeStamp
,0);
136 printf(" %s \n", name
);
141 dbMgr
->closeTable(table
);
142 dbMgr
->dropTable("t1");