use of org.simpleflatmapper.jdbc.named.NamedSqlQuery in project SimpleFlatMapper by arnaudroger.
the class NamedSqlQueryTest method testParseComplexSql.
@Test
public void testParseComplexSql() {
String sql = "SELECT a, b, c FROM table " + "where " + "a in (?, :futon) " + "and b=lower(?) " + "and c = :c " + "and upper(lower(d)) = ? " + "and upper(lower(e)) = upper(lower(?)) " + "and lower(f) = upper(lower(?))";
NamedSqlQuery namedSqlQuery = NamedSqlQuery.parse(sql);
assertEquals(7, namedSqlQuery.getParametersSize());
assertEquals("a", namedSqlQuery.getParameter(0).getName());
assertEquals("futon", namedSqlQuery.getParameter(1).getName());
assertEquals("b", namedSqlQuery.getParameter(2).getName());
assertEquals("c", namedSqlQuery.getParameter(3).getName());
assertEquals("d", namedSqlQuery.getParameter(4).getName());
assertEquals("e", namedSqlQuery.getParameter(5).getName());
assertEquals("f", namedSqlQuery.getParameter(6).getName());
assertEquals("SELECT a, b, c FROM table " + "where a in (?, ?) " + "and b=lower(?) " + "and c = ? " + "and upper(lower(d)) = ? " + "and upper(lower(e)) = upper(lower(?)) " + "and lower(f) = upper(lower(?))", namedSqlQuery.toSqlQuery());
}
use of org.simpleflatmapper.jdbc.named.NamedSqlQuery in project SimpleFlatMapper by arnaudroger.
the class MappingSqlQuery method extractParameters.
private SqlParameter[] extractParameters(String sql) {
NamedSqlQuery query = NamedSqlQuery.parse(sql);
SqlParameter[] params = new SqlParameter[query.getParametersSize()];
for (int i = 0; i < params.length; i++) {
NamedParameter namedParameter = query.getParameter(i);
params[i] = new SqlParameter(namedParameter.getName(), 0);
}
return params;
}
Aggregations