Examples of toSql()


Examples of org.apache.metamodel.query.Query.toSql()

        assertEquals("SELECT DISTINCT tbl.foo, tbl.bar AS f FROM sch.tbl", q.toSql());
    }

    public void testSimpleSelectFrom() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo\nFROM sch.tbl");
        assertEquals("SELECT tbl.foo FROM sch.tbl", q.toSql());

        assertEquals(1, q.getFromClause().getItemCount());
        FromItem fromItem = q.getFromClause().getItem(0);
        assertNull("FROM item was an expression based item, which indicates it was not parsed",
                fromItem.getExpression());
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

    }

    public void testCarthesianProduct() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc,
                "  SELECT a.foo,b.bar FROM      sch.tbl a, sch.tbl b \t WHERE a.foo = b.foo");
        assertEquals("SELECT a.foo, b.bar FROM sch.tbl a, sch.tbl b WHERE a.foo = b.foo", q.toSql());

        List<FromItem> fromItems = q.getFromClause().getItems();
        assertNotNull(fromItems.get(0).getTable());
        assertNotNull(fromItems.get(1).getTable());
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

    }

    public void testJoin() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc,
                "SELECT a.foo,b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals("SELECT a.foo, b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo", q.toSql());

        q = MetaModelHelper.parseQuery(dc,
                "SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz");
        assertEquals("SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz", q.toSql());
    }
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

                "SELECT a.foo,b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals("SELECT a.foo, b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo", q.toSql());

        q = MetaModelHelper.parseQuery(dc,
                "SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz");
        assertEquals("SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz", q.toSql());
    }

    public void testSimpleSelectFromWhere() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'baz' AND baz > 5");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.baz > 5", q.toSql());
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

        assertEquals("SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz", q.toSql());
    }

    public void testSimpleSelectFromWhere() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'baz' AND baz > 5");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.baz > 5", q.toSql());

        FilterClause whereClause = q.getWhereClause();
        assertEquals(2, whereClause.getItemCount());
        assertNull("WHERE item was an expression based item, which indicates it was not parsed", whereClause.getItem(0)
                .getExpression());
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

        assertEquals(Integer.class, whereClause.getItem(1).getOperand().getClass());
    }
   
    public void testWhereStringEscaped() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'ba\\'z'");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'ba'z'", q.toSql());
    }
   
    public void testWhereOperandIsBoolean() throws Exception {
     // set 'baz' column to an integer column (to influence query generation)
        MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

     // set 'baz' column to an integer column (to influence query generation)
        MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
        col.setType(ColumnType.BOOLEAN);
       
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE baz = TRUE");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.baz = TRUE", q.toSql());
    }
   
    public void testWhereOperandIsDate() throws Exception {
        // set 'baz' column to an integer column (to influence query generation)
           MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

        .select(colA).as("a").select(colB).as("b").select(colC).as("c")
        .toQuery();

    assertEquals(
        "SELECT tableAB.colA AS a, tableAB.colB AS b, tableC.colC AS c FROM tableAB LEFT JOIN tableC ON tableAB.colB = tableC.colC",
        q.toSql());
  }
}
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

        // set 'baz' column to an integer column (to influence query generation)
           MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
           col.setType(ColumnType.TIME);
          
           Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE baz = 10:24");
           assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.baz = TIME '10:24:00'", q.toSql());
       }

    public void testCoumpoundWhereClause() throws Exception {
        Query q = MetaModelHelper
                .parseQuery(dc, "SELECT foo FROM sch.tbl WHERE (bar = 'baz' OR (baz > 5 AND baz < 7))");
View Full Code Here

Examples of org.apache.metamodel.query.Query.toSql()

       }

    public void testCoumpoundWhereClause() throws Exception {
        Query q = MetaModelHelper
                .parseQuery(dc, "SELECT foo FROM sch.tbl WHERE (bar = 'baz' OR (baz > 5 AND baz < 7))");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE (tbl.bar = 'baz' OR (tbl.baz > 5 AND tbl.baz < 7))", q.toSql());

        FilterClause wc = q.getWhereClause();
        assertEquals(1, wc.getItemCount());
        FilterItem item = wc.getItem(0);
        assertTrue(item.isCompoundFilter());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.