예제 #1
0
 def _get_alias_mapping(self):
     from openerp.osv.expression import get_alias_from_query
     mapping = {}
     for table in self.tables:
         alias, statement = get_alias_from_query(table)
         mapping[statement] = table
     return mapping
예제 #2
0
파일: query.py 프로젝트: Antiun/odoo
 def _get_alias_mapping(self):
     from openerp.osv.expression import get_alias_from_query
     mapping = {}
     for table in self.tables:
         alias, statement = get_alias_from_query(table)
         mapping[statement] = table
     return mapping
예제 #3
0
파일: query.py 프로젝트: Antiun/odoo
    def get_sql(self):
        """ Returns (query_from, query_where, query_params). """
        from openerp.osv.expression import get_alias_from_query
        tables_to_process = list(self.tables)
        alias_mapping = self._get_alias_mapping()
        from_clause = []
        from_params = []

        def add_joins_for_table(lhs):
            for (rhs, lhs_col, rhs_col, join) in self.joins.get(lhs, []):
                tables_to_process.remove(alias_mapping[rhs])
                from_clause.append(' %s %s ON ("%s"."%s" = "%s"."%s"' % \
                    (join, alias_mapping[rhs], lhs, lhs_col, rhs, rhs_col))
                extra = self.extras.get((lhs, (rhs, lhs_col, rhs_col, join)))
                if extra:
                    from_clause.append(' AND ')
                    from_clause.append(extra[0])
                    from_params.extend(extra[1])
                from_clause.append(')')
                add_joins_for_table(rhs)

        for pos, table in enumerate(tables_to_process):
            if pos > 0:
                from_clause.append(',')
            from_clause.append(table)
            table_alias = get_alias_from_query(table)[1]
            if table_alias in self.joins:
                add_joins_for_table(table_alias)

        return "".join(from_clause), " AND ".join(self.where_clause), from_params + self.where_clause_params
예제 #4
0
    def get_sql(self):
        """ Returns (query_from, query_where, query_params). """
        from openerp.osv.expression import get_alias_from_query
        tables_to_process = list(self.tables)
        alias_mapping = self._get_alias_mapping()
        from_clause = []
        from_params = []

        def add_joins_for_table(lhs):
            for (rhs, lhs_col, rhs_col, join) in self.joins.get(lhs, []):
                tables_to_process.remove(alias_mapping[rhs])
                from_clause.append(' %s %s ON ("%s"."%s" = "%s"."%s"' % \
                    (join, alias_mapping[rhs], lhs, lhs_col, rhs, rhs_col))
                extra = self.extras.get((lhs, (rhs, lhs_col, rhs_col, join)))
                if extra:
                    from_clause.append(' AND ')
                    from_clause.append(extra[0])
                    from_params.extend(extra[1])
                from_clause.append(')')
                add_joins_for_table(rhs)

        for pos, table in enumerate(tables_to_process):
            if pos > 0:
                from_clause.append(',')
            from_clause.append(table)
            table_alias = get_alias_from_query(table)[1]
            if table_alias in self.joins:
                add_joins_for_table(table_alias)

        return "".join(from_clause), " AND ".join(
            self.where_clause), from_params + self.where_clause_params
예제 #5
0
    def get_sql(self):
        """ Returns (query_from, query_where, query_params). """
        from openerp.osv.expression import get_alias_from_query
        query_from = ''
        tables_to_process = list(self.tables)
        alias_mapping = self._get_alias_mapping()

        def add_joins_for_table(table, query_from):
            for (dest_table, lhs_col, col, join) in self.joins.get(table, []):
                tables_to_process.remove(alias_mapping[dest_table])
                query_from += ' %s %s ON ("%s"."%s" = "%s"."%s")' % \
                    (join, alias_mapping[dest_table], table, lhs_col, dest_table, col)
                query_from = add_joins_for_table(dest_table, query_from)
            return query_from

        for table in tables_to_process:
            query_from += table
            table_alias = get_alias_from_query(table)[1]
            if table_alias in self.joins:
                query_from = add_joins_for_table(table_alias, query_from)
            query_from += ','
        query_from = query_from[:-1]  # drop last comma
        return (query_from, " AND ".join(self.where_clause), self.where_clause_params)
예제 #6
0
    def get_sql(self):
        """ Returns (query_from, query_where, query_params). """
        from openerp.osv.expression import get_alias_from_query
        query_from = ''
        tables_to_process = list(self.tables)
        alias_mapping = self._get_alias_mapping()

        def add_joins_for_table(table, query_from):
            for (dest_table, lhs_col, col, join) in self.joins.get(table, []):
                tables_to_process.remove(alias_mapping[dest_table])
                query_from += ' %s %s ON ("%s"."%s" = "%s"."%s")' % \
                    (join, alias_mapping[dest_table], table, lhs_col, dest_table, col)
                query_from = add_joins_for_table(dest_table, query_from)
            return query_from

        for table in tables_to_process:
            query_from += table
            table_alias = get_alias_from_query(table)[1]
            if table_alias in self.joins:
                query_from = add_joins_for_table(table_alias, query_from)
            query_from += ','
        query_from = query_from[:-1]  # drop last comma
        return query_from, " AND ".join(self.where_clause), self.where_clause_params
예제 #7
0
 def _get_table_aliases(self):
     from openerp.osv.expression import get_alias_from_query
     return [
         get_alias_from_query(from_statement)[1]
         for from_statement in self.tables
     ]
예제 #8
0
파일: query.py 프로젝트: Antiun/odoo
 def _get_table_aliases(self):
     from openerp.osv.expression import get_alias_from_query
     return [get_alias_from_query(from_statement)[1] for from_statement in self.tables]