test cases for trie index
[csql.git] / test / dbapi / Predicate / predicate1.c
blob81aceb3591f2bd528a0651cad909e8f05e33948a
1 /*
2 a. f1=10
3 b. f1!= 10
4 c. f1<10
5 d. f1<=10
6 e. f1>10
7 f. f1>=10
8 */
9 #include<CSql.h>
10 int id=0;
11 char name[100];//="NIHAR";
12 int select(Table *table, ComparisionOp op)
14 printf("Operator Test for %d\n",op);
15 Condition p1;
16 int val1=10;
17 p1.setTerm("f1",op,&val1);
18 table->setCondition(&p1);
19 table->execute();
20 void *tuple;
21 while((tuple=(char*) table->fetch()))
23 printf("Tuple is %d %s \n",id,name);
25 table->closeScan();
26 return 0;
29 int main()
31 Connection conn;
32 DbRetVal rv=conn.open("root","manager");
33 if (rv != OK)
35 printf("Error during connection %d\n", rv);
36 return 1;
38 DatabaseManager *dbMgr = conn.getDatabaseManager();
39 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
40 TableDef tabDef;
41 tabDef.addField("f1", typeInt, 0, NULL, true );
42 tabDef.addField("f2", typeString, 100);
43 rv = dbMgr->createTable("t1", tabDef);
44 if (rv != OK) { printf("Table creation failed\n"); return 3; }
45 printf("Table created\n");
46 #ifdef WITHINDEX
47 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
48 strcpy(idxInfo->tableName, "t1");
49 idxInfo->list.append("f1");
50 idxInfo->indType = hashIndex;
51 rv = dbMgr->createIndex("indx1", idxInfo);
52 if (rv != OK) { printf("Index creation failed\n"); return -1; }
53 printf("Index created\n");
54 delete idxInfo;
55 #endif
56 #ifdef WITHTREEINDEX
57 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
58 strcpy(idxInfo->tableName, "t1");
59 idxInfo->list.append("f1");
60 idxInfo->indType = treeIndex;
61 rv = dbMgr->createIndex("indx1", idxInfo);
62 if (rv != OK) { printf("Index creation failed\n"); return -1; }
63 printf("Index created\n");
64 delete idxInfo;
65 #endif
66 Table *table = dbMgr->openTable("t1");
67 if (table == NULL) { printf("Unable to open table\n"); return 4; }
68 table->bindFld("f1", &id);
69 table->bindFld("f2", name);
70 char *tuple;
71 int ret;
72 int i;
73 char nam[100];
74 rv =conn.startTransaction();
75 for(i = 6; i< 12; i++)
77 if (rv != OK) exit(5);
78 id= i;
79 sprintf(nam,"%s%d","NIHAR",i);
80 strcpy(name, nam);
81 ret = table->insertTuple();
82 if (ret != 0) break;
84 conn.commit();
85 conn.startTransaction();
86 select(table, OpEquals);
87 conn.commit();
89 conn.startTransaction();
90 select(table, OpNotEquals);
91 conn.commit();
93 conn.startTransaction();
94 select(table, OpLessThan);
95 conn.commit();
97 conn.startTransaction();
98 select( table, OpLessThanEquals);
99 conn.commit();
101 conn.startTransaction();
102 select( table, OpGreaterThan);
103 conn.commit();
105 conn.startTransaction();
106 select( table, OpGreaterThanEquals);
107 conn.commit();
109 dbMgr->closeTable(table);
110 dbMgr->dropTable("t1");
112 conn.close();
113 return 0;