#NEWLINE# def get_from_clause( self ) : #NEWLINE# #INDENT# '\n        Returns a list of strings that are joined together to go after the\n        "FROM" part of the query, as well as a list any extra parameters that\n        need to be included. Sub-classes, can override this to create a\n        from-clause via a "select".\n\n        This should only be called after any SQL construction methods that\n        might change the tables we need. This means the select columns and\n        ordering must be done first.\n        ' #NEWLINE# result = [ ] #NEWLINE# qn = self . quote_name_unless_alias #NEWLINE# qn2 = self . connection . ops . quote_name #NEWLINE# index_map = self . query . index_map #NEWLINE# first = True #NEWLINE# from_params = [ ] #NEWLINE# for alias in self . query . tables : #NEWLINE# #INDENT# if ( not self . query . alias_refcount [ alias ] ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( name , alias , join_type , lhs , join_cols , _ , join_field ) = self . query . alias_map [ alias ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# alias_str = ( ( ( alias != name ) and ( ' %s' % alias ) ) or '' ) #NEWLINE# if ( name in index_map ) : #NEWLINE# #INDENT# use_index = ( 'USE INDEX (%s)' % qn ( index_map [ name ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# use_index = '' #NEWLINE# #UNINDENT# if ( join_type and ( not first ) ) : #NEWLINE# #INDENT# extra_cond = join_field . get_extra_restriction ( self . query . where_class , alias , lhs ) #NEWLINE# if extra_cond : #NEWLINE# #INDENT# ( extra_sql , extra_params ) = extra_cond . as_sql ( qn , self . connection ) #NEWLINE# extra_sql = ( 'AND (%s)' % extra_sql ) #NEWLINE# from_params . extend ( extra_params ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# extra_sql = '' #NEWLINE# #UNINDENT# result . append ( ( '%s %s%s %s ON (' % ( join_type , qn ( name ) , alias_str , use_index ) ) ) #NEWLINE# for ( index , ( lhs_col , rhs_col ) ) in enumerate ( join_cols ) : #NEWLINE# #INDENT# if ( index != 0 ) : #NEWLINE# #INDENT# result . append ( ' AND ' ) #NEWLINE# #UNINDENT# result . append ( ( '%s.%s = %s.%s' % ( qn ( lhs ) , qn2 ( lhs_col ) , qn ( alias ) , qn2 ( rhs_col ) ) ) ) #NEWLINE# #UNINDENT# result . append ( ( '%s)' % extra_sql ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# connector = connector = ( '' if first else ', ' ) #NEWLINE# result . append ( ( '%s%s%s %s' % ( connector , qn ( name ) , alias_str , use_index ) ) ) #NEWLINE# #UNINDENT# first = False #NEWLINE# #UNINDENT# for t in self . query . extra_tables : #NEWLINE# #INDENT# ( alias , unused ) = self . query . table_alias ( t ) #NEWLINE# if ( ( alias not in self . query . alias_map ) or ( self . query . alias_refcount [ alias ] == 1 ) ) : #NEWLINE# #INDENT# connector = ( ( ( not first ) and ', ' ) or '' ) #NEWLINE# result . append ( ( '%s%s' % ( connector , qn ( alias ) ) ) ) #NEWLINE# first = False #NEWLINE# #UNINDENT# #UNINDENT# return ( result , from_params )