*** empty log message ***
[csql.git] / test / dbapi / Predicate / andorandpredicate1.c
blob80a3d2b1263c82c0a8a0030b4027bb6385e59bfa
1 #include "common.h"
2 int main()
4 Connection conn;
5 DbRetVal rv = conn.open("root", "manager");
6 if (rv != OK) return 1;
7 DatabaseManager *dbMgr = conn.getDatabaseManager();
8 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
10 if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
11 int inscount = insertTuple(dbMgr, conn);
12 //check the inscount and return error
14 Table *table = dbMgr->openTable("t1");
15 if (table == NULL)
17 printf("Unable to open table\n");
18 return 0;
22 Condition p1,p2,p3,p4;
23 int val1 = 2, val2 = 3, val3 = 5;
24 p1.setTerm("f1", OpEquals, &val2);
25 p2.setTerm("f2", OpGreaterThan, &val1);
26 p3.setTerm("f3", OpNotEquals, &val3);
27 p4.setTerm("f4", OpLessThan, &val3);
29 Condition cond2, cond2a, cond2b;
30 cond2.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
31 cond2a.setTerm(p3.getPredicate(), OpAnd, p4.getPredicate());
32 cond2b.setTerm(cond2.getPredicate(), OpOr, cond2a.getPredicate());
33 table->setCondition(&cond2b);
34 printf("Predicate: (f1 ==3 AND f2 > 2) OR (f3 !=3 AND f4 <5) ) \n");
35 conn.startTransaction();
36 execAndPrint(table);
37 conn.commit();
39 dbMgr->closeTable(table);
40 dbMgr->dropTable("t1");
41 conn.close();
42 return 0;