code: def rawsql(query, ec=None):
      
      if isinstance(query, Result):
          query = query.get_query()
  
      ec = ec or __default_engine__
      if isinstance(ec, (str, unicode)):
          engine = engine_manager[ec]
          dialect = engine.engine.dialect
      else:
          dialect = ec.dialect
      if isinstance(query, (str, unicode)):
          return query
      # comp = query.compile(dialect=dialect)
  
      compiler = query._compiler(dialect)
      class LiteralCompiler(compiler.__class__):
          def visit_bindparam(
                  self, bindparam, within_columns_clause=False,
                  literal_binds=False, **kwargs
          ):
              return super(LiteralCompiler, self).render_literal_bindparam(
                      bindparam, within_columns_clause=within_columns_clause,
                      literal_binds=literal_binds, **kwargs
              )
          def render_literal_value(self, value, type_):
              """Render the value of a bind parameter as a quoted literal.
  
              This is used for statement sections that do not accept bind paramters
              on the target driver/database.
  
              This should be implemented by subclasses using the quoting services
              of the DBAPI.
  
              """
              return repr_value(value)
  
      compiler = LiteralCompiler(dialect, query)
      return str(compiler.process(query)).replace('\n', '')
docs: ec could be engine name or engine instance