Examples of toSql()


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

        assertTrue(bazConditions.isCompoundFilter());
    }

    public void testWhereSomethingIsNull() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar IS NULL");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar IS NULL", q.toSql());

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

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

        assertEquals(OperatorType.EQUALS_TO, q.getWhereClause().getItem(0).getOperator());
    }

    public void testWhereSomethingIsNotNull() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar IS NOT NULL");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar IS NOT NULL", q.toSql());

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

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

        assertEquals(OperatorType.DIFFERENT_FROM, q.getWhereClause().getItem(0).getOperator());
    }

    public void testLimitAndOffset() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl LIMIT 1234 OFFSET 5");
        assertEquals("SELECT tbl.foo FROM sch.tbl", q.toSql());
        assertEquals(1234, q.getMaxRows().intValue());
        assertEquals(6, q.getFirstRow().intValue());
    }

    public void testWhereIn() throws Exception {
View Full Code Here

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

        assertEquals(6, q.getFirstRow().intValue());
    }

    public void testWhereIn() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE foo IN ('a','b',5)");
        assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.foo IN ('a' , 'b' , '5')", q.toSql());

        FilterItem whereItem = q.getWhereClause().getItem(0);
        assertEquals(OperatorType.IN, whereItem.getOperator());
        Object operand = whereItem.getOperand();
        assertTrue(operand instanceof List);
View Full Code Here

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

        assertEquals(5, ((List<?>) operand).get(2));
    }

    public void testSimpleSubQuery() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT f.foo AS fo FROM (SELECT * FROM sch.tbl) f");
        assertEquals("SELECT f.foo AS fo FROM (SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl) f", q.toSql());
    }
   
    public void testSelectEverythingFromSubQuery() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM (SELECT foo, bar FROM sch.tbl) f");
        assertEquals("SELECT f.foo, f.bar FROM (SELECT tbl.foo, tbl.bar FROM sch.tbl) f", q.toSql());
View Full Code Here

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

        assertEquals("SELECT f.foo AS fo FROM (SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl) f", q.toSql());
    }
   
    public void testSelectEverythingFromSubQuery() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM (SELECT foo, bar FROM sch.tbl) f");
        assertEquals("SELECT f.foo, f.bar FROM (SELECT tbl.foo, tbl.bar FROM sch.tbl) f", q.toSql());
    }

    public void testGetIndicesVanillaScenario() throws Exception {
        QueryParser qp = new QueryParser(dc, "SELECT ... FROM ... BAR BAZ");
        assertEquals("[0, 7]", Arrays.toString(qp.indexesOf("SELECT ", null)));
View Full Code Here

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

        Query q = MetaModelHelper.parseQuery(dc,
                "SELECT foo, COUNT(* ), MAX( baz ) FROM sch.tbl WHERE bar = 'baz' AND foo = bar AND baz > 5 "
                        + "GROUP BY foo HAVING COUNT(*) > 2 ORDER BY foo LIMIT 20 OFFSET 10");
        assertEquals(
                "SELECT tbl.foo, COUNT(*), MAX(tbl.baz) FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.foo = tbl.bar AND tbl.baz > 5 "
                        + "GROUP BY tbl.foo HAVING COUNT(*) > 2 ORDER BY tbl.foo ASC", q.toSql());
        assertEquals(20, q.getMaxRows().intValue());
        assertEquals(11, q.getFirstRow().intValue());

        // SELECT ...
        // tbl.foo
View Full Code Here

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

    public void testMultipleTables() throws Exception {
        Query q = dc.query().from(table1).as("t1").and(table2).as("t2").select(col1).where(col1).greaterThan(col2)
                .orderBy(col2).desc().toQuery();
        assertEquals("SELECT t1.foo FROM sch.tab1 t1, sch.tab2 t2 " + "WHERE t1.foo > t1.bar ORDER BY t1.bar DESC",
                q.toSql());
    }
}
View Full Code Here

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

        assertEquals("Column[name=mycol1,columnNumber=0,type=INTEGER,nullable=false,nativeType=int,columnSize=16]",
                columns[0].toString());
        assertEquals("Column[name=mycol1,columnNumber=1,type=VARCHAR,nullable=true,nativeType=text,columnSize=255]",
                columns[1].toString());

        assertEquals("SELECT mytable.\"mycol1\" FROM myschema.mytable WHERE mytable.mycol1 = 'foo'", q.toSql());
    }
}
View Full Code Here

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

        MockDataContext dc = new MockDataContext("sch", "tab", "1");
        Table table = dc.getDefaultSchema().getTables()[0];
        Column[] columns = table.getColumns();

        Query query = dc.query().from(table).select(FunctionType.MAX, columns[0]).and(columns[1]).toQuery();
        assertEquals("SELECT MAX(tab.foo), tab.bar FROM sch.tab", query.toSql());

        DataSet ds = dc.executeQuery(query);
        assertTrue(ds.next());
        assertEquals("Row[values=[4, hello]]", ds.getRow().toString());
        assertTrue(ds.next());
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.