def format(sql, encoding=None, **options): """Format *sql* according to *options*. Available options are documented in :ref:`formatting`. In addition to the formatting options this function accepts the keyword "encoding" which determines the encoding of the statement. :returns: The formatted SQL statement as string. """ stack = engine.FilterStack() options = formatter.validate_options(options) stack = formatter.build_filter_stack(stack, options) stack.postprocess.append(filters.SerializerUnicode()) return ''.join(stack.run(sql, encoding))
def format_sql(statement, prefix_length=0): width, height = getTerminalSize() stack = engine.FilterStack() stack.enable_grouping() stack.stmtprocess.append(filters.StripWhitespaceFilter()) stack.stmtprocess.append(MyReindentFilter(width - 30)) stack.postprocess.append(filters.SerializerUnicode()) statement = ''.join(stack.run(statement)) lines = statement.split('\n') new_lines = [lines[0]] for line in lines[1:]: new_lines.append(' ' * prefix_length + line) statement = '\n'.join(new_lines) return statement
def format(sql, **options): """Format *sql* according to *options*. Available options are documented in :ref:`formatting`. In addition to the formatting options this function accepts the keyword "encoding" which determines the encoding of the statement. :returns: The formatted SQL statement as string. """ options = formatter.validate_options(options) encoding = options.pop('encoding', None) stream = lexer.tokenize(sql, encoding) stream = _format_pre_process(stream, options) stack = engine.FilterStack() stack = formatter.build_filter_stack(stack, options) stack.postprocess.append(filters.SerializerUnicode()) statements = split2(stream) return ''.join(stack.run(statement) for statement in statements)
def parse(query): stack = engine.FilterStack() stack.preprocess.append(ValueFilter()) stack.postprocess.append(filters.SerializerUnicode()) return ''.join(stack.run(query))