#NEWLINE# def literalquery( statement , dialect = None ) : #NEWLINE# #INDENT# 'Generate an SQL expression string with bound parameters rendered inline\n    for the given SQLAlchemy statement.\n\n    WARNING: This method of escaping is insecure, incomplete, and for debugging\n    purposes only. Executing SQL statements with inline-rendered user values is\n    extremely insecure.\n    ' #NEWLINE# if isinstance ( statement , sqlalchemy . orm . Query ) : #NEWLINE# #INDENT# if ( dialect is None ) : #NEWLINE# #INDENT# dialect = statement . session . get_bind ( statement . _mapper_zero_or_none ( ) ) . dialect #NEWLINE# #UNINDENT# statement = statement . statement #NEWLINE# #UNINDENT# if ( dialect is None ) : #NEWLINE# #INDENT# dialect = getattr ( statement . bind , 'dialect' , None ) #NEWLINE# #UNINDENT# if ( dialect is None ) : #NEWLINE# #INDENT# from sqlalchemy.dialects import mysql #NEWLINE# dialect = mysql . dialect ( ) #NEWLINE# #UNINDENT# Compiler = type ( statement . _compiler ( dialect ) ) #NEWLINE# class LiteralCompiler ( Compiler ) : #NEWLINE# #INDENT# visit_bindparam = Compiler . render_literal_bindparam #NEWLINE# def render_literal_value( self , value , type_ ) : #NEWLINE# #INDENT# if isinstance ( value , ( Decimal , long ) ) : #NEWLINE# #INDENT# return str ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , datetime ) : #NEWLINE# #INDENT# return repr ( str ( value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = super ( LiteralCompiler , self ) . render_literal_value ( value , type_ ) #NEWLINE# if isinstance ( value , unicode ) : #NEWLINE# #INDENT# return value . encode ( 'UTF-8' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return LiteralCompiler ( dialect , statement )