removing old folder content which had current storage source files
[csql.git] / test / dbapi / Predicate / notpredicate1.c
blob4165c0097ea5fe73e83b425c1dc2c72ca49eb35b
1 //Testing Not operator with all comparision operator on int data type.
2 //Five tuples are inserted and then selected using single term predicates
3 //all with NOT operator
4 /*
5 a. NOT(f1 = 3)
6 b. NOT(f1 != 3)
7 c. NOT(f1 < 3)
8 d. NOT(f1 <= 3)
9 e. NOT(f1 > 3)
10 f. NOT(f1 >=10)
11 (notpredicate1.c)
13 #include<CSql.h>
15 int id = 0;
16 char name[196] = "PRABAKARAN";
17 int select(Table *table, ComparisionOp op)
19 printf("Operator test for %d\n", op);
20 Condition p1;
21 int val1 = 3;
22 p1.setTerm("f1", op, &val1);
23 Condition p2;
24 p2.setTerm(p1.getPredicate(), OpNot);
25 table->setCondition(&p2);
26 table->execute();
27 void *tuple;
28 while ((tuple = (char*) table->fetch())) {
29 printf("tuple value is %d %s \n", id, name);
31 table->closeScan();
32 return 0;
35 int main()
38 Connection conn;
39 DbRetVal rv = conn.open("root", "manager");
40 if (rv != OK)
42 printf("Error during connection %d\n", rv);
43 return 1;
45 DatabaseManager *dbMgr = conn.getDatabaseManager();
46 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
47 TableDef tabDef;
48 tabDef.addField("f1", typeInt, 0, NULL, true );
49 tabDef.addField("f2", typeString, 196);
50 rv = dbMgr->createTable("t1", tabDef);
51 if (rv != OK) { printf("Table creation failed\n"); return 3; }
52 printf("Table created\n");
53 #ifdef WITHINDEX
54 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
55 strcpy(idxInfo->tableName, "t1");
56 idxInfo->list.append("f1");
57 idxInfo->indType = hashIndex;
58 rv = dbMgr->createIndex("indx1", idxInfo);
59 if (rv != OK) { printf("Index creation failed\n"); return -1; }
60 printf("Index created\n");
61 delete idxInfo;
62 #endif
63 #ifdef WITHTREEINDEX
64 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
65 strcpy(idxInfo->tableName, "t1");
66 idxInfo->list.append("f1");
67 idxInfo->indType = treeIndex;
68 rv = dbMgr->createIndex("indx1", idxInfo);
69 if (rv != OK) { printf("Index creation failed\n"); return -1; }
70 printf("Index created\n");
71 delete idxInfo;
72 #endif
73 Table *table = dbMgr->openTable("t1");
74 if (table == NULL) { printf("Unable to open table\n"); return 4; }
75 table->bindFld("f1", &id);
76 table->bindFld("f2", name);
77 char *tuple;
78 int ret;
79 int i;
80 rv =conn.startTransaction();
81 for(i = 0; i< 5; i++)
83 if (rv != OK) exit(5);
84 id= i;
85 strcpy(name, "PRABAKARAN0123456750590");
86 ret = table->insertTuple();
87 if (ret != 0) break;
89 conn.commit();
91 conn.startTransaction();
92 select(table, OpEquals);
93 conn.commit();
95 conn.startTransaction();
96 select(table, OpNotEquals);
97 conn.commit();
99 conn.startTransaction();
100 select(table, OpLessThan);
101 conn.commit();
103 conn.startTransaction();
104 select( table, OpLessThanEquals);
105 conn.commit();
107 conn.startTransaction();
108 select( table, OpGreaterThan);
109 conn.commit();
111 conn.startTransaction();
112 select( table, OpGreaterThanEquals);
113 conn.commit();
115 dbMgr->closeTable(table);
116 dbMgr->dropTable("t1");
118 conn.close();
119 return 0;