From 3273c981f8d370ce6ccc6cbd8a20fea4f9d64de0 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 13 Nov 2005 05:11:41 +0000 Subject: [PATCH] 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 --- django/core/db/__init__.py | 1 - django/core/db/backends/ado_mssql.py | 10 +++++----- django/core/db/backends/mysql.py | 10 +++++----- django/core/db/backends/postgresql.py | 10 +++++----- django/core/db/backends/sqlite3.py | 10 +++++----- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/django/core/db/__init__.py b/django/core/db/__init__.py index 6636d4f176..f0ffeebc2e 100644 --- a/django/core/db/__init__.py +++ b/django/core/db/__init__.py @@ -36,7 +36,6 @@ get_limit_offset_sql = dbmod.get_limit_offset_sql get_random_function_sql = dbmod.get_random_function_sql get_table_list = dbmod.get_table_list get_relations = dbmod.get_relations -quote_name = dbmod.quote_name OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING DATA_TYPES = dbmod.DATA_TYPES DATA_TYPES_REVERSE = dbmod.DATA_TYPES_REVERSE diff --git a/django/core/db/backends/ado_mssql.py b/django/core/db/backends/ado_mssql.py index 480de3b074..d4f2a359c5 100644 --- a/django/core/db/backends/ado_mssql.py +++ b/django/core/db/backends/ado_mssql.py @@ -77,6 +77,11 @@ class DatabaseWrapper: self.connection.close() 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): cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name)) return cursor.fetchone()[0] @@ -110,11 +115,6 @@ def get_table_list(cursor): def get_relations(cursor, table_name): raise NotImplementedError -def quote_name(name): - if name.startswith('[') and name.endswith(']'): - return name # Quoting once is enough. - return '[%s]' % name - OPERATOR_MAPPING = { 'exact': '=', 'iexact': 'LIKE', diff --git a/django/core/db/backends/mysql.py b/django/core/db/backends/mysql.py index e7ede84a12..dd94948b96 100644 --- a/django/core/db/backends/mysql.py +++ b/django/core/db/backends/mysql.py @@ -84,6 +84,11 @@ class DatabaseWrapper: self.connection.close() 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): cursor.execute("SELECT LAST_INSERT_ID()") return cursor.fetchone()[0] @@ -122,11 +127,6 @@ def get_table_list(cursor): def get_relations(cursor, table_name): raise NotImplementedError -def quote_name(name): - if name.startswith("`") and name.endswith("`"): - return name # Quoting once is enough. - return "`%s`" % name - OPERATOR_MAPPING = { 'exact': '=', 'iexact': 'LIKE', diff --git a/django/core/db/backends/postgresql.py b/django/core/db/backends/postgresql.py index a1de11e3df..b6d34fc814 100644 --- a/django/core/db/backends/postgresql.py +++ b/django/core/db/backends/postgresql.py @@ -49,6 +49,11 @@ class DatabaseWrapper: self.connection.close() 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): "Returns a row from the cursor as a dict" return cursor.dictfetchone() @@ -116,11 +121,6 @@ def get_relations(cursor, table_name): continue 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 # in Python's native (standard-library) datetime/time format, whereas psycopg # use mx.DateTime by default. diff --git a/django/core/db/backends/sqlite3.py b/django/core/db/backends/sqlite3.py index 3fde8c77e1..60ffd37620 100644 --- a/django/core/db/backends/sqlite3.py +++ b/django/core/db/backends/sqlite3.py @@ -55,6 +55,11 @@ class DatabaseWrapper: self.connection.close() 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): """ 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): raise NotImplementedError -def quote_name(name): - if name.startswith('"') and name.endswith('"'): - return name # Quoting once is enough. - return '"%s"' % name - # Operators and fields ######################################################## OPERATOR_MAPPING = {