def parse(sql): try: parse_result = SQLParser.parseString(sql, parseAll=True) except Exception as e: if isinstance(e, ParseException) and e.msg == "Expected end of text": problems = all_exceptions.get(e.loc, []) expecting = [ f for f in (set(p.msg.lstrip("Expected").strip() for p in problems)-{"Found unwanted token"}) if not f.startswith("{") ] raise ParseException(sql, e.loc, "Expecting one of (" + (", ".join(expecting)) + ")") raise return _scrub(parse_result)
def parse(sql): try: parse_result = SQLParser.parseString(sql, parseAll=True) except Exception as e: if isinstance(e, ParseException) and e.msg == "Expected end of text": problems = all_exceptions.get(e.loc, []) expecting = [ f for f in ( set(p.msg.lstrip("Expected").strip() for p in problems) - {"Found unwanted token"}) if not f.startswith("{") ] raise ParseException( sql, e.loc, "Expecting one of (" + (", ".join(expecting)) + ")") raise return _scrub(parse_result)
def parse(sql): with parseLocker: try: all_exceptions.clear() sql = sql.rstrip().rstrip(";") parse_result = SQLParser.parseString(sql, parseAll=True) return scrub(parse_result) except Exception as cause: if (isinstance(cause, ParseException) and cause.msg == "Expected end of text"): problems = all_exceptions.get(cause.loc, []) expecting = [ f for f in (set( p.msg.lstrip("Expected").strip() for p in problems) - {"Found unwanted token"}) if not f.startswith("{") ] raise ParseException( sql, cause.loc, "Expecting one of (" + ", ".join(expecting) + ")", cause=cause, ) raise
def parse(sql): with parseLocker: # Handle cases like queries of ('McDonald's | Food Folk ') to {'literal': "McDonald's | Food Folk "} sql = sql.rstrip().rstrip(";") parse_result = SQLParser.parseString(sql, parseAll=True) return scrub(parse_result)
def parse(sql): parse_result = SQLParser.parseString(sql, parseAll=True) return _scrub(parse_result)
def parse(sql): with parseLocker: sql = sql.rstrip().rstrip(";") parse_result = SQLParser.parseString(sql, parseAll=True) return scrub(parse_result)
def parse(sql): return _scrub(SQLParser.parseString(sql))