Skip to content

Commit

Permalink
Fixed and tested some scenarios where the malformed SQL is inputed
Browse files Browse the repository at this point in the history
  • Loading branch information
luan-cestari committed Feb 4, 2015
1 parent 78c93a2 commit f9cc5bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private int findColon(int start, StringBuffer query) {
}

// get parameter
if (c == ':' && (query.charAt(i + 1) != '=')) {
if (c == ':' && query.length() > i+1 && (query.charAt(i + 1) != '=') && (query.charAt(i + 1) != ' ')) {
return i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public void testSQLGeneration() throws Exception {
assertFalse(nps.processedQuery.contains(":parameter"));
}

//malformed SQL
{
connection = new MyConnection();
connection.myPreparedStatement = new MyPreparedStatement();
nps = new SQLConverter(connection,"select:");
assertEquals("select:", nps.processedQuery);
assertFalse(nps.processedQuery.contains(":parameter"));
}
{
connection = new MyConnection();
connection.myPreparedStatement = new MyPreparedStatement();
nps = new SQLConverter(connection,"select : "); // '=' and ' ' are ignored, so it will not convert to '?'
assertEquals("select : ", nps.processedQuery);
assertFalse(nps.processedQuery.contains(":parameter"));
}

}

Expand Down

0 comments on commit f9cc5bc

Please sign in to comment.