From 5a6426448f9813ef9abe17d59eb99e278f9461ee Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 19 Aug 2007 23:13:06 +0000 Subject: [PATCH] Refactored get_fulltext_search_sql() to DatabaseOperations.fulltext_search_sql(). Refs #5106 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5957 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/__init__.py | 8 ++++++++ django/db/backends/ado_mssql/base.py | 3 --- django/db/backends/dummy/base.py | 1 - django/db/backends/mysql/base.py | 6 +++--- django/db/backends/mysql_old/base.py | 6 +++--- django/db/backends/oracle/base.py | 3 --- django/db/backends/postgresql/base.py | 3 --- django/db/backends/postgresql_psycopg2/base.py | 3 --- django/db/backends/sqlite3/base.py | 3 --- django/db/models/query.py | 2 +- 10 files changed, 15 insertions(+), 23 deletions(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index f740bef3bb..8113f6f877 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -91,3 +91,11 @@ class BaseDatabaseOperations(object): Returns the SQL command that drops a foreign key. """ return "DROP CONSTRAINT" + + def fulltext_search_sql(self, field_name): + """ + Returns the SQL WHERE clause to use in order to perform a full-text + search of the given field_name. Note that the resulting string should + contain a '%s' placeholder for the value being searched against. + """ + raise NotImplementedError('Full-text search is not implemented for this database backend') diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py index 56dd944dcd..6c9b50bd4b 100644 --- a/django/db/backends/ado_mssql/base.py +++ b/django/db/backends/ado_mssql/base.py @@ -110,9 +110,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "RAND()" -def get_fulltext_search_sql(field_name): - raise NotImplementedError - def get_pk_default_value(): return "DEFAULT" diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py index e9488540d6..9e49840f9e 100644 --- a/django/db/backends/dummy/base.py +++ b/django/db/backends/dummy/base.py @@ -46,7 +46,6 @@ dictfetchall = complain get_last_insert_id = complain get_limit_offset_sql = complain get_random_function_sql = complain -get_fulltext_search_sql = complain get_pk_default_value = complain get_max_name_length = ignore get_start_transaction_sql = complain diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 642d8d4272..900b995c1b 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -74,6 +74,9 @@ class DatabaseOperations(BaseDatabaseOperations): def drop_foreignkey_sql(self): return "DROP FOREIGN KEY" + def fulltext_search_sql(self, field_name): + return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name + class DatabaseWrapper(BaseDatabaseWrapper): ops = DatabaseOperations() @@ -164,9 +167,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "RAND()" -def get_fulltext_search_sql(field_name): - return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name - def get_pk_default_value(): return "DEFAULT" diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index 558475e02f..519670ad74 100644 --- a/django/db/backends/mysql_old/base.py +++ b/django/db/backends/mysql_old/base.py @@ -84,6 +84,9 @@ class DatabaseOperations(BaseDatabaseOperations): def drop_foreignkey_sql(self): return "DROP FOREIGN KEY" + def fulltext_search_sql(self, field_name): + return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name + class DatabaseWrapper(BaseDatabaseWrapper): ops = DatabaseOperations() @@ -183,9 +186,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "RAND()" -def get_fulltext_search_sql(field_name): - return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name - def get_pk_default_value(): return "DEFAULT" diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 318e0cf03e..28b798fa2d 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -186,9 +186,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "DBMS_RANDOM.RANDOM" -def get_fulltext_search_sql(field_name): - raise NotImplementedError - def get_pk_default_value(): return "DEFAULT" diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index b51501f570..cb83200776 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -140,9 +140,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "RANDOM()" -def get_fulltext_search_sql(field_name): - raise NotImplementedError - def get_pk_default_value(): return "DEFAULT" diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index e7bf84d4f4..d60210b772 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -94,9 +94,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "RANDOM()" -def get_fulltext_search_sql(field_name): - raise NotImplementedError - def get_pk_default_value(): return "DEFAULT" diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 75b5f55077..51ef11d346 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -127,9 +127,6 @@ def get_limit_offset_sql(limit, offset=None): def get_random_function_sql(): return "RANDOM()" -def get_fulltext_search_sql(field_name): - raise NotImplementedError - def get_pk_default_value(): return "NULL" diff --git a/django/db/models/query.py b/django/db/models/query.py index ec56a6ce1a..faf469f1bf 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -810,7 +810,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type): elif lookup_type == 'isnull': return "%s IS %sNULL" % (field_sql, (not value and 'NOT ' or '')) elif lookup_type == 'search': - return backend.get_fulltext_search_sql(field_sql) + return connection.ops.fulltext_search_sql(field_sql) elif lookup_type in ('regex', 'iregex'): if settings.DATABASE_ENGINE == 'oracle': if lookup_type == 'regex':