use of com.developmentontheedge.sql.model.AstStart in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method number.
@Test
public void number() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE totalSize = <parameter:totalSize />");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("totalSize", "123").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE totalSize = 123", start.getQuery().toString());
}
use of com.developmentontheedge.sql.model.AstStart in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method string.
@Test
public void string() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = '<parameter:name />'");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "test").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE name = 'test'", start.getQuery().toString());
}
use of com.developmentontheedge.sql.model.AstStart in project be5 by DevelopmentOnTheEdge.
the class FilterApplierTest method testAddFilterApplierUnion.
@Test
public void testAddFilterApplierUnion() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
AstStart query = SqlQuery.parse("SELECT name FROM bbc b WHERE name LIKE 'Z%' UNION SELECT name FROM actor WHERE name LIKE 'Z%'");
Map<ColumnRef, Object> conditions = Collections.singletonMap(ColumnRef.resolve(query, "bbc.data"), new java.sql.Date(format.parse("01-01-1900").getTime()));
new FilterApplier().addFilter(query, conditions);
assertEquals("SELECT * FROM (SELECT name FROM bbc b WHERE name LIKE 'Z%' UNION SELECT name FROM actor WHERE name LIKE 'Z%') tmp WHERE b.data ='1900-01-01'", new Formatter().format(query, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
}
use of com.developmentontheedge.sql.model.AstStart in project be5 by DevelopmentOnTheEdge.
the class FilterApplierTest method testAddFilterApplier.
@Test
public void testAddFilterApplier() {
AstStart query = SqlQuery.parse("SELECT * FROM games, city WHERE games.city = city.name AND city.country = 'UK'");
Map<ColumnRef, Object> conditions = Collections.singletonMap(ColumnRef.resolve(query, "games.yr"), 2012);
new FilterApplier().addFilter(query, conditions);
assertEquals("SELECT * FROM games, city WHERE games.city = city.name AND city.country = 'UK' AND games.yr = 2012", new Formatter().format(query, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
query = SqlQuery.parse("SELECT * FROM games RIGHT JOIN city ON (games.city = city.name) WHERE city.country ='UK'");
new FilterApplier().addFilter(query, conditions);
assertEquals("SELECT * FROM games RIGHT JOIN city ON (games.city = city.name) WHERE city.country ='UK' AND games.yr = 2012", new Formatter().format(query, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
query = SqlQuery.parse("SELECT * FROM games RIGHT JOIN city ON (games.city = city.name) WHERE city.country ='UK' OR city.active = 'yes'");
new FilterApplier().addFilter(query, conditions);
assertEquals("SELECT * FROM games RIGHT JOIN city ON (games.city = city.name) WHERE ( city.country ='UK' OR city.active = 'yes') AND games.yr = 2012", new Formatter().format(query, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
query = SqlQuery.parse("SELECT * FROM games, city ORDER BY 1");
new FilterApplier().addFilter(query, conditions);
assertEquals("SELECT * FROM games, city WHERE games.yr = 2012 ORDER BY 1", new Formatter().format(query, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
}
use of com.developmentontheedge.sql.model.AstStart 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()));
}
Aggregations