Fixed #967 -- 'tables' parameter in DB API is now only quoted if needed. Thanks, Russell Keith-Magee

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1581 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-12-09 03:08:51 +00:00
parent a8b3d67b7a
commit 5fe45cb0f8
2 changed files with 9 additions and 6 deletions

View File

@ -56,6 +56,7 @@ answer newbie questions, and generally made Django that much better:
Robert Rock Howard <http://djangomojo.com/> Robert Rock Howard <http://djangomojo.com/>
Jason Huggins <http://www.jrandolph.com/blog/> Jason Huggins <http://www.jrandolph.com/blog/>
Michael Josephson <http://www.sdjournal.com/> Michael Josephson <http://www.sdjournal.com/>
Russell Keith-Magee <freakboy@iinet.net.au>
Garth Kidd <http://www.deadlybloodyserious.com/> Garth Kidd <http://www.deadlybloodyserious.com/>
Sune Kirkeby <http://ibofobi.dk/> Sune Kirkeby <http://ibofobi.dk/>
lakin.wecker@gmail.com lakin.wecker@gmail.com

View File

@ -1584,9 +1584,16 @@ def _parse_lookup(kwarg_items, opts, table_count=0):
return tables, join_where, where, params, table_count return tables, join_where, where, params, table_count
def function_get_sql_clause(opts, **kwargs): def function_get_sql_clause(opts, **kwargs):
def quote_only_if_word(word):
if ' ' in word:
return word
else:
return db.db.quote_name(word)
# Construct the fundamental parts of the query: SELECT X FROM Y WHERE Z.
select = ["%s.%s" % (db.db.quote_name(opts.db_table), db.db.quote_name(f.column)) for f in opts.fields] select = ["%s.%s" % (db.db.quote_name(opts.db_table), db.db.quote_name(f.column)) for f in opts.fields]
tables = [opts.db_table] + (kwargs.get('tables') and kwargs['tables'][:] or []) tables = [opts.db_table] + (kwargs.get('tables') and kwargs['tables'][:] or [])
tables = [db.db.quote_name(t) for t in tables] tables = [quote_only_if_word(t) for t in tables]
where = kwargs.get('where') and kwargs['where'][:] or [] where = kwargs.get('where') and kwargs['where'][:] or []
params = kwargs.get('params') and kwargs['params'][:] or [] params = kwargs.get('params') and kwargs['params'][:] or []
@ -1604,11 +1611,6 @@ def function_get_sql_clause(opts, **kwargs):
_fill_table_cache(opts, select, tables, where, opts.db_table, [opts.db_table]) _fill_table_cache(opts, select, tables, where, opts.db_table, [opts.db_table])
# Add any additional SELECTs passed in via kwargs. # Add any additional SELECTs passed in via kwargs.
def quote_only_if_word(word):
if word.find(' ')>=0:
return word
else:
return db.db.quote_name(word)
if kwargs.get('select'): if kwargs.get('select'):
select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), db.db.quote_name(s[0])) for s in kwargs['select']]) select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), db.db.quote_name(s[0])) for s in kwargs['select']])