Search in sources :

Example 1 with OrderByFilter

use of com.developmentontheedge.sql.format.OrderByFilter in project be5 by DevelopmentOnTheEdge.

the class OrderByFilterTest method testOrderByFilterUnion.

@Test
public void testOrderByFilterUnion() {
    AstStart start = SqlQuery.parse("SELECT name FROM bbc WHERE name LIKE 'Z%' UNION SELECT name FROM actor WHERE name LIKE 'Z%'");
    Map<String, String> columns = Collections.singletonMap("name", "DESC");
    new OrderByFilter().apply(start, columns);
    assertEquals("SELECT * FROM (SELECT name FROM bbc WHERE name LIKE 'Z%' UNION SELECT name FROM actor WHERE name LIKE 'Z%') " + "tmp ORDER BY 1 DESC", new Formatter().format(start, new Context(Dbms.MYSQL), new DefaultParserContext()));
}
Also used : Context(com.developmentontheedge.sql.format.Context) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) AstStart(com.developmentontheedge.sql.model.AstStart) Formatter(com.developmentontheedge.sql.format.Formatter) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) OrderByFilter(com.developmentontheedge.sql.format.OrderByFilter) Test(org.junit.Test)

Example 2 with OrderByFilter

use of com.developmentontheedge.sql.format.OrderByFilter in project be5 by DevelopmentOnTheEdge.

the class OrderByFilterTest method testOrderByFilter.

@Test
public void testOrderByFilter() {
    AstStart start = SqlQuery.parse("SELECT t.a, t.b, t.c AS foo FROM myTable t WHERE t.b > 2");
    Map<String, String> columns = new HashMap<String, String>();
    columns.put("t.a", "ASC");
    columns.put("foo", "DESC");
    new OrderByFilter().apply(start, columns);
    assertEquals("SELECT t.a, t.b, t.c AS foo FROM myTable t WHERE t.b > 2 ORDER BY 1 ASC, 3 DESC", new Formatter().format(start, new Context(Dbms.MYSQL), new DefaultParserContext()));
}
Also used : Context(com.developmentontheedge.sql.format.Context) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) AstStart(com.developmentontheedge.sql.model.AstStart) HashMap(java.util.HashMap) Formatter(com.developmentontheedge.sql.format.Formatter) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) OrderByFilter(com.developmentontheedge.sql.format.OrderByFilter) Test(org.junit.Test)

Aggregations

Context (com.developmentontheedge.sql.format.Context)2 Formatter (com.developmentontheedge.sql.format.Formatter)2 OrderByFilter (com.developmentontheedge.sql.format.OrderByFilter)2 AstStart (com.developmentontheedge.sql.model.AstStart)2 DefaultParserContext (com.developmentontheedge.sql.model.DefaultParserContext)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1