Ticket #967: safe_quoted_tables.diff
File safe_quoted_tables.diff, 1.6 KB (added by , 19 years ago) |
---|
-
django/core/meta/__init__.py
1580 1580 return tables, join_where, where, params, table_count 1581 1581 1582 1582 def function_get_sql_clause(opts, **kwargs): 1583 def quote_only_if_word(word): 1584 """ 1585 Helper function used to protect user-provided names that might be 1586 subselects in their own right 1587 """ 1588 if word.find(' ')>=0: 1589 return word 1590 else: 1591 return db.db.quote_name(word) 1592 1593 # Construct the fundamental parts of the query: SELECT X FROM Y WHERE Z 1583 1594 select = ["%s.%s" % (db.db.quote_name(opts.db_table), db.db.quote_name(f.column)) for f in opts.fields] 1584 1595 tables = [opts.db_table] + (kwargs.get('tables') and kwargs['tables'][:] or []) 1585 tables = [ db.db.quote_name(t) for t in tables]1596 tables = [quote_only_if_word(t) for t in tables] 1586 1597 where = kwargs.get('where') and kwargs['where'][:] or [] 1587 1598 params = kwargs.get('params') and kwargs['params'][:] or [] 1588 1599 … … 1600 1611 _fill_table_cache(opts, select, tables, where, opts.db_table, [opts.db_table]) 1601 1612 1602 1613 # Add any additional SELECTs passed in via kwargs. 1603 def quote_only_if_word(word):1604 if word.find(' ')>=0:1605 return word1606 else:1607 return db.db.quote_name(word)1608 1614 if kwargs.get('select'): 1609 1615 select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), db.db.quote_name(s[0])) for s in kwargs['select']]) 1610 1616