Github user Ben-Zvi commented on a diff in the pull request:

    https://github.com/apache/drill/pull/860#discussion_r127357111
  
    --- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java ---
    @@ -231,4 +236,120 @@ public void setControls(String controls) {
       public RowSetBuilder rowSetBuilder(BatchSchema schema) {
         return new RowSetBuilder(allocator(), schema);
       }
    +
    +  /**
    +   * Very simple parser for semi-colon separated lists of SQL statements 
which
    +   * handles quoted semicolons. Drill can execute only one statement at a 
time
    +   * (without a trailing semi-colon.) This parser breaks up a statement 
list
    +   * into single statements. Input:<code><pre>
    +   * USE a.b;
    +   * ALTER SESSION SET `foo` = ";";
    +   * SELECT * FROM bar WHERE x = "\";";
    +   * </pre><code>Output:
    +   * <ul>
    +   * <li><tt>USE a.b</tt></li>
    +   * <li><tt>ALTER SESSION SET `foo` = ";"</tt></li>
    +   * <li><tt>SELECT * FROM bar WHERE x = "\";"</tt></li>
    +   */
    +
    +  public static class StatementParser {
    +    private final Reader in;
    +    private StringBuilder buf;
    +
    +    public StatementParser(Reader in) {
    +      this.in = in;
    +    }
    +
    +    public String parseNext() throws IOException {
    +      boolean eof = false;
    +      buf = new StringBuilder();
    +      outer:
    +      for (;;) {
    +        int c = in.read();
    +        if (c == -1) {
    +          eof = true;
    +          break;
    +        }
    +        if (c == ';') {
    +          break;
    +        }
    +        buf.append((char) c);
    +        if (c == '"' || c == '\'' || c == '`') {
    +          int quote = c;
    +          boolean escape = false;
    +          for (;;) {
    +            c = in.read();
    +            if (c == -1) {
    +              break outer;
    --- End diff --
    
    Note: This code would return a truncated SQL Statement (non matched quote), 
as appears in the input.
    Option: Throw some user exception here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to