test cases for trie index
[csql.git] / test / dbapi / DataType / datetest.c
blob41f99e67cff514bdd8f7fe1d309ffb3d9037b143
1 #include<CSql.h>
3 Date id;
4 char name[196] = "PRABAKARAN";
5 int select(Table *table, ComparisionOp op)
7 printf("Operator test for %d\n", op);
8 Condition p1;
9 Date val1(1981, 12, 22);
10 p1.setTerm("f1", op, &val1);
11 table->setCondition(&p1);
12 table->execute();
13 void *tuple;
14 while ((tuple = (char*) table->fetch())) {
15 printf("tuple value is ");
16 AllDataType::printVal(&id, typeDate,0);
17 printf(" %s \n", name);
19 table->closeScan();
20 return 0;
23 int main()
26 Connection conn;
27 DbRetVal rv = conn.open("root", "manager");
28 if (rv != OK)
30 printf("Error during connection %d\n", rv);
31 return 1;
33 DatabaseManager *dbMgr = conn.getDatabaseManager();
34 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
35 TableDef tabDef;
36 tabDef.addField("f1", typeDate, 0 ,NULL, 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");
41 #ifdef WITHINDEX
42 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
43 strcpy(idxInfo->tableName, "t1");
44 idxInfo->list.append("f1");
45 idxInfo->isUnique = true;
46 idxInfo->isPrimary = true;
47 idxInfo->indType = hashIndex;
48 rv = dbMgr->createIndex("indx1", idxInfo);
49 if (rv != OK) { printf("Index creation failed\n"); return -1; }
50 delete idxInfo;
51 printf("Index created\n");
52 #endif
53 #ifdef WITHTREEINDEX
54 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
55 strcpy(idxInfo->tableName, "t1");
56 idxInfo->list.append("f1");
57 idxInfo->indType = treeIndex;
58 rv = dbMgr->createIndex("indx1", idxInfo);
59 if (rv != OK) { printf("Index creation failed\n"); return -1; }
60 delete idxInfo;
61 printf("Index created\n");
62 #endif
64 Table *table = dbMgr->openTable("t1");
65 if (table == NULL) { printf("Unable to open table\n"); return 4; }
66 table->bindFld("f1", &id);
67 table->bindFld("f2", name);
68 char *tuple;
69 int ret;
70 long i;
71 rv =conn.startTransaction();
72 for(i = 8; i< 13; i++)
74 if (rv != OK) exit(5);
75 for (int j =20 ; j <25; j++) {
76 id.set(1981, i, j);
77 strcpy(name, "PRABAKARAN0123456750590");
78 ret = table->insertTuple();
79 if (ret != 0) break;
82 conn.commit();
84 conn.startTransaction();
85 select(table, OpEquals);
86 conn.commit();
88 conn.startTransaction();
89 select(table, OpNotEquals);
90 conn.commit();
92 conn.startTransaction();
93 select(table, OpLessThan);
94 conn.commit();
96 conn.startTransaction();
97 select( table, OpLessThanEquals);
98 conn.commit();
100 conn.startTransaction();
101 select( table, OpGreaterThan);
102 conn.commit();
104 conn.startTransaction();
105 select( table, OpGreaterThanEquals);
106 conn.commit();
109 dbMgr->closeTable(table);
110 dbMgr->dropTable("t1");
112 conn.close();
113 return 0;