Skip to content

Commit

Permalink
#3 Added unit test for {call ...} syntax. Fixed jdbc param formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejboy authored and ejboy committed Nov 4, 2014
1 parent 2c1c0e4 commit 04dcdcf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/java/scriptella/jdbc/SqlParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void handleStatement(final String sql,
* @return substituion string.
*/
protected String handleParameter(final String name, final boolean expression, final boolean jdbcParam) {
return expression ? ((jdbcParam ? "?{" : "${") + name + '}') : ((jdbcParam ? "?{" : "$") + name);
return expression ? ((jdbcParam ? "?{" : "${") + name + '}') : ((jdbcParam ? "?" : "$") + name);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/scriptella/jdbc/SQLParserBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,28 @@ protected void statementParsed(String parsedSql) {

}

public void testCallableStatement() {
final String sql = "{call procName(?arg1, ?out_arg2, ?inout_arg3, 'value')}";

SqlParserBase p = new SqlParserBase() {
String[] paramNames = {"arg1", "out_arg2", "inout_arg3"};
int paramNumber;
@Override
protected String handleParameter(final String name, final boolean expression, boolean jdbcParam) {
assertEquals(paramNames[paramNumber], name);
assertFalse(expression);
assertTrue(jdbcParam);
paramNumber++;
String s = super.handleParameter(name, expression, jdbcParam);
return s;
}

@Override
protected void statementParsed(String parsedSql) {
assertEquals(sql, parsedSql);
}
};
p.parse(new StringReader(sql));
}

}

0 comments on commit 04dcdcf

Please sign in to comment.