#NEWLINE# def execute_sql( self , result_type = MULTI ) : #NEWLINE# #INDENT# "\n        Run the query against the database and returns the result(s). The\n        return value is a single data item if result_type is SINGLE, or an\n        iterator over the results if the result_type is MULTI.\n\n        result_type is either MULTI (use fetchmany() to retrieve all rows),\n        SINGLE (only retrieve a single row), or None. In this last case, the\n        cursor is returned if any query is executed, since it's used by\n        subclasses such as InsertQuery). It's possible, however, that no query\n        is needed, as the filters describe an empty set. In that case, None is\n        returned, to avoid any unnecessary database interaction.\n        " #NEWLINE# try : #NEWLINE# #INDENT# ( sql , params ) = self . as_sql ( ) #NEWLINE# if ( not sql ) : #NEWLINE# #INDENT# raise EmptyResultSet #NEWLINE# #UNINDENT# #UNINDENT# except EmptyResultSet : #NEWLINE# #INDENT# if ( result_type == MULTI ) : #NEWLINE# #INDENT# return empty_iter ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# cursor = self . connection . cursor ( ) #NEWLINE# cursor . execute ( sql , params ) #NEWLINE# if ( not result_type ) : #NEWLINE# #INDENT# return cursor #NEWLINE# #UNINDENT# if ( result_type == SINGLE ) : #NEWLINE# #INDENT# if self . query . ordering_aliases : #NEWLINE# #INDENT# return cursor . fetchone ( ) [ : ( - len ( self . query . ordering_aliases ) ) ] #NEWLINE# #UNINDENT# return cursor . fetchone ( ) #NEWLINE# #UNINDENT# if self . query . ordering_aliases : #NEWLINE# #INDENT# result = order_modified_iter ( cursor , len ( self . query . ordering_aliases ) , self . connection . features . empty_fetchmany_value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = iter ( ( lambda : cursor . fetchmany ( GET_ITERATOR_CHUNK_SIZE ) ) , self . connection . features . empty_fetchmany_value ) #NEWLINE# #UNINDENT# if ( not self . connection . features . can_use_chunked_reads ) : #NEWLINE# #INDENT# return list ( result ) #NEWLINE# #UNINDENT# return result