Skip to content

Commit

Permalink
"double semicolon" as escape
Browse files Browse the repository at this point in the history
"double semicolon" used to escape a semicolon and avoid splitting
  • Loading branch information
sbeigel committed Jan 12, 2016
1 parent 8a05d9f commit bc8797f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions framework/src/play/db/SQLSplitter.java
Expand Up @@ -193,14 +193,19 @@ public CharSequence next() {
while ( i < sql.length() ) {
if ( sql.charAt(i) == ';' ) {
++i;
CharSequence ret = sql.subSequence(prev, i);
prev = i;
return ret;
// check "double semicolon" -> used to escape a semicolon and avoid splitting
if ((i < sql.length() && sql.charAt(i) == ';')) {
++i;
} else {
CharSequence ret = sql.subSequence(prev, i).toString().replace(";;", ";");
prev = i;
return ret;
}
}
i = nextChar(sql, i);
}
if ( prev != i ) {
CharSequence ret = sql.subSequence(prev, i);
CharSequence ret = sql.subSequence(prev, i).toString().replace(";;", ";");
prev = i;
return ret;
}
Expand Down
6 changes: 6 additions & 0 deletions framework/test-src/play/db/SQLSplitterTest.java
Expand Up @@ -88,6 +88,12 @@ public void verifyTrailingParenthesis() {
assertEquals(3, SQLSplitter.consumeParentheses("(()", 0));
}

@Test
public void verifyDoubleSemicolonHandling() {
assertEquals(2, SQLSplitter.splitSQL("a;\nb;;\nc;").size());
assertEquals(3, SQLSplitter.splitSQL("a;\nb;\nc;").size());
}

String readFile(final String filename) throws Exception {
final File src = new File(getClass().getResource(filename).toURI());
final byte [] srcbytes = new byte[(int)src.length()];
Expand Down

0 comments on commit bc8797f

Please sign in to comment.