test cases for trie index
[csql.git] / test / dbapi / Predicate / notandpredicate1.c
blob9965a525ef8da01b626f6fce9a0fbe5bd9197495
1 //Testing NOT with AND operator with all comparision operator on int data type.
2 //Five tuples are inserted and then selected by setting predicates
3 //with AND operator with NOT operator
5 #include "common.h"
6 int main()
8 Connection conn;
9 DbRetVal rv = conn.open("root", "manager");
10 if (rv != OK) return 1;
11 DatabaseManager *dbMgr = conn.getDatabaseManager();
12 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
14 if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
15 #ifdef WITHF1INDEX
16 if (createIndex(dbMgr, "f1", "idx1") != 0) {dbMgr->dropTable("t1");
17 conn.close();
18 return 4;
20 #endif
21 #ifdef WITHF1TREEINDEX
22 if (createIndex(dbMgr, "f1", "idx1", true) != 0) {dbMgr->dropTable("t1");
23 conn.close();
24 return 4;
26 #endif
28 #ifdef WITHF2INDEX
29 if (createIndex(dbMgr, "f2", "idx2") != 0) {dbMgr->dropTable("t1");
30 conn.close();
31 return 4;
33 #endif
34 #ifdef WITHF2TREEINDEX
35 if (createIndex(dbMgr, "f2", "idx2", true) != 0) {dbMgr->dropTable("t1");
36 conn.close();
37 return 4;
39 #endif
41 int inscount = insertTuple(dbMgr, conn);
42 //check the inscount and return error
44 Table *table = dbMgr->openTable("t1");
45 if (table == NULL)
47 printf("Unable to open table\n");
48 return 0;
52 Condition p1,p2,p3,p4,p5;
53 int val1 = 2, val2 = 3, val3 = 4;
54 p1.setTerm("f1", OpEquals, &val3);
55 p2.setTerm("f2", OpGreaterThan, &val2);
56 p3.setTerm("f2", OpEquals, &val3);
57 p4.setTerm("f1", OpLessThan, &val3);
58 p5.setTerm("f1", OpGreaterThan, &val1);
61 Condition cond1, cond1a;
62 cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
63 cond1a.setTerm(cond1.getPredicate(), OpNot);
64 table->setCondition(&cond1a);
65 printf("Predicate: NOT(f1 ==4 AND f2 >3) \n");
66 conn.startTransaction();
67 execAndPrint(table);
68 conn.commit();
70 Condition cond2, cond2a;
71 cond2.setTerm(p1.getPredicate(), OpAnd, p3.getPredicate());
72 cond2a.setTerm(cond2.getPredicate(), OpNot);
73 table->setCondition(&cond2a);
74 printf("Predicate: NOT( f1 ==4 AND f2 ==4) \n");
75 conn.startTransaction();
76 execAndPrint(table);
77 conn.commit();
79 Condition cond3, cond3a;
80 cond3.setTerm(p4.getPredicate(), OpAnd, p5.getPredicate());
81 cond3a.setTerm(cond3.getPredicate(), OpNot);
82 table->setCondition(&cond3a);
83 printf("Predicate: NOT( f1 <4 AND f1 >2) \n");
84 conn.startTransaction();
85 execAndPrint(table);
86 conn.commit();
89 Condition cond4, cond4a;
90 cond4.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
91 cond4a.setTerm(cond4.getPredicate(), OpNot);
92 table->setCondition(&cond4a);
93 printf("Predicate: NOT( f1 <4 AND f2 >3) \n");
94 conn.startTransaction();
95 execAndPrint(table);
96 conn.commit();
98 Condition cond5, cond5a;
99 cond5.setTerm(p2.getPredicate(), OpNot);
100 cond5a.setTerm(p4.getPredicate(), OpAnd, cond5.getPredicate());
101 table->setCondition(&cond5a);
102 printf("Predicate: ( f1 <4 AND (NOT(f2 >3)) \n");
103 conn.startTransaction();
104 execAndPrint(table);
106 conn.commit();
107 dbMgr->closeTable(table);
108 dbMgr->dropTable("t1");
109 conn.close();
110 return 0;