1
[csql.git] / test / dbapi / Predicate / andpredicate1.c
blob1f39eab509616e02e8413e74ebbef311b5333f4f
1 //Testing 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
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
36 #ifdef WITHF2TREEINDEX
37 if (createIndex(dbMgr, "f2", "idx2", true) != 0) {dbMgr->dropTable("t1");
38 conn.close();
39 return 4;
41 #endif
43 int inscount = insertTuple(dbMgr, conn);
44 //check the inscount and return error
46 Table *table = dbMgr->openTable("t1");
47 if (table == NULL)
49 printf("Unable to open table\n");
50 return 0;
54 Condition p1,p2,p3,p4,p5;
55 int val1 = 2, val2 = 3, val3 = 4;
56 p1.setTerm("f1", OpEquals, &val3);
57 p2.setTerm("f2", OpGreaterThan, &val2);
58 p3.setTerm("f2", OpEquals, &val3);
59 p4.setTerm("f1", OpLessThan, &val3);
60 p5.setTerm("f1", OpGreaterThan, &val1);
63 Condition cond1;
64 cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
65 table->setCondition(&cond1);
66 printf("Predicate: f1 ==4 AND f2 >3 \n");
67 conn.startTransaction();
68 execAndPrint(table);
69 conn.commit();
71 Condition cond2;
72 cond2.setTerm(p1.getPredicate(), OpAnd, p3.getPredicate());
73 table->setCondition(&cond2);
74 printf("Predicate: f1 ==4 AND f2 ==4 \n");
75 conn.startTransaction();
76 execAndPrint(table);
77 conn.commit();
79 Condition cond3;
80 cond3.setTerm(p4.getPredicate(), OpAnd, p5.getPredicate());
81 table->setCondition(&cond3);
82 printf("Predicate: f1 <4 AND f1 >2 \n");
83 conn.startTransaction();
84 execAndPrint(table);
85 conn.commit();
88 Condition cond4;
89 cond4.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
90 table->setCondition(&cond4);
91 printf("Predicate: f1 <4 AND f2 >3 \n");
92 conn.startTransaction();
93 execAndPrint(table);
94 conn.commit();
96 dbMgr->closeTable(table);
97 dbMgr->dropTable("t1");
98 conn.close();
99 return 0;