(sql, standard_quoting = False)
Parse multi-statement string into separate statements.

    Returns list of statements.

    >>> [sql for sql in parse_statements("begin; select 1; select 'foo'; end;")]
    ['begin;', 'select 1;', "select 'foo';", 'end;']
Parse multi-statement string into separate statements.
Parse multi - statement string into separate statements .
def parse_statements(sql, standard_quoting = False):
    """Parse multi-statement string into separate statements.

    Returns list of statements.

    >>> [sql for sql in parse_statements("begin; select 1; select 'foo'; end;")]
    ['begin;', 'select 1;', "select 'foo';", 'end;']
    """

    global _copy_from_stdin_rc
    if not _copy_from_stdin_rc:
        _copy_from_stdin_rc = re.compile(_copy_from_stdin_re, re.X | re.I)
    tokens = []
    pcount = 0 # '(' level
    for typ, t in sql_tokenizer(sql, standard_quoting = standard_quoting):
        # skip whitespace and comments before statement
        if len(tokens) == 0 and typ == "ws":
            continue
        # keep the rest
        tokens.append(t)
        if t == "(":
            pcount += 1
        elif t == ")":
            pcount -= 1
        elif t == ";" and pcount == 0:
            sql = "".join(tokens)
            if _copy_from_stdin_rc.match(sql):
                raise Exception("copy from stdin not supported")
            yield ("".join(tokens))
            tokens = []
    if len(tokens) > 0:
        yield ("".join(tokens))
    if pcount != 0:
        raise Exception("syntax error - unbalanced parenthesis")
def parse_statements ( sql , standard_quoting = False ) : global _copy_from_stdin_rc if not _copy_from_stdin_rc : _copy_from_stdin_rc = re . compile ( _copy_from_stdin_re , re . X | re . I ) tokens = [ ] pcount = 0 # '(' level for typ , t in sql_tokenizer ( sql , standard_quoting = standard_quoting ) : # skip whitespace and comments before statement if len ( tokens ) == 0 and typ == "ws" : continue # keep the rest tokens . append ( t ) if t == "(" : pcount += 1 elif t == ")" : pcount -= 1 elif t == ";" and pcount == 0 : sql = "" . join ( tokens ) if _copy_from_stdin_rc . match ( sql ) : raise Exception ( "copy from stdin not supported" ) yield ( "" . join ( tokens ) ) tokens = [ ] if len ( tokens ) > 0 : yield ( "" . join ( tokens ) ) if pcount != 0 : raise Exception ( "syntax error - unbalanced parenthesis" )