adding mutex name
[csql.git] / test / dbapi / Predicate / orandpredicate1.c
blob27c08707e42b8e0e4a646a364d7edd01c023eecc
1 //Testing OR 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 OR 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 int inscount = insertTuple(dbMgr, conn);
16 //check the inscount and return error
18 Table *table = dbMgr->openTable("t1");
19 if (table == NULL)
21 printf("Unable to open table\n");
22 return 0;
26 Condition p1,p2,p3,p4,p5;
27 int val1 = 2, val2 = 3, val3 = 4;
28 p1.setTerm("f1", OpEquals, &val3);
29 p2.setTerm("f2", OpGreaterThan, &val2);
30 p3.setTerm("f2", OpEquals, &val3);
31 p4.setTerm("f1", OpLessThan, &val3);
32 p5.setTerm("f1", OpGreaterThan, &val1);
35 Condition cond1, cond1a;
36 cond1.setTerm(p1.getPredicate(), OpOr, p2.getPredicate());
37 cond1a.setTerm(cond1.getPredicate(), OpAnd, p4.getPredicate());
38 table->setCondition(&cond1a);
39 printf("Predicate: (f1 ==4 OR f2 >3) AND (f1< 4) \n");
40 conn.startTransaction();
41 execAndPrint(table);
42 conn.commit();
44 Condition cond2, cond2a;
45 cond2.setTerm(p4.getPredicate(), OpOr, p2.getPredicate());
46 cond2a.setTerm(cond1.getPredicate(), OpAnd, cond2.getPredicate());
47 table->setCondition(&cond2a);
48 printf("Predicate: (f1 ==4 OR f2 >3) AND (f1< 4 OR f2 > 2) \n");
49 conn.startTransaction();
50 execAndPrint(table);
51 conn.commit();
53 dbMgr->closeTable(table);
54 dbMgr->dropTable("t1");
55 conn.close();
56 return 0;