def execute_select(self, server, cursor, params): # self.params --- (distinct flag, table columns, from, where, extra where, # group by, having, ordering, limits) if len(self.params[2]) == 1: return self.execute_simple_select(server, cursor, params) else: leftmost_table_name = self.params[2][0] lookups = [] for x in self.params[2][1:]: left, right = x.split('ON') left = left.split() right = right[2:-1].split() if left[0] == 'INNER': if len(left) == 4: # in case of alias table_name = left[2] alias = left[3] else: table_name = left[2] alias = unquote_name(left[2]) table = server[unquote_name(table_name)] view = self.simple_select(server, table, (table_name + '.' + '"id"', ), self.params[3], params, alias=alias) ids = (d.id for d in view) # table_alias, name, db_type, lookup_type, value_annot, params l = Lookup(leftmost_table_name, unquote_name(right[0].split('.')[1]), None, 'in', None, ids) lookups.append(l.as_sql()) lookup_str = ' AND '.join(lookups) table = server[unquote_name(leftmost_table_name)] if len(self.params[1]) == 1 and self.params[1][0] == 'COUNT(*)': joined_view = self.simple_select( server, table, (leftmost_table_name + '.' + '"id"', ), lookup_str, params) cursor.save_one(len(joined_view)) else: joined_view = self.simple_select(server, table, self.params[1], lookup_str, params) cursor.save_view(joined_view)
def execute_select(self, server, cursor, params): # self.params --- (distinct flag, table columns, from, where, extra where, # group by, having, ordering, limits) if len(self.params[2]) == 1: return self.execute_simple_select(server,cursor,params) else: leftmost_table_name = self.params[2][0] lookups = [] for x in self.params[2][1:]: left, right = x.split('ON') left = left.split() right = right[2:-1].split() if left[0] == 'INNER': if len(left) == 4: # in case of alias table_name = left[2] alias = left[3] else: table_name = left[2] alias = unquote_name(left[2]) table = server[unquote_name(table_name)] view = self.simple_select(server, table, (table_name+'.'+'"id"',), self.params[3], params, alias=alias) ids = (d.id for d in view) # table_alias, name, db_type, lookup_type, value_annot, params l = Lookup(leftmost_table_name, unquote_name(right[0].split('.')[1]), None, 'in', None, ids) lookups.append(l.as_sql()) lookup_str = ' AND '.join(lookups) table = server[unquote_name(leftmost_table_name)] if len(self.params[1])==1 and self.params[1][0]=='COUNT(*)': joined_view = self.simple_select(server, table, (leftmost_table_name+'.'+'"id"',), lookup_str, params) cursor.save_one(len(joined_view)) else: joined_view = self.simple_select(server, table, self.params[1], lookup_str, params) cursor.save_view(joined_view)
def make_atom(self, child, qn): #~ table_alias, name, db_type, lookup_type, value_annot, params = child lookup = Lookup(*child) return lookup.as_sql(), []
def make_atom(self, child, qn): # ~ table_alias, name, db_type, lookup_type, value_annot, params = child lookup = Lookup(*child) return lookup.as_sql(), []