public void setUp() { c1 = new Constant("'value1'"); c2 = new Constant("'value1'"); c3 = new Constant("'value22'"); c4 = new Constant("5"); c5 = new Constant("66"); c6 = new Constant("flibble"); c7 = new Constant("5::REAL"); c8 = new Constant("1089290109834.28728747598768541"); c9 = new Constant("1089290109834.28728747598768542"); c10 = new Constant("5.1"); c11 = new Constant("5.1::REAL"); c12 = new Constant(new BigDecimal((new Float(5.1)).doubleValue()).toString()); c13 = new Constant("1.3432E-11"); }
public void testConstantWithNullValue() throws Exception { try { Constant c = new Constant(null); fail("Expected: NullPointerException"); } catch (NullPointerException e) { } }
public void testGetSQLString() throws Exception { Constant c = new Constant("'A constant'"); assertEquals("'A constant'", c.getSQLString()); }
public void testValueMap() throws Exception { Set values = new HashSet(); AbstractValue v1 = new Constant("'c1'"); AbstractValue v2 = new Constant("'c2'"); AbstractValue v3 = new Constant("'c3'"); SelectValue s1 = new SelectValue(v1, "alias1"); SelectValue s2 = new SelectValue(v2, "alias2"); SelectValue s3 = new SelectValue(v3, "alias3"); values.add(s1); values.add(s2); values.add(s3); Map result = new HashMap(); result.put(v1, s1); result.put(v2, s2); result.put(v3, s3); Query q1 = new Query("SELECT 'c1' AS alias1, 'c2' AS alias2, 'c3' AS alias3 FROM table"); PrecomputedTable pt = new PrecomputedTable(q1, q1.getSQLString(), "name", null, con); assertEquals(result, pt.getValueMap()); }
public void testKimsBug2() throws Exception { Table t = new Table("a", "b"); Constraint c1 = new Constraint(new Constant("5325019"), Constraint.LT, new Field("b", t)); Constraint c2 = new Constraint(new Constant("10669827"), Constraint.EQ, new Field("b", t)); Constraint c3 = new Constraint(new Constant("1066982"), Constraint.EQ, new Field("b", t)); Constraint c4 = new Constraint(new Constant("5325020"), Constraint.LT, new Field("b", t)); assertEquals(Constraint.IMPLIED_BY, c1.compare(c2)); assertEquals(Constraint.EXCLUDES, c1.compare(c3)); assertEquals(Constraint.IMPLIED_BY, c1.compare(c4)); Set set1 = Collections.singleton(c2); Set set2 = Collections.singleton(c1); Set equalsSet = new LinkedHashSet(); assertFalse(QueryOptimiser.compareConstraints(set1, set2, equalsSet)); assertTrue(equalsSet.isEmpty()); }
public void testTooManyColumns() throws Exception { q1.addSelect(new SelectValue(new Constant("8"), "r")); try { c1.getSQLString(); fail("Expected: IllegalStateException"); } catch (IllegalStateException e) { } try { SubQueryConstraint c = new SubQueryConstraint(v1, q1); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException e) { } } }
public void setUp() { Constant c1 = new Constant("3"); Constant c2 = new Constant("f"); Table t = new Table("mytable"); Field f = new Field("myfield", t); v1 = new SelectValue(c1, "alias1"); v2 = new SelectValue(c1, "alias1"); v3 = new SelectValue(c1, "alias2"); v4 = new SelectValue(c2, "alias1"); v5 = new SelectValue(c2, "alias3"); v6 = new SelectValue(f, null); v7 = new SelectValue(f, "myfield"); v8 = new SelectValue(f, "alias4"); }
public void testWhereTwoEqualConstraints() throws Exception { q1 = new Query("select table1.field1 from table1 where table1.field1 = 1 and table1.field2 = 2"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Field f2 = new Field("field2", t1); Constant c1 = new Constant("1"); Constant c2 = new Constant("2"); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addWhere(new Constraint(f1, Constraint.EQ, c1)); q2.addWhere(new Constraint(f2, Constraint.EQ, c2)); assertEquals(q2, q1); }
public void setUp() { q1 = new Query(); Table t = new Table("mytable"); Constant c = new Constant("1"); Field f = new Field("a", t); SelectValue sv = new SelectValue(f, null); q1.addFrom(t); q1.addSelect(sv); q1.addWhere(new Constraint(f, Constraint.EQ, c)); }
public void testHavingTwoEqualConstraints() throws Exception { q1 = new Query("select table1.field1 from table1 group by table1.field1 having table1.field1 = 1 and table1.field2 = 2"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Field f2 = new Field("field2", t1); Constant c1 = new Constant("1"); Constant c2 = new Constant("2"); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addGroupBy(f1); q2.addHaving(new Constraint(f1, Constraint.EQ, c1)); q2.addHaving(new Constraint(f2, Constraint.EQ, c2)); assertEquals(q2, q1); }
public void testNotNullStuff() throws Exception { q1 = new Query("select t.a from t where t.b is not null"); q2 = new Query("select t.a from t where not t.b is null"); q3 = new Query(); Table t1 = new Table("t"); Field f1 = new Field("a", t1); Field f2 = new Field("b", t1); q3.addSelect(new SelectValue(f1, null)); q3.addFrom(t1); q3.addWhere(new NotConstraint(new Constraint(f2, Constraint.EQ, new Constant("null")))); assertEquals("SELECT t.a FROM t WHERE t.b IS NOT NULL", q1.getSQLString()); assertEquals("SELECT t.a FROM t WHERE t.b IS NOT NULL", q2.getSQLString()); assertEquals("SELECT t.a FROM t WHERE t.b IS NOT NULL", q3.getSQLString()); assertEquals(q2, q1); assertEquals(q3, q1); assertEquals(q3, q2); }
public void testGetSQLString() throws Exception { Query q = new Query(); Table t = new Table("mytable"); Constant c = new Constant("1"); Field f = new Field("a", t); SelectValue sv = new SelectValue(f, null); q.addFrom(t); q.addSelect(sv); q.addWhere(new Constraint(f, Constraint.EQ, c)); assertEquals("SELECT mytable.a FROM mytable WHERE mytable.a = 1", q.getSQLString()); }
public void testScientificNumbers() throws Exception { Query q = new Query("SELECT table.field AS a FROM table WHERE table.field < 1.3432E-11"); Query eq = new Query(); Table t = new Table("table"); Field f = new Field("field", t); Constant c = new Constant("1.3432E-11"); SelectValue sv = new SelectValue(f, "a"); eq.addFrom(t); eq.addSelect(sv); eq.addWhere(new Constraint(f, Constraint.LT, c)); assertEquals(eq, q); }
public void testWhereOneEqualConstraint() throws Exception { q1 = new Query("select table1.field1 from table1 where table1.field1 = 1"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Constant c = new Constant("1"); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addWhere(new Constraint(f1, Constraint.EQ, c)); assertEquals(q2, q1); }
public void setUp() throws Exception { database = DatabaseFactory.getDatabase("db.unittest"); Query q1 = new Query(); Table t = new Table("tabletest"); Constant c = new Constant("50"); Field f1 = new Field("col1", t); Field f2 = new Field("col2", t); SelectValue sv1 = new SelectValue(f1, null); SelectValue sv2 = new SelectValue(f2, null); q1.addFrom(t); q1.addSelect(sv1); q1.addSelect(sv2); q1.addWhere(new Constraint(f1, Constraint.LT, c)); q1.addOrderBy(f1); Connection con = database.getConnection(); con.setAutoCommit(false); pt1 = new PrecomputedTable(q1, q1.getSQLString(), "precompA", "test", con); con.close(); }
public void testHavingOneLessThanConstraint() throws Exception { q1 = new Query("select table1.field1 from table1 group by table1.field1 having table1.field1 < 1"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Constant c = new Constant("1"); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addGroupBy(f1); q2.addHaving(new Constraint(f1, Constraint.LT, c)); assertEquals(q2, q1); }
public void testNullStuff() throws Exception { q1 = new Query("select t.a from t where t.b is null"); q2 = new Query("select t.a from t where not t.b is not null"); q3 = new Query(); Table t1 = new Table("t"); Field f1 = new Field("a", t1); Field f2 = new Field("b", t1); q3.addSelect(new SelectValue(f1, null)); q3.addFrom(t1); q3.addWhere(new Constraint(f2, Constraint.EQ, new Constant("null"))); assertEquals("SELECT t.a FROM t WHERE t.b IS NULL", q1.getSQLString()); assertEquals("SELECT t.a FROM t WHERE t.b IS NULL", q2.getSQLString()); assertEquals("SELECT t.a FROM t WHERE t.b IS NULL", q3.getSQLString()); assertEquals(q2, q1); assertEquals(q3, q1); assertEquals(q3, q2); }
public void testCoalesce() throws Exception { q1 = new Query("select coalesce(t.a, 53) AS b from t"); q2 = new Query(); Table t1 = new Table("t"); Field f1 = new Field("a", t1); Constant c1 = new Constant("53"); Function f2 = new Function(Function.COALESCE); f2.add(f1); f2.add(c1); q2.addSelect(new SelectValue(f2, "b")); q2.addFrom(t1); assertEquals("SELECT COALESCE(t.a, 53) AS b FROM t", q1.getSQLString()); assertEquals("SELECT COALESCE(t.a, 53) AS b FROM t", q2.getSQLString()); assertEquals(q1, q2); }
public void setUp() { q1 = new Query(); Table t = new Table("mytable"); Constant c = new Constant("1"); Field f = new Field("a", t); SelectValue sv = new SelectValue(f, null); q1.addFrom(t); q1.addSelect(sv); q1.addWhere(new Constraint(f, Constraint.EQ, c)); q2 = new Query(); Table t1 = new Table("mytable"); Table t2 = new Table("mytable"); Field f1 = new Field("a", t1); Field f2 = new Field("b", t2); sv = new SelectValue(f1, null); q2.addFrom(t1); q2.addFrom(t2); q2.addSelect(sv); q2.addWhere(new Constraint(f1, Constraint.EQ, c)); q2.addWhere(new Constraint(f2, Constraint.EQ, c)); }
public void setUp() { q1 = new Query(); Table t = new Table("mytable"); Constant c = new Constant("1"); Field f = new Field("a", t); SelectValue sv = new SelectValue(f, null); q1.addFrom(t); q1.addSelect(sv); q1.addWhere(new Constraint(f, Constraint.EQ, c)); q2 = new Query(); Table t1 = new Table("mytable"); Table t2 = new Table("mytable"); Field f1 = new Field("a", t1); Field f2 = new Field("b", t2); sv = new SelectValue(f1, null); q2.addFrom(t1); q2.addFrom(t2); q2.addSelect(sv); q2.addWhere(new Constraint(f1, Constraint.EQ, c)); q2.addWhere(new Constraint(f2, Constraint.EQ, c)); }