mirror of https://github.com/django/django.git
Moved db.quote_name from a model-level function to a method of DatabaseWrapper for all database backends, so quote_name will be accessible in a 'from django.core.db import db' context
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1213 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
29bdbc3dbf
commit
3273c981f8
|
@ -36,7 +36,6 @@ get_limit_offset_sql = dbmod.get_limit_offset_sql
|
||||||
get_random_function_sql = dbmod.get_random_function_sql
|
get_random_function_sql = dbmod.get_random_function_sql
|
||||||
get_table_list = dbmod.get_table_list
|
get_table_list = dbmod.get_table_list
|
||||||
get_relations = dbmod.get_relations
|
get_relations = dbmod.get_relations
|
||||||
quote_name = dbmod.quote_name
|
|
||||||
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
|
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
|
||||||
DATA_TYPES = dbmod.DATA_TYPES
|
DATA_TYPES = dbmod.DATA_TYPES
|
||||||
DATA_TYPES_REVERSE = dbmod.DATA_TYPES_REVERSE
|
DATA_TYPES_REVERSE = dbmod.DATA_TYPES_REVERSE
|
||||||
|
|
|
@ -77,6 +77,11 @@ class DatabaseWrapper:
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
|
def quote_name(self, name):
|
||||||
|
if name.startswith('[') and name.endswith(']'):
|
||||||
|
return name # Quoting once is enough.
|
||||||
|
return '[%s]' % name
|
||||||
|
|
||||||
def get_last_insert_id(cursor, table_name, pk_name):
|
def get_last_insert_id(cursor, table_name, pk_name):
|
||||||
cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name))
|
cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name))
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
@ -110,11 +115,6 @@ def get_table_list(cursor):
|
||||||
def get_relations(cursor, table_name):
|
def get_relations(cursor, table_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def quote_name(name):
|
|
||||||
if name.startswith('[') and name.endswith(']'):
|
|
||||||
return name # Quoting once is enough.
|
|
||||||
return '[%s]' % name
|
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
OPERATOR_MAPPING = {
|
||||||
'exact': '=',
|
'exact': '=',
|
||||||
'iexact': 'LIKE',
|
'iexact': 'LIKE',
|
||||||
|
|
|
@ -84,6 +84,11 @@ class DatabaseWrapper:
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
|
def quote_name(self, name):
|
||||||
|
if name.startswith("`") and name.endswith("`"):
|
||||||
|
return name # Quoting once is enough.
|
||||||
|
return "`%s`" % name
|
||||||
|
|
||||||
def get_last_insert_id(cursor, table_name, pk_name):
|
def get_last_insert_id(cursor, table_name, pk_name):
|
||||||
cursor.execute("SELECT LAST_INSERT_ID()")
|
cursor.execute("SELECT LAST_INSERT_ID()")
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
@ -122,11 +127,6 @@ def get_table_list(cursor):
|
||||||
def get_relations(cursor, table_name):
|
def get_relations(cursor, table_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def quote_name(name):
|
|
||||||
if name.startswith("`") and name.endswith("`"):
|
|
||||||
return name # Quoting once is enough.
|
|
||||||
return "`%s`" % name
|
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
OPERATOR_MAPPING = {
|
||||||
'exact': '=',
|
'exact': '=',
|
||||||
'iexact': 'LIKE',
|
'iexact': 'LIKE',
|
||||||
|
|
|
@ -49,6 +49,11 @@ class DatabaseWrapper:
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
|
def quote_name(self, name):
|
||||||
|
if name.startswith('"') and name.endswith('"'):
|
||||||
|
return name # Quoting once is enough.
|
||||||
|
return '"%s"' % name
|
||||||
|
|
||||||
def dictfetchone(cursor):
|
def dictfetchone(cursor):
|
||||||
"Returns a row from the cursor as a dict"
|
"Returns a row from the cursor as a dict"
|
||||||
return cursor.dictfetchone()
|
return cursor.dictfetchone()
|
||||||
|
@ -116,11 +121,6 @@ def get_relations(cursor, table_name):
|
||||||
continue
|
continue
|
||||||
return relations
|
return relations
|
||||||
|
|
||||||
def quote_name(name):
|
|
||||||
if name.startswith('"') and name.endswith('"'):
|
|
||||||
return name # Quoting once is enough.
|
|
||||||
return '"%s"' % name
|
|
||||||
|
|
||||||
# Register these custom typecasts, because Django expects dates/times to be
|
# Register these custom typecasts, because Django expects dates/times to be
|
||||||
# in Python's native (standard-library) datetime/time format, whereas psycopg
|
# in Python's native (standard-library) datetime/time format, whereas psycopg
|
||||||
# use mx.DateTime by default.
|
# use mx.DateTime by default.
|
||||||
|
|
|
@ -55,6 +55,11 @@ class DatabaseWrapper:
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
|
def quote_name(self, name):
|
||||||
|
if name.startswith('"') and name.endswith('"'):
|
||||||
|
return name # Quoting once is enough.
|
||||||
|
return '"%s"' % name
|
||||||
|
|
||||||
class SQLiteCursorWrapper(Database.Cursor):
|
class SQLiteCursorWrapper(Database.Cursor):
|
||||||
"""
|
"""
|
||||||
Django uses "format" style placeholders, but pysqlite2 uses "qmark" style.
|
Django uses "format" style placeholders, but pysqlite2 uses "qmark" style.
|
||||||
|
@ -124,11 +129,6 @@ def get_table_list(cursor):
|
||||||
def get_relations(cursor, table_name):
|
def get_relations(cursor, table_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def quote_name(name):
|
|
||||||
if name.startswith('"') and name.endswith('"'):
|
|
||||||
return name # Quoting once is enough.
|
|
||||||
return '"%s"' % name
|
|
||||||
|
|
||||||
# Operators and fields ########################################################
|
# Operators and fields ########################################################
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
OPERATOR_MAPPING = {
|
||||||
|
|
Loading…
Reference in New Issue