2013-02-10 23:15:49 +08:00
|
|
|
import datetime
|
2013-02-18 18:37:26 +08:00
|
|
|
import time
|
2013-02-10 23:15:49 +08:00
|
|
|
|
2011-02-12 21:02:42 +08:00
|
|
|
try:
|
2012-08-18 16:56:56 +08:00
|
|
|
from django.utils.six.moves import _thread as thread
|
2011-02-12 21:02:42 +08:00
|
|
|
except ImportError:
|
2012-07-20 22:16:57 +08:00
|
|
|
from django.utils.six.moves import _dummy_thread as thread
|
2013-01-13 04:10:08 +08:00
|
|
|
from collections import namedtuple
|
2011-08-07 08:43:26 +08:00
|
|
|
from contextlib import contextmanager
|
2013-07-29 21:50:58 +08:00
|
|
|
from importlib import import_module
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2011-01-12 21:39:31 +08:00
|
|
|
from django.conf import settings
|
2014-01-20 10:45:21 +08:00
|
|
|
from django.core import checks
|
2009-12-22 23:18:51 +08:00
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
2013-02-19 00:12:42 +08:00
|
|
|
from django.db.backends.signals import connection_created
|
2013-09-17 00:52:05 +08:00
|
|
|
from django.db.backends import utils
|
2011-02-12 21:02:42 +08:00
|
|
|
from django.db.transaction import TransactionManagementError
|
2013-10-15 22:36:31 +08:00
|
|
|
from django.db.utils import DatabaseError, DatabaseErrorWrapper, ProgrammingError
|
2012-06-09 21:59:52 +08:00
|
|
|
from django.utils.functional import cached_property
|
2012-07-20 20:48:51 +08:00
|
|
|
from django.utils import six
|
2013-02-10 23:15:49 +08:00
|
|
|
from django.utils import timezone
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2011-01-12 21:39:31 +08:00
|
|
|
|
2011-12-16 21:40:19 +08:00
|
|
|
class BaseDatabaseWrapper(object):
|
2007-08-20 06:29:57 +08:00
|
|
|
"""
|
|
|
|
Represents a database connection.
|
|
|
|
"""
|
|
|
|
ops = None
|
2010-12-04 02:15:54 +08:00
|
|
|
vendor = 'unknown'
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2011-12-16 21:40:19 +08:00
|
|
|
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS,
|
|
|
|
allow_thread_sharing=False):
|
2014-03-21 21:21:43 +08:00
|
|
|
# Connection related attributes.
|
|
|
|
self.connection = None
|
|
|
|
self.queries = []
|
2009-03-11 11:39:34 +08:00
|
|
|
# `settings_dict` should be a dictionary containing keys such as
|
2009-12-22 23:18:51 +08:00
|
|
|
# NAME, USER, etc. It's called `settings_dict` instead of `settings`
|
|
|
|
# to disambiguate it from Django settings modules.
|
2009-03-11 11:39:34 +08:00
|
|
|
self.settings_dict = settings_dict
|
2009-12-22 23:18:51 +08:00
|
|
|
self.alias = alias
|
2010-10-12 11:33:19 +08:00
|
|
|
self.use_debug_cursor = None
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2014-03-21 21:21:43 +08:00
|
|
|
# Transaction related attributes.
|
|
|
|
# Tracks if the connection is in autocommit mode. Per PEP 249, by
|
|
|
|
# default, it isn't.
|
2013-03-02 20:47:46 +08:00
|
|
|
self.autocommit = False
|
2013-03-13 21:08:32 +08:00
|
|
|
# Tracks if the connection is in a transaction managed by 'atomic'.
|
2013-03-05 05:17:35 +08:00
|
|
|
self.in_atomic_block = False
|
2014-03-21 21:21:43 +08:00
|
|
|
# Increment to generate unique savepoint ids.
|
|
|
|
self.savepoint_state = 0
|
|
|
|
# List of savepoints created by 'atomic'.
|
2013-03-13 21:54:44 +08:00
|
|
|
self.savepoint_ids = []
|
2013-03-13 21:08:32 +08:00
|
|
|
# Tracks if the outermost 'atomic' block should commit on exit,
|
|
|
|
# ie. if autocommit was active on entry.
|
|
|
|
self.commit_on_exit = True
|
2013-03-08 22:44:41 +08:00
|
|
|
# Tracks if the transaction should be rolled back to the next
|
|
|
|
# available savepoint because of an exception in an inner block.
|
|
|
|
self.needs_rollback = False
|
2011-01-17 17:52:47 +08:00
|
|
|
|
2014-03-21 21:21:43 +08:00
|
|
|
# Connection termination related attributes.
|
2013-02-18 18:37:26 +08:00
|
|
|
self.close_at = None
|
|
|
|
self.errors_occurred = False
|
|
|
|
|
2014-03-21 21:21:43 +08:00
|
|
|
# Thread-safety related attributes.
|
2011-12-16 21:40:19 +08:00
|
|
|
self.allow_thread_sharing = allow_thread_sharing
|
2013-03-02 19:12:51 +08:00
|
|
|
self._thread_ident = thread.get_ident()
|
2011-01-17 17:52:47 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def __eq__(self, other):
|
2013-07-08 07:35:08 +08:00
|
|
|
if isinstance(other, BaseDatabaseWrapper):
|
|
|
|
return self.alias == other.alias
|
|
|
|
return NotImplemented
|
2009-12-22 23:18:51 +08:00
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self == other
|
2007-08-20 05:30:57 +08:00
|
|
|
|
2013-02-26 05:53:08 +08:00
|
|
|
def __hash__(self):
|
|
|
|
return hash(self.alias)
|
2012-08-18 17:02:38 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Backend-specific methods for creating connections and cursors #####
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
|
2013-02-19 02:31:10 +08:00
|
|
|
def get_connection_params(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Returns a dict of parameters suitable for get_new_connection."""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a get_connection_params() method')
|
2013-02-19 02:31:10 +08:00
|
|
|
|
|
|
|
def get_new_connection(self, conn_params):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Opens a connection to the database."""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a get_new_connection() method')
|
2013-02-19 02:31:10 +08:00
|
|
|
|
|
|
|
def init_connection_state(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Initializes the database connection settings."""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require an init_connection_state() method')
|
2013-02-19 02:31:10 +08:00
|
|
|
|
|
|
|
def create_cursor(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Creates a cursor. Assumes that a connection is established."""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a create_cursor() method')
|
2013-02-19 02:31:10 +08:00
|
|
|
|
2013-03-03 22:43:24 +08:00
|
|
|
##### Backend-specific methods for creating connections #####
|
|
|
|
|
|
|
|
def connect(self):
|
|
|
|
"""Connects to the database. Assumes that the connection is closed."""
|
2013-03-13 21:54:44 +08:00
|
|
|
# In case the previous connection was closed while in an atomic block
|
|
|
|
self.in_atomic_block = False
|
|
|
|
self.savepoint_ids = []
|
2013-03-03 22:43:24 +08:00
|
|
|
# Reset parameters defining when to close the connection
|
|
|
|
max_age = self.settings_dict['CONN_MAX_AGE']
|
|
|
|
self.close_at = None if max_age is None else time.time() + max_age
|
|
|
|
self.errors_occurred = False
|
|
|
|
# Establish the connection
|
|
|
|
conn_params = self.get_connection_params()
|
|
|
|
self.connection = self.get_new_connection(conn_params)
|
2014-01-13 03:27:08 +08:00
|
|
|
self.set_autocommit(self.settings_dict['AUTOCOMMIT'])
|
2013-03-03 22:43:24 +08:00
|
|
|
self.init_connection_state()
|
|
|
|
connection_created.send(sender=self.__class__, connection=self)
|
|
|
|
|
|
|
|
def ensure_connection(self):
|
|
|
|
"""
|
|
|
|
Guarantees that a connection to the database is established.
|
|
|
|
"""
|
|
|
|
if self.connection is None:
|
2013-09-15 15:12:16 +08:00
|
|
|
with self.wrap_database_errors:
|
2013-03-03 22:43:24 +08:00
|
|
|
self.connect()
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Backend-specific wrappers for PEP-249 connection methods #####
|
|
|
|
|
2013-02-19 00:12:42 +08:00
|
|
|
def _cursor(self):
|
2013-03-03 22:43:24 +08:00
|
|
|
self.ensure_connection()
|
2013-09-15 15:12:16 +08:00
|
|
|
with self.wrap_database_errors:
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
return self.create_cursor()
|
2012-08-18 17:02:38 +08:00
|
|
|
|
2007-08-20 05:30:57 +08:00
|
|
|
def _commit(self):
|
|
|
|
if self.connection is not None:
|
2013-09-15 15:12:16 +08:00
|
|
|
with self.wrap_database_errors:
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
return self.connection.commit()
|
2007-08-20 05:30:57 +08:00
|
|
|
|
|
|
|
def _rollback(self):
|
|
|
|
if self.connection is not None:
|
2013-09-15 15:12:16 +08:00
|
|
|
with self.wrap_database_errors:
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
return self.connection.rollback()
|
2007-08-20 05:30:57 +08:00
|
|
|
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
def _close(self):
|
|
|
|
if self.connection is not None:
|
2013-09-15 15:12:16 +08:00
|
|
|
with self.wrap_database_errors:
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
return self.connection.close()
|
2007-08-20 05:30:57 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Generic wrappers for PEP-249 connection methods #####
|
|
|
|
|
|
|
|
def cursor(self):
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Creates a cursor, opening a connection if necessary.
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
|
|
|
if (self.use_debug_cursor or
|
2013-11-26 17:43:46 +08:00
|
|
|
(self.use_debug_cursor is None and settings.DEBUG)):
|
2013-03-02 19:12:51 +08:00
|
|
|
cursor = self.make_debug_cursor(self._cursor())
|
|
|
|
else:
|
2013-09-17 00:52:05 +08:00
|
|
|
cursor = utils.CursorWrapper(self._cursor(), self)
|
2013-03-02 19:12:51 +08:00
|
|
|
return cursor
|
2009-03-11 15:06:50 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
def commit(self):
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-05 05:17:35 +08:00
|
|
|
Commits a transaction and resets the dirty flag.
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
2013-03-02 19:12:51 +08:00
|
|
|
self._commit()
|
|
|
|
|
|
|
|
def rollback(self):
|
|
|
|
"""
|
2013-03-05 05:17:35 +08:00
|
|
|
Rolls back a transaction and resets the dirty flag.
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
|
|
|
self.validate_thread_sharing()
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
2013-03-02 19:12:51 +08:00
|
|
|
self._rollback()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
"""
|
|
|
|
Closes the connection to the database.
|
|
|
|
"""
|
|
|
|
self.validate_thread_sharing()
|
2013-03-13 21:54:44 +08:00
|
|
|
# Don't call validate_no_atomic_block() to avoid making it difficult
|
|
|
|
# to get rid of a connection in an invalid state. The next connect()
|
|
|
|
# will reset the transaction state anyway.
|
2013-03-02 19:12:51 +08:00
|
|
|
try:
|
|
|
|
self._close()
|
|
|
|
finally:
|
|
|
|
self.connection = None
|
|
|
|
|
|
|
|
##### Backend-specific savepoint management methods #####
|
2009-03-11 15:06:50 +08:00
|
|
|
|
2008-08-12 13:34:56 +08:00
|
|
|
def _savepoint(self, sid):
|
2014-01-09 23:05:15 +08:00
|
|
|
with self.cursor() as cursor:
|
|
|
|
cursor.execute(self.ops.savepoint_create_sql(sid))
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def _savepoint_rollback(self, sid):
|
2014-01-09 23:05:15 +08:00
|
|
|
with self.cursor() as cursor:
|
|
|
|
cursor.execute(self.ops.savepoint_rollback_sql(sid))
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def _savepoint_commit(self, sid):
|
2014-01-09 23:05:15 +08:00
|
|
|
with self.cursor() as cursor:
|
|
|
|
cursor.execute(self.ops.savepoint_commit_sql(sid))
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2013-03-01 17:09:22 +08:00
|
|
|
def _savepoint_allowed(self):
|
|
|
|
# Savepoints cannot be created outside a transaction
|
2013-06-30 21:57:00 +08:00
|
|
|
return self.features.uses_savepoints and not self.get_autocommit()
|
2013-03-01 17:09:22 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Generic savepoint management methods #####
|
|
|
|
|
|
|
|
def savepoint(self):
|
2013-02-06 05:52:29 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
Creates a savepoint inside the current transaction. Returns an
|
|
|
|
identifier for the savepoint that will be used for the subsequent
|
|
|
|
rollback or commit. Does nothing if savepoints are not supported.
|
2013-02-06 05:52:29 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
if not self._savepoint_allowed():
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
thread_ident = thread.get_ident()
|
2013-03-01 17:09:22 +08:00
|
|
|
tid = str(thread_ident).replace('-', '')
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
self.savepoint_state += 1
|
|
|
|
sid = "s%s_x%d" % (tid, self.savepoint_state)
|
2013-03-01 17:09:22 +08:00
|
|
|
|
|
|
|
self.validate_thread_sharing()
|
2013-03-02 19:12:51 +08:00
|
|
|
self._savepoint(sid)
|
2013-03-01 17:09:22 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
return sid
|
|
|
|
|
|
|
|
def savepoint_rollback(self, sid):
|
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
Rolls back to a savepoint. Does nothing if savepoints are not supported.
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
if not self._savepoint_allowed():
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
2013-03-01 17:09:22 +08:00
|
|
|
self._savepoint_rollback(sid)
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
def savepoint_commit(self, sid):
|
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
Releases a savepoint. Does nothing if savepoints are not supported.
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
if not self._savepoint_allowed():
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
2013-03-01 17:09:22 +08:00
|
|
|
self._savepoint_commit(sid)
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
def clean_savepoints(self):
|
|
|
|
"""
|
|
|
|
Resets the counter used to generate unique savepoint ids in this thread.
|
|
|
|
"""
|
|
|
|
self.savepoint_state = 0
|
|
|
|
|
|
|
|
##### Backend-specific transaction management methods #####
|
|
|
|
|
2013-03-02 20:47:46 +08:00
|
|
|
def _set_autocommit(self, autocommit):
|
|
|
|
"""
|
|
|
|
Backend-specific implementation to enable or disable autocommit.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a _set_autocommit() method')
|
2013-03-02 20:47:46 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Generic transaction management methods #####
|
2013-02-06 05:52:29 +08:00
|
|
|
|
2013-06-30 21:57:00 +08:00
|
|
|
def get_autocommit(self):
|
|
|
|
"""
|
|
|
|
Check the autocommit state.
|
|
|
|
"""
|
|
|
|
self.ensure_connection()
|
|
|
|
return self.autocommit
|
|
|
|
|
2013-03-11 22:10:58 +08:00
|
|
|
def set_autocommit(self, autocommit):
|
2011-12-16 21:40:19 +08:00
|
|
|
"""
|
2013-03-02 20:47:46 +08:00
|
|
|
Enable or disable autocommit.
|
|
|
|
"""
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
2013-03-03 22:43:24 +08:00
|
|
|
self.ensure_connection()
|
2013-03-02 20:47:46 +08:00
|
|
|
self._set_autocommit(autocommit)
|
|
|
|
self.autocommit = autocommit
|
|
|
|
|
2013-06-30 21:57:00 +08:00
|
|
|
def get_rollback(self):
|
|
|
|
"""
|
|
|
|
Get the "needs rollback" flag -- for *advanced use* only.
|
|
|
|
"""
|
|
|
|
if not self.in_atomic_block:
|
|
|
|
raise TransactionManagementError(
|
|
|
|
"The rollback flag doesn't work outside of an 'atomic' block.")
|
|
|
|
return self.needs_rollback
|
|
|
|
|
2013-06-28 04:19:54 +08:00
|
|
|
def set_rollback(self, rollback):
|
|
|
|
"""
|
|
|
|
Set or unset the "needs rollback" flag -- for *advanced use* only.
|
|
|
|
"""
|
|
|
|
if not self.in_atomic_block:
|
|
|
|
raise TransactionManagementError(
|
2013-06-30 21:57:00 +08:00
|
|
|
"The rollback flag doesn't work outside of an 'atomic' block.")
|
2013-06-28 04:19:54 +08:00
|
|
|
self.needs_rollback = rollback
|
|
|
|
|
2013-03-05 06:26:31 +08:00
|
|
|
def validate_no_atomic_block(self):
|
|
|
|
"""
|
|
|
|
Raise an error if an atomic block is active.
|
|
|
|
"""
|
|
|
|
if self.in_atomic_block:
|
|
|
|
raise TransactionManagementError(
|
|
|
|
"This is forbidden when an 'atomic' block is active.")
|
|
|
|
|
2013-09-23 04:14:17 +08:00
|
|
|
def validate_no_broken_transaction(self):
|
|
|
|
if self.needs_rollback:
|
|
|
|
raise TransactionManagementError(
|
|
|
|
"An error occurred in the current transaction. You can't "
|
|
|
|
"execute queries until the end of the 'atomic' block.")
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Foreign key constraints checks handling #####
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
@contextmanager
|
|
|
|
def constraint_checks_disabled(self):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Context manager that disables foreign key constraint checking.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2011-08-07 08:43:26 +08:00
|
|
|
disabled = self.disable_constraint_checking()
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
if disabled:
|
|
|
|
self.enable_constraint_checking()
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
def disable_constraint_checking(self):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Backends can implement as needed to temporarily disable foreign key
|
2013-06-10 03:04:36 +08:00
|
|
|
constraint checking. Should return True if the constraints were
|
2013-04-25 01:26:13 +08:00
|
|
|
disabled and will need to be reenabled.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-04-25 01:26:13 +08:00
|
|
|
return False
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
def enable_constraint_checking(self):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Backends can implement as needed to re-enable foreign key constraint
|
|
|
|
checking.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2011-08-07 08:43:26 +08:00
|
|
|
pass
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
def check_constraints(self, table_names=None):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Backends can override this method if they can apply constraint
|
|
|
|
checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE"). Should raise an
|
|
|
|
IntegrityError if any invalid foreign key references are encountered.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2011-08-07 08:43:26 +08:00
|
|
|
pass
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Connection termination handling #####
|
|
|
|
|
|
|
|
def is_usable(self):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Tests if the database connection is usable.
|
|
|
|
This function may assume that self.connection is not None.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require an is_usable() method')
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
def close_if_unusable_or_obsolete(self):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Closes the current connection if unrecoverable errors have occurred,
|
|
|
|
or if it outlived its maximum age.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-02-18 18:37:26 +08:00
|
|
|
if self.connection is not None:
|
2013-03-07 21:47:50 +08:00
|
|
|
# If the application didn't restore the original autocommit setting,
|
|
|
|
# don't take chances, drop the connection.
|
2013-06-30 21:57:00 +08:00
|
|
|
if self.get_autocommit() != self.settings_dict['AUTOCOMMIT']:
|
2013-03-07 21:47:50 +08:00
|
|
|
self.close()
|
|
|
|
return
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
if self.errors_occurred:
|
|
|
|
if self.is_usable():
|
|
|
|
self.errors_occurred = False
|
|
|
|
else:
|
|
|
|
self.close()
|
|
|
|
return
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
if self.close_at is not None and time.time() >= self.close_at:
|
|
|
|
self.close()
|
|
|
|
return
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Thread safety handling #####
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
def validate_thread_sharing(self):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Validates that the connection isn't accessed by another thread than the
|
|
|
|
one which originally created it, unless the connection was explicitly
|
|
|
|
authorized to be shared between threads (via the `allow_thread_sharing`
|
|
|
|
property). Raises an exception if the validation fails.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
if not (self.allow_thread_sharing
|
|
|
|
or self._thread_ident == thread.get_ident()):
|
|
|
|
raise DatabaseError("DatabaseWrapper objects created in a "
|
|
|
|
"thread can only be used in that same thread. The object "
|
|
|
|
"with alias '%s' was created in thread id %s and this is "
|
|
|
|
"thread id %s."
|
|
|
|
% (self.alias, self._thread_ident, thread.get_ident()))
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Miscellaneous #####
|
2011-08-07 08:43:26 +08:00
|
|
|
|
2013-09-15 15:12:16 +08:00
|
|
|
@cached_property
|
2013-03-02 19:12:51 +08:00
|
|
|
def wrap_database_errors(self):
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Context manager and decorator that re-throws backend-specific database
|
|
|
|
exceptions using Django's common wrappers.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
return DatabaseErrorWrapper(self)
|
2011-08-07 08:43:26 +08:00
|
|
|
|
2007-08-20 05:30:57 +08:00
|
|
|
def make_debug_cursor(self, cursor):
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Creates a cursor that logs all queries in self.queries.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2013-09-17 00:52:05 +08:00
|
|
|
return utils.CursorDebugWrapper(cursor, self)
|
2011-08-07 08:43:26 +08:00
|
|
|
|
2013-02-19 17:51:24 +08:00
|
|
|
@contextmanager
|
|
|
|
def temporary_connection(self):
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Context manager that ensures that a connection is established, and
|
|
|
|
if it opened one, closes it to avoid leaving a dangling connection.
|
|
|
|
This is useful for operations outside of the request-response cycle.
|
2011-08-07 08:43:26 +08:00
|
|
|
|
2013-03-12 04:08:49 +08:00
|
|
|
Provides a cursor: with self.temporary_connection() as cursor: ...
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
2013-02-19 17:51:24 +08:00
|
|
|
must_close = self.connection is None
|
|
|
|
cursor = self.cursor()
|
|
|
|
try:
|
2013-03-12 04:08:49 +08:00
|
|
|
yield cursor
|
2013-02-19 17:51:24 +08:00
|
|
|
finally:
|
|
|
|
cursor.close()
|
|
|
|
if must_close:
|
|
|
|
self.close()
|
2007-08-20 05:30:57 +08:00
|
|
|
|
2013-03-05 05:17:35 +08:00
|
|
|
def _start_transaction_under_autocommit(self):
|
|
|
|
"""
|
|
|
|
Only required when autocommits_when_autocommit_is_off = True.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a _start_transaction_under_autocommit() method')
|
2007-08-20 06:29:57 +08:00
|
|
|
|
2013-09-07 04:27:51 +08:00
|
|
|
def schema_editor(self, *args, **kwargs):
|
2012-06-19 00:32:03 +08:00
|
|
|
"Returns a new instance of this backend's SchemaEditor"
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a schema_editor() method')
|
2012-06-19 00:32:03 +08:00
|
|
|
|
|
|
|
|
2007-08-20 10:20:33 +08:00
|
|
|
class BaseDatabaseFeatures(object):
|
2009-01-15 19:06:34 +08:00
|
|
|
allows_group_by_pk = False
|
2008-07-29 13:09:29 +08:00
|
|
|
# True if django.db.backend.utils.typecast_timestamp is used on values
|
|
|
|
# returned from dates() calls.
|
2007-08-20 10:20:33 +08:00
|
|
|
needs_datetime_string_cast = True
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
empty_fetchmany_value = []
|
2008-04-28 19:51:52 +08:00
|
|
|
update_can_self_select = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
|
|
|
# Does the backend distinguish between '' and None?
|
2008-06-16 11:15:04 +08:00
|
|
|
interprets_empty_strings_as_nulls = False
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2011-03-09 06:41:25 +08:00
|
|
|
# Does the backend allow inserting duplicate rows when a unique_together
|
|
|
|
# constraint exists, but one of the unique_together columns is NULL?
|
|
|
|
ignores_nulls_in_unique_constraints = True
|
|
|
|
|
2008-07-16 02:47:32 +08:00
|
|
|
can_use_chunked_reads = True
|
2009-03-11 15:06:50 +08:00
|
|
|
can_return_id_from_insert = False
|
2011-09-10 03:22:28 +08:00
|
|
|
has_bulk_insert = False
|
2008-08-12 13:34:56 +08:00
|
|
|
uses_savepoints = False
|
2011-09-10 03:22:28 +08:00
|
|
|
can_combine_inserts_with_and_without_auto_increment_pk = False
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2008-09-01 08:49:03 +08:00
|
|
|
# If True, don't use integer foreign keys referring to, e.g., positive
|
|
|
|
# integer primary keys.
|
|
|
|
related_fields_match_type = False
|
2010-04-05 01:05:43 +08:00
|
|
|
allow_sliced_subqueries = True
|
2011-04-21 04:42:07 +08:00
|
|
|
has_select_for_update = False
|
|
|
|
has_select_for_update_nowait = False
|
2007-08-20 10:20:33 +08:00
|
|
|
|
2011-12-06 07:11:43 +08:00
|
|
|
supports_select_related = True
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
# Does the default test database allow multiple connections?
|
|
|
|
# Usually an indication that the test database is in-memory
|
|
|
|
test_db_allows_multiple_connections = True
|
|
|
|
|
|
|
|
# Can an object be saved without an explicit primary key?
|
|
|
|
supports_unspecified_pk = False
|
|
|
|
|
|
|
|
# Can a fixture contain forward references? i.e., are
|
|
|
|
# FK constraints checked at the end of transaction, or
|
|
|
|
# at the end of each save operation?
|
|
|
|
supports_forward_references = True
|
|
|
|
|
|
|
|
# Does the backend allow very long model names without error?
|
|
|
|
supports_long_model_names = True
|
|
|
|
|
|
|
|
# Is there a REAL datatype in addition to floats/doubles?
|
|
|
|
has_real_datatype = False
|
|
|
|
supports_subqueries_in_group_by = True
|
|
|
|
supports_bitwise_or = True
|
|
|
|
|
|
|
|
# Do time/datetime fields have microsecond precision?
|
|
|
|
supports_microsecond_precision = True
|
|
|
|
|
|
|
|
# Does the __regex lookup support backreferencing and grouping?
|
|
|
|
supports_regex_backreferencing = True
|
|
|
|
|
|
|
|
# Can date/datetime lookups be performed using a string?
|
|
|
|
supports_date_lookup_using_string = True
|
|
|
|
|
|
|
|
# Can datetimes with timezones be used?
|
|
|
|
supports_timezones = True
|
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
# Does the database have a copy of the zoneinfo database?
|
|
|
|
has_zoneinfo_database = True
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
# When performing a GROUP BY, is an ORDER BY NULL required
|
|
|
|
# to remove any ordering?
|
|
|
|
requires_explicit_null_ordering_when_grouping = False
|
|
|
|
|
2013-08-20 16:33:44 +08:00
|
|
|
# Does the backend order NULL values as largest or smallest?
|
|
|
|
nulls_order_largest = False
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
# Is there a 1000 item limit on query parameters?
|
2010-10-19 08:14:41 +08:00
|
|
|
supports_1000_query_parameters = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2013-11-24 21:12:22 +08:00
|
|
|
# Can an object have an autoincrement primary key of 0? MySQL says No.
|
|
|
|
allows_auto_pk_0 = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2010-11-10 00:46:42 +08:00
|
|
|
# Do we need to NULL a ForeignKey out, or can the constraint check be
|
|
|
|
# deferred
|
|
|
|
can_defer_constraint_checks = False
|
|
|
|
|
2010-12-22 11:34:04 +08:00
|
|
|
# date_interval_sql can properly handle mixed Date/DateTime fields and timedeltas
|
|
|
|
supports_mixed_date_datetime_comparisons = True
|
|
|
|
|
2011-10-15 05:49:43 +08:00
|
|
|
# Does the backend support tablespaces? Default to False because it isn't
|
|
|
|
# in the SQL standard.
|
|
|
|
supports_tablespaces = False
|
|
|
|
|
2012-05-23 04:46:27 +08:00
|
|
|
# Does the backend reset sequences between tests?
|
|
|
|
supports_sequence_reset = True
|
|
|
|
|
2012-06-09 21:59:52 +08:00
|
|
|
# Confirm support for introspected foreign keys
|
|
|
|
# Every database can do this reliably, except MySQL,
|
|
|
|
# which can't do it for MyISAM tables
|
|
|
|
can_introspect_foreign_keys = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2013-09-12 22:03:29 +08:00
|
|
|
# Can the backend introspect an AutoField, instead of an IntegerField?
|
|
|
|
can_introspect_autofield = False
|
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
# Support for the DISTINCT ON clause
|
|
|
|
can_distinct_on_fields = False
|
|
|
|
|
2013-03-05 05:17:35 +08:00
|
|
|
# Does the backend decide to commit before SAVEPOINT statements
|
|
|
|
# when autocommit is disabled? http://bugs.python.org/issue8145#msg109965
|
|
|
|
autocommits_when_autocommit_is_off = False
|
|
|
|
|
2013-09-23 04:14:17 +08:00
|
|
|
# Does the backend prevent running SQL queries in broken transactions?
|
|
|
|
atomic_transactions = True
|
|
|
|
|
2012-06-19 00:32:03 +08:00
|
|
|
# Can we roll back DDL in a transaction?
|
|
|
|
can_rollback_ddl = False
|
|
|
|
|
2012-06-19 20:25:22 +08:00
|
|
|
# Can we issue more than one ALTER COLUMN clause in an ALTER TABLE?
|
|
|
|
supports_combined_alters = False
|
|
|
|
|
2012-09-08 00:51:11 +08:00
|
|
|
# Does it support foreign keys?
|
|
|
|
supports_foreign_keys = True
|
|
|
|
|
2012-09-08 03:40:59 +08:00
|
|
|
# Does it support CHECK constraints?
|
|
|
|
supports_check_constraints = True
|
|
|
|
|
2013-06-28 11:15:03 +08:00
|
|
|
# Does the backend support 'pyformat' style ("... %(name)s ...", {'name': value})
|
|
|
|
# parameter passing? Note this can be provided by the backend even if not
|
|
|
|
# supported by the Python driver
|
|
|
|
supports_paramstyle_pyformat = True
|
|
|
|
|
2014-03-02 22:25:53 +08:00
|
|
|
# Does the backend require literal defaults, rather than parameterized ones?
|
2013-08-23 19:07:55 +08:00
|
|
|
requires_literal_defaults = False
|
|
|
|
|
|
|
|
# Does the backend require a connection reset after each material schema change?
|
|
|
|
connection_persists_old_columns = False
|
|
|
|
|
2013-09-24 08:17:59 +08:00
|
|
|
# What kind of error does the backend throw when accessing closed cursor?
|
|
|
|
closed_cursor_error_class = ProgrammingError
|
|
|
|
|
2014-01-18 17:09:43 +08:00
|
|
|
# Does 'a' LIKE 'A' match?
|
|
|
|
has_case_insensitive_like = True
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2012-06-09 21:59:52 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_transactions(self):
|
2014-03-21 21:21:43 +08:00
|
|
|
"""Confirm support for transactions."""
|
|
|
|
with self.connection.cursor() as cursor:
|
|
|
|
cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
|
|
|
|
self.connection.set_autocommit(False)
|
|
|
|
cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
|
|
|
|
self.connection.rollback()
|
|
|
|
self.connection.set_autocommit(True)
|
|
|
|
cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
|
|
|
|
count, = cursor.fetchone()
|
|
|
|
cursor.execute('DROP TABLE ROLLBACK_TEST')
|
2010-10-11 20:55:17 +08:00
|
|
|
return count == 0
|
|
|
|
|
2012-06-09 21:59:52 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_stddev(self):
|
2014-03-21 21:21:43 +08:00
|
|
|
"""Confirm support for STDDEV and related stats functions."""
|
2010-10-11 20:55:17 +08:00
|
|
|
class StdDevPop(object):
|
|
|
|
sql_function = 'STDDEV_POP'
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.connection.ops.check_aggregate_support(StdDevPop())
|
2012-05-18 18:08:36 +08:00
|
|
|
return True
|
2010-10-28 10:59:22 +08:00
|
|
|
except NotImplementedError:
|
2012-05-18 18:08:36 +08:00
|
|
|
return False
|
2010-10-11 20:55:17 +08:00
|
|
|
|
|
|
|
|
2007-08-20 06:29:57 +08:00
|
|
|
class BaseDatabaseOperations(object):
|
|
|
|
"""
|
|
|
|
This class encapsulates all backend-specific differences, such as the way
|
|
|
|
a backend performs ordering or calculates the ID of a recently-inserted
|
|
|
|
row.
|
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
compiler_module = "django.db.models.sql.compiler"
|
|
|
|
|
2011-04-05 08:19:17 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
2011-01-12 21:39:31 +08:00
|
|
|
self._cache = None
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2007-09-15 02:12:36 +08:00
|
|
|
def autoinc_sql(self, table, column):
|
2007-08-20 06:29:57 +08:00
|
|
|
"""
|
|
|
|
Returns any SQL needed to support auto-incrementing primary keys, or
|
|
|
|
None if no SQL is necessary.
|
|
|
|
|
|
|
|
This SQL is executed when a table is created.
|
|
|
|
"""
|
|
|
|
return None
|
2007-08-20 06:40:06 +08:00
|
|
|
|
2012-04-29 09:22:05 +08:00
|
|
|
def bulk_batch_size(self, fields, objs):
|
|
|
|
"""
|
|
|
|
Returns the maximum allowed batch size for the backend. The fields
|
|
|
|
are the fields going to be inserted in the batch, the objs contains
|
|
|
|
all the objects to be inserted.
|
|
|
|
"""
|
|
|
|
return len(objs)
|
|
|
|
|
2012-07-05 22:20:48 +08:00
|
|
|
def cache_key_culling_sql(self):
|
|
|
|
"""
|
2013-09-06 06:23:48 +08:00
|
|
|
Returns an SQL query that retrieves the first cache key greater than the
|
2012-07-05 22:20:48 +08:00
|
|
|
n smallest.
|
|
|
|
|
|
|
|
This is used by the 'db' cache backend to determine where to start
|
|
|
|
culling.
|
|
|
|
"""
|
|
|
|
return "SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"
|
|
|
|
|
2007-08-20 06:40:06 +08:00
|
|
|
def date_extract_sql(self, lookup_type, field_name):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
|
|
|
|
extracts a value from the given date field field_name.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_extract_sql() method')
|
2007-08-20 06:47:43 +08:00
|
|
|
|
2010-12-22 11:34:04 +08:00
|
|
|
def date_interval_sql(self, sql, connector, timedelta):
|
|
|
|
"""
|
|
|
|
Implements the date interval functionality for expressions
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_interval_sql() method')
|
2010-12-22 11:34:04 +08:00
|
|
|
|
2007-08-20 06:47:43 +08:00
|
|
|
def date_trunc_sql(self, lookup_type, field_name):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
|
2013-02-10 23:15:49 +08:00
|
|
|
truncates the given date field field_name to a date object with only
|
2007-08-20 06:47:43 +08:00
|
|
|
the given specificity.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetrunc_sql() method')
|
2007-08-20 06:55:05 +08:00
|
|
|
|
|
|
|
def datetime_cast_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL necessary to cast a datetime value so that it will be
|
|
|
|
retrieved as a Python datetime object instead of a string.
|
2007-08-20 06:57:08 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
This SQL should include a '%s' in place of the field's name.
|
2007-08-20 06:55:05 +08:00
|
|
|
"""
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return "%s"
|
2007-08-20 07:03:38 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
def datetime_extract_sql(self, lookup_type, field_name, tzname):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
|
|
|
|
'second', returns the SQL that extracts a value from the given
|
|
|
|
datetime field field_name, and a tuple of parameters.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_extract_sql() method')
|
2013-02-10 23:15:49 +08:00
|
|
|
|
|
|
|
def datetime_trunc_sql(self, lookup_type, field_name, tzname):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
|
|
|
|
'second', returns the SQL that truncates the given datetime field
|
|
|
|
field_name to a datetime object with only the given specificity, and
|
|
|
|
a tuple of parameters.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_trunk_sql() method')
|
2013-02-10 23:15:49 +08:00
|
|
|
|
2007-08-20 07:03:38 +08:00
|
|
|
def deferrable_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL necessary to make a constraint "initially deferred"
|
|
|
|
during a CREATE TABLE statement.
|
|
|
|
"""
|
|
|
|
return ''
|
2007-08-20 07:07:34 +08:00
|
|
|
|
2012-04-29 09:22:05 +08:00
|
|
|
def distinct_sql(self, fields):
|
|
|
|
"""
|
|
|
|
Returns an SQL DISTINCT clause which removes duplicate rows from the
|
|
|
|
result set. If any fields are given, only the given fields are being
|
|
|
|
checked for duplicates.
|
|
|
|
"""
|
|
|
|
if fields:
|
|
|
|
raise NotImplementedError('DISTINCT ON fields is not supported by this database backend')
|
|
|
|
else:
|
|
|
|
return 'DISTINCT'
|
|
|
|
|
2007-08-20 07:07:34 +08:00
|
|
|
def drop_foreignkey_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL command that drops a foreign key.
|
|
|
|
"""
|
|
|
|
return "DROP CONSTRAINT"
|
2007-08-20 07:13:06 +08:00
|
|
|
|
2007-08-20 11:08:32 +08:00
|
|
|
def drop_sequence_sql(self, table):
|
|
|
|
"""
|
|
|
|
Returns any SQL necessary to drop the sequence for the given table.
|
|
|
|
Returns None if no SQL is necessary.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2009-03-13 07:41:27 +08:00
|
|
|
def fetch_returned_insert_id(self, cursor):
|
|
|
|
"""
|
|
|
|
Given a cursor object that has just performed an INSERT...RETURNING
|
|
|
|
statement into a table that has an auto-incrementing ID, returns the
|
|
|
|
newly created ID.
|
|
|
|
"""
|
|
|
|
return cursor.fetchone()[0]
|
|
|
|
|
2013-05-19 19:28:09 +08:00
|
|
|
def field_cast_sql(self, db_type, internal_type):
|
2007-08-20 11:03:40 +08:00
|
|
|
"""
|
2013-05-19 19:28:09 +08:00
|
|
|
Given a column type (e.g. 'BLOB', 'VARCHAR'), and an internal type
|
|
|
|
(e.g. 'GenericIPAddressField'), returns the SQL necessary to cast it
|
|
|
|
before using it in a WHERE statement. Note that the resulting string
|
|
|
|
should contain a '%s' placeholder for the column being searched against.
|
2007-08-20 11:03:40 +08:00
|
|
|
"""
|
|
|
|
return '%s'
|
|
|
|
|
2008-12-10 13:19:27 +08:00
|
|
|
def force_no_ordering(self):
|
|
|
|
"""
|
|
|
|
Returns a list used in the "ORDER BY" clause to force no ordering at
|
|
|
|
all. Returning an empty list means that nothing will be included in the
|
|
|
|
ordering.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2011-04-21 04:42:07 +08:00
|
|
|
def for_update_sql(self, nowait=False):
|
|
|
|
"""
|
|
|
|
Returns the FOR UPDATE SQL clause to lock rows for an update operation.
|
|
|
|
"""
|
|
|
|
if nowait:
|
|
|
|
return 'FOR UPDATE NOWAIT'
|
|
|
|
else:
|
|
|
|
return 'FOR UPDATE'
|
|
|
|
|
2007-08-20 07:13:06 +08:00
|
|
|
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')
|
2007-08-20 07:18:43 +08:00
|
|
|
|
2007-10-24 03:00:31 +08:00
|
|
|
def last_executed_query(self, cursor, sql, params):
|
|
|
|
"""
|
|
|
|
Returns a string of the query last executed by the given cursor, with
|
|
|
|
placeholders replaced with actual values.
|
|
|
|
|
|
|
|
`sql` is the raw query containing placeholders, and `params` is the
|
|
|
|
sequence of parameters. These are used by default, but this method
|
|
|
|
exists for database backends to provide a better implementation
|
|
|
|
according to their own quoting schemes.
|
|
|
|
"""
|
2012-08-30 04:40:51 +08:00
|
|
|
from django.utils.encoding import force_text
|
2007-10-24 03:00:31 +08:00
|
|
|
|
|
|
|
# Convert params to contain Unicode values.
|
2012-07-21 16:00:10 +08:00
|
|
|
to_unicode = lambda s: force_text(s, strings_only=True, errors='replace')
|
2007-10-24 03:00:31 +08:00
|
|
|
if isinstance(params, (list, tuple)):
|
2013-01-27 00:51:44 +08:00
|
|
|
u_params = tuple(to_unicode(val) for val in params)
|
2013-03-23 23:09:56 +08:00
|
|
|
elif params is None:
|
|
|
|
u_params = ()
|
2007-10-24 03:00:31 +08:00
|
|
|
else:
|
2013-01-27 00:51:44 +08:00
|
|
|
u_params = dict((to_unicode(k), to_unicode(v)) for k, v in params.items())
|
2007-10-24 03:00:31 +08:00
|
|
|
|
2013-01-27 00:51:44 +08:00
|
|
|
return six.text_type("QUERY = %r - PARAMS = %r") % (sql, u_params)
|
2007-10-24 03:00:31 +08:00
|
|
|
|
2007-08-20 07:18:43 +08:00
|
|
|
def last_insert_id(self, cursor, table_name, pk_name):
|
|
|
|
"""
|
|
|
|
Given a cursor object that has just performed an INSERT statement into
|
|
|
|
a table that has an auto-incrementing ID, returns the newly created ID.
|
|
|
|
|
|
|
|
This method also receives the table name and the name of the primary-key
|
|
|
|
column.
|
|
|
|
"""
|
|
|
|
return cursor.lastrowid
|
2007-08-20 07:24:59 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def lookup_cast(self, lookup_type):
|
|
|
|
"""
|
|
|
|
Returns the string to use in a query when performing lookups
|
|
|
|
("contains", "like", etc). The resulting string should contain a '%s'
|
|
|
|
placeholder for the column being searched against.
|
|
|
|
"""
|
|
|
|
return "%s"
|
|
|
|
|
2010-09-17 03:53:41 +08:00
|
|
|
def max_in_list_size(self):
|
|
|
|
"""
|
|
|
|
Returns the maximum number of items that can be passed in a single 'IN'
|
|
|
|
list condition, or None if the backend does not impose a limit.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2007-08-20 07:53:39 +08:00
|
|
|
def max_name_length(self):
|
|
|
|
"""
|
|
|
|
Returns the maximum length of table and column names, or None if there
|
|
|
|
is no limit.
|
|
|
|
"""
|
|
|
|
return None
|
2007-08-20 07:59:06 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def no_limit_value(self):
|
|
|
|
"""
|
|
|
|
Returns the value to use for the LIMIT when we are wanting "LIMIT
|
|
|
|
infinity". Returns None if the limit clause can be omitted in this case.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a no_limit_value() method')
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2007-08-20 07:59:06 +08:00
|
|
|
def pk_default_value(self):
|
|
|
|
"""
|
|
|
|
Returns the value to use during an INSERT statement to specify that
|
|
|
|
the field should use its default value.
|
|
|
|
"""
|
|
|
|
return 'DEFAULT'
|
2007-08-20 08:04:20 +08:00
|
|
|
|
2009-03-14 05:04:48 +08:00
|
|
|
def process_clob(self, value):
|
|
|
|
"""
|
|
|
|
Returns the value of a CLOB column, for backends that return a locator
|
|
|
|
object that requires additional processing.
|
|
|
|
"""
|
|
|
|
return value
|
|
|
|
|
2009-03-11 15:06:50 +08:00
|
|
|
def return_insert_id(self):
|
|
|
|
"""
|
2009-03-13 07:41:27 +08:00
|
|
|
For backends that support returning the last insert ID as part
|
|
|
|
of an insert query, this method returns the SQL and params to
|
|
|
|
append to the INSERT query. The returned fragment should
|
|
|
|
contain a format string to hold the appropriate column.
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def compiler(self, compiler_name):
|
2007-08-20 10:39:05 +08:00
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
Returns the SQLCompiler class corresponding to the given name,
|
|
|
|
in the namespace corresponding to the `compiler_module` attribute
|
|
|
|
on this backend.
|
2007-08-20 10:39:05 +08:00
|
|
|
"""
|
2011-01-12 21:39:31 +08:00
|
|
|
if self._cache is None:
|
|
|
|
self._cache = import_module(self.compiler_module)
|
|
|
|
return getattr(self._cache, compiler_name)
|
2007-08-20 10:39:05 +08:00
|
|
|
|
2007-08-20 09:03:33 +08:00
|
|
|
def quote_name(self, name):
|
|
|
|
"""
|
|
|
|
Returns a quoted version of the given table, index or column name. Does
|
|
|
|
not quote the given name if it's already been quoted.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a quote_name() method')
|
2007-08-20 09:03:33 +08:00
|
|
|
|
2007-08-20 08:04:20 +08:00
|
|
|
def random_function_sql(self):
|
|
|
|
"""
|
2013-09-06 06:23:48 +08:00
|
|
|
Returns an SQL expression that returns a random value.
|
2007-08-20 08:04:20 +08:00
|
|
|
"""
|
|
|
|
return 'RANDOM()'
|
2007-08-20 08:15:53 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def regex_lookup(self, lookup_type):
|
|
|
|
"""
|
|
|
|
Returns the string to use in a query when performing regular expression
|
|
|
|
lookups (using "regex" or "iregex"). The resulting string should
|
|
|
|
contain a '%s' placeholder for the column being searched against.
|
|
|
|
|
|
|
|
If the feature is not supported (or part of it is not supported), a
|
|
|
|
NotImplementedError exception can be raised.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations may require a regex_lookup() method')
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2008-08-12 13:34:56 +08:00
|
|
|
def savepoint_create_sql(self, sid):
|
|
|
|
"""
|
|
|
|
Returns the SQL for starting a new savepoint. Only required if the
|
|
|
|
"uses_savepoints" feature is True. The "sid" parameter is a string
|
|
|
|
for the savepoint id.
|
|
|
|
"""
|
2013-03-01 01:30:03 +08:00
|
|
|
return "SAVEPOINT %s" % self.quote_name(sid)
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def savepoint_commit_sql(self, sid):
|
|
|
|
"""
|
|
|
|
Returns the SQL for committing the given savepoint.
|
|
|
|
"""
|
2013-03-01 01:30:03 +08:00
|
|
|
return "RELEASE SAVEPOINT %s" % self.quote_name(sid)
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def savepoint_rollback_sql(self, sid):
|
|
|
|
"""
|
|
|
|
Returns the SQL for rolling back the given savepoint.
|
|
|
|
"""
|
2013-03-01 01:30:03 +08:00
|
|
|
return "ROLLBACK TO SAVEPOINT %s" % self.quote_name(sid)
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2012-03-14 07:29:15 +08:00
|
|
|
def set_time_zone_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL that will set the connection's time zone.
|
|
|
|
|
|
|
|
Returns '' if the backend doesn't support time zones.
|
|
|
|
"""
|
|
|
|
return ''
|
|
|
|
|
2013-06-10 03:04:36 +08:00
|
|
|
def sql_flush(self, style, tables, sequences, allow_cascade=False):
|
2007-08-20 08:15:53 +08:00
|
|
|
"""
|
|
|
|
Returns a list of SQL statements required to remove all data from
|
|
|
|
the given database tables (without actually removing the tables
|
|
|
|
themselves).
|
|
|
|
|
2012-07-25 04:24:16 +08:00
|
|
|
The returned value also includes SQL statements required to reset DB
|
|
|
|
sequences passed in :param sequences:.
|
|
|
|
|
2007-08-20 08:15:53 +08:00
|
|
|
The `style` argument is a Style object as returned by either
|
|
|
|
color_style() or no_style() in django.core.management.color.
|
2013-06-10 03:04:36 +08:00
|
|
|
|
|
|
|
The `allow_cascade` argument determines whether truncation may cascade
|
|
|
|
to tables with foreign keys pointing the tables being truncated.
|
|
|
|
PostgreSQL requires a cascade even if these tables are empty.
|
2007-08-20 08:15:53 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseOperations must provide a sql_flush() method')
|
2007-08-20 08:21:10 +08:00
|
|
|
|
2012-07-25 04:24:16 +08:00
|
|
|
def sequence_reset_by_name_sql(self, style, sequences):
|
|
|
|
"""
|
|
|
|
Returns a list of the SQL statements required to reset sequences
|
|
|
|
passed in :param sequences:.
|
|
|
|
|
|
|
|
The `style` argument is a Style object as returned by either
|
|
|
|
color_style() or no_style() in django.core.management.color.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2007-08-20 08:21:10 +08:00
|
|
|
def sequence_reset_sql(self, style, model_list):
|
|
|
|
"""
|
|
|
|
Returns a list of the SQL statements required to reset sequences for
|
|
|
|
the given models.
|
|
|
|
|
|
|
|
The `style` argument is a Style object as returned by either
|
|
|
|
color_style() or no_style() in django.core.management.color.
|
|
|
|
"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
return [] # No sequence reset required by default.
|
2007-08-20 08:24:03 +08:00
|
|
|
|
|
|
|
def start_transaction_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL statement required to start a transaction.
|
|
|
|
"""
|
|
|
|
return "BEGIN;"
|
2007-08-20 08:30:19 +08:00
|
|
|
|
2010-05-28 21:46:12 +08:00
|
|
|
def end_transaction_sql(self, success=True):
|
2013-03-05 05:17:35 +08:00
|
|
|
"""
|
|
|
|
Returns the SQL statement required to end a transaction.
|
|
|
|
"""
|
2010-05-28 21:46:12 +08:00
|
|
|
if not success:
|
|
|
|
return "ROLLBACK;"
|
|
|
|
return "COMMIT;"
|
|
|
|
|
2008-09-11 07:03:07 +08:00
|
|
|
def tablespace_sql(self, tablespace, inline=False):
|
2007-08-20 08:30:19 +08:00
|
|
|
"""
|
2011-10-15 05:49:43 +08:00
|
|
|
Returns the SQL that will be used in a query to define the tablespace.
|
|
|
|
|
|
|
|
Returns '' if the backend doesn't support tablespaces.
|
|
|
|
|
|
|
|
If inline is True, the SQL is appended to a row; otherwise it's appended
|
|
|
|
to the entire CREATE TABLE or CREATE INDEX statement.
|
2007-08-20 08:30:19 +08:00
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
return ''
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2008-06-16 11:15:04 +08:00
|
|
|
def prep_for_like_query(self, x):
|
|
|
|
"""Prepares a value for use in a LIKE query."""
|
2012-08-30 04:40:51 +08:00
|
|
|
from django.utils.encoding import force_text
|
|
|
|
return force_text(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2008-08-28 13:42:05 +08:00
|
|
|
# Same as prep_for_like_query(), but called for "iexact" matches, which
|
|
|
|
# need not necessarily be implemented using "LIKE" in the backend.
|
|
|
|
prep_for_iexact_query = prep_for_like_query
|
|
|
|
|
2012-04-25 02:03:14 +08:00
|
|
|
def validate_autopk_value(self, value):
|
|
|
|
"""
|
|
|
|
Certain backends do not accept some values for "serial" fields
|
|
|
|
(for example zero in MySQL). This method will raise a ValueError
|
|
|
|
if the value is invalid, otherwise returns validated value.
|
|
|
|
"""
|
|
|
|
return value
|
|
|
|
|
2008-07-29 13:09:29 +08:00
|
|
|
def value_to_db_date(self, value):
|
|
|
|
"""
|
|
|
|
Transform a date value to an object compatible with what is expected
|
|
|
|
by the backend driver for date columns.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(value)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
def value_to_db_datetime(self, value):
|
|
|
|
"""
|
|
|
|
Transform a datetime value to an object compatible with what is expected
|
2008-07-30 11:16:39 +08:00
|
|
|
by the backend driver for datetime columns.
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(value)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
def value_to_db_time(self, value):
|
|
|
|
"""
|
2011-10-14 03:23:45 +08:00
|
|
|
Transform a time value to an object compatible with what is expected
|
2008-07-30 11:16:39 +08:00
|
|
|
by the backend driver for time columns.
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2013-02-10 23:15:49 +08:00
|
|
|
if timezone.is_aware(value):
|
2011-11-18 21:01:06 +08:00
|
|
|
raise ValueError("Django does not support timezone-aware times.")
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(value)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
def value_to_db_decimal(self, value, max_digits, decimal_places):
|
|
|
|
"""
|
|
|
|
Transform a decimal.Decimal value to an object compatible with what is
|
|
|
|
expected by the backend driver for decimal (numeric) columns.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2013-09-17 00:52:05 +08:00
|
|
|
return utils.format_number(value, max_digits, decimal_places)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
def year_lookup_bounds_for_date_field(self, value):
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
Returns a two-elements list with the lower and upper bound to be used
|
2013-02-10 23:15:49 +08:00
|
|
|
with a BETWEEN operator to query a DateField value using a year
|
|
|
|
lookup.
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
`value` is an int, containing the looked-up year.
|
|
|
|
"""
|
2013-02-10 23:15:49 +08:00
|
|
|
first = datetime.date(value, 1, 1)
|
|
|
|
second = datetime.date(value, 12, 31)
|
|
|
|
return [first, second]
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
def year_lookup_bounds_for_datetime_field(self, value):
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
Returns a two-elements list with the lower and upper bound to be used
|
2013-02-10 23:15:49 +08:00
|
|
|
with a BETWEEN operator to query a DateTimeField value using a year
|
|
|
|
lookup.
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
`value` is an int, containing the looked-up year.
|
|
|
|
"""
|
2013-02-10 23:15:49 +08:00
|
|
|
first = datetime.datetime(value, 1, 1)
|
|
|
|
second = datetime.datetime(value, 12, 31, 23, 59, 59, 999999)
|
|
|
|
if settings.USE_TZ:
|
|
|
|
tz = timezone.get_current_timezone()
|
|
|
|
first = timezone.make_aware(first, tz)
|
|
|
|
second = timezone.make_aware(second, tz)
|
|
|
|
return [first, second]
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2009-01-15 19:06:34 +08:00
|
|
|
def convert_values(self, value, field):
|
2012-07-15 19:41:05 +08:00
|
|
|
"""
|
|
|
|
Coerce the value returned by the database backend into a consistent type
|
|
|
|
that is compatible with the field type.
|
2009-01-15 19:06:34 +08:00
|
|
|
"""
|
2013-09-23 23:18:20 +08:00
|
|
|
if value is None or field is None:
|
2009-01-15 19:06:34 +08:00
|
|
|
return value
|
2012-12-17 04:24:15 +08:00
|
|
|
internal_type = field.get_internal_type()
|
|
|
|
if internal_type == 'FloatField':
|
2012-08-13 14:15:20 +08:00
|
|
|
return float(value)
|
2012-07-15 19:41:05 +08:00
|
|
|
elif (internal_type and (internal_type.endswith('IntegerField')
|
|
|
|
or internal_type == 'AutoField')):
|
2009-01-15 19:06:34 +08:00
|
|
|
return int(value)
|
2012-07-15 19:41:05 +08:00
|
|
|
return value
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-02-02 20:03:31 +08:00
|
|
|
def check_aggregate_support(self, aggregate_func):
|
|
|
|
"""Check that the backend supports the provided aggregate
|
|
|
|
|
|
|
|
This is used on specific backends to rule out known aggregates
|
|
|
|
that are known to have faulty implementations. If the named
|
|
|
|
aggregate function has a known problem, the backend should
|
2011-10-05 17:54:01 +08:00
|
|
|
raise NotImplementedError.
|
2009-02-02 20:03:31 +08:00
|
|
|
"""
|
|
|
|
pass
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-02-24 19:15:31 +08:00
|
|
|
def combine_expression(self, connector, sub_expressions):
|
|
|
|
"""Combine a list of subexpressions into a single expression, using
|
|
|
|
the provided connecting operator. This is required because operators
|
|
|
|
can vary between backends (e.g., Oracle with %% and &) and between
|
|
|
|
subexpression types (e.g., date expressions)
|
|
|
|
"""
|
|
|
|
conn = ' %s ' % connector
|
|
|
|
return conn.join(sub_expressions)
|
|
|
|
|
2012-11-15 20:23:02 +08:00
|
|
|
def modify_insert_params(self, placeholders, params):
|
|
|
|
"""Allow modification of insert parameters. Needed for Oracle Spatial
|
|
|
|
backend due to #10888.
|
|
|
|
"""
|
|
|
|
return params
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
|
2013-01-13 04:10:08 +08:00
|
|
|
|
|
|
|
# Structure returned by the DB-API cursor.description interface (PEP 249)
|
|
|
|
FieldInfo = namedtuple('FieldInfo',
|
2013-12-09 01:20:06 +08:00
|
|
|
'name type_code display_size internal_size precision scale null_ok')
|
2013-01-13 04:10:08 +08:00
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseIntrospection(object):
|
|
|
|
"""
|
|
|
|
This class encapsulates all backend-specific introspection utilities
|
|
|
|
"""
|
|
|
|
data_types_reverse = {}
|
|
|
|
|
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2009-08-22 05:42:39 +08:00
|
|
|
def get_field_type(self, data_type, description):
|
|
|
|
"""Hook for a database backend to use the cursor description to
|
|
|
|
match a Django field type to a database column.
|
|
|
|
|
|
|
|
For Oracle, the column data_type on its own is insufficient to
|
|
|
|
distinguish between a FloatField and IntegerField, for example."""
|
|
|
|
return self.data_types_reverse[data_type]
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def table_name_converter(self, name):
|
|
|
|
"""Apply a conversion to the name for the purposes of comparison.
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
The default table name converter is for case sensitive comparison.
|
|
|
|
"""
|
|
|
|
return name
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2012-04-29 07:11:55 +08:00
|
|
|
def table_names(self, cursor=None):
|
|
|
|
"""
|
|
|
|
Returns a list of names of all tables that exist in the database.
|
|
|
|
The returned table list is sorted by Python's default sorting. We
|
|
|
|
do NOT use database's ORDER BY here to avoid subtle differences
|
|
|
|
in sorting order between databases.
|
|
|
|
"""
|
|
|
|
if cursor is None:
|
2014-01-09 23:05:15 +08:00
|
|
|
with self.connection.cursor() as cursor:
|
|
|
|
return sorted(self.get_table_list(cursor))
|
2012-04-29 07:11:55 +08:00
|
|
|
return sorted(self.get_table_list(cursor))
|
|
|
|
|
|
|
|
def get_table_list(self, cursor):
|
|
|
|
"""
|
|
|
|
Returns an unsorted list of names of all tables that exist in the
|
|
|
|
database.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseIntrospection may require a get_table_list() method')
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
def django_table_names(self, only_existing=False):
|
|
|
|
"""
|
|
|
|
Returns a list of all table names that have associated Django models and
|
|
|
|
are in INSTALLED_APPS.
|
|
|
|
|
|
|
|
If only_existing is True, the resulting list will only include the tables
|
|
|
|
that actually exist in the database.
|
|
|
|
"""
|
2013-12-24 19:25:17 +08:00
|
|
|
from django.apps import apps
|
2013-12-12 06:31:34 +08:00
|
|
|
from django.db import router
|
2008-08-11 20:11:25 +08:00
|
|
|
tables = set()
|
2013-12-31 06:53:54 +08:00
|
|
|
for app_config in apps.get_app_configs():
|
2013-12-30 04:21:23 +08:00
|
|
|
for model in router.get_migratable_models(app_config, self.connection.alias):
|
2009-03-09 11:35:02 +08:00
|
|
|
if not model._meta.managed:
|
|
|
|
continue
|
2008-08-11 20:11:25 +08:00
|
|
|
tables.add(model._meta.db_table)
|
2013-08-30 07:20:00 +08:00
|
|
|
tables.update(f.m2m_db_table() for f in model._meta.local_many_to_many)
|
2012-02-12 06:12:49 +08:00
|
|
|
tables = list(tables)
|
2008-08-11 20:11:25 +08:00
|
|
|
if only_existing:
|
2010-10-31 08:53:58 +08:00
|
|
|
existing_tables = self.table_names()
|
|
|
|
tables = [
|
|
|
|
t
|
|
|
|
for t in tables
|
|
|
|
if self.table_name_converter(t) in existing_tables
|
|
|
|
]
|
2008-08-11 20:11:25 +08:00
|
|
|
return tables
|
|
|
|
|
|
|
|
def installed_models(self, tables):
|
|
|
|
"Returns a set of all models represented by the provided list of table names."
|
2013-12-24 19:25:17 +08:00
|
|
|
from django.apps import apps
|
2013-12-12 06:31:34 +08:00
|
|
|
from django.db import router
|
2008-08-11 20:11:25 +08:00
|
|
|
all_models = []
|
2013-12-31 06:53:54 +08:00
|
|
|
for app_config in apps.get_app_configs():
|
2013-12-30 04:21:23 +08:00
|
|
|
all_models.extend(router.get_migratable_models(app_config, self.connection.alias))
|
2012-08-16 14:08:45 +08:00
|
|
|
tables = list(map(self.table_name_converter, tables))
|
2010-11-02 13:41:46 +08:00
|
|
|
return set([
|
|
|
|
m for m in all_models
|
|
|
|
if self.table_name_converter(m._meta.db_table) in tables
|
2008-08-11 20:11:25 +08:00
|
|
|
])
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def sequence_list(self):
|
|
|
|
"Returns a list of information about all DB sequences for all models in all apps."
|
2013-12-24 19:25:17 +08:00
|
|
|
from django.apps import apps
|
2010-03-10 21:43:23 +08:00
|
|
|
from django.db import models, router
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
sequence_list = []
|
|
|
|
|
2013-12-31 06:53:54 +08:00
|
|
|
for app_config in apps.get_app_configs():
|
2013-12-30 04:21:23 +08:00
|
|
|
for model in router.get_migratable_models(app_config, self.connection.alias):
|
2009-03-09 11:35:02 +08:00
|
|
|
if not model._meta.managed:
|
|
|
|
continue
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
if model._meta.swapped:
|
|
|
|
continue
|
2008-08-11 20:11:25 +08:00
|
|
|
for f in model._meta.local_fields:
|
|
|
|
if isinstance(f, models.AutoField):
|
|
|
|
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
break # Only one AutoField is allowed per model, so don't bother continuing.
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
for f in model._meta.local_many_to_many:
|
2009-04-13 15:07:51 +08:00
|
|
|
# If this is an m2m using an intermediate table,
|
|
|
|
# we don't need to reset the sequence.
|
|
|
|
if f.rel.through is None:
|
|
|
|
sequence_list.append({'table': f.m2m_db_table(), 'column': None})
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
return sequence_list
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
def get_key_columns(self, cursor, table_name):
|
|
|
|
"""
|
|
|
|
Backends can override this to return a list of (column_name, referenced_table_name,
|
|
|
|
referenced_column_name) for all key columns in given table.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseIntrospection may require a get_key_columns() method')
|
2011-08-07 08:43:26 +08:00
|
|
|
|
|
|
|
def get_primary_key_column(self, cursor, table_name):
|
|
|
|
"""
|
2012-09-08 16:24:13 +08:00
|
|
|
Returns the name of the primary key column for the given table.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2012-09-08 16:24:13 +08:00
|
|
|
for column in six.iteritems(self.get_indexes(cursor, table_name)):
|
|
|
|
if column[1]['primary_key']:
|
|
|
|
return column[0]
|
|
|
|
return None
|
2011-08-07 08:43:26 +08:00
|
|
|
|
2012-04-30 19:05:30 +08:00
|
|
|
def get_indexes(self, cursor, table_name):
|
|
|
|
"""
|
|
|
|
Returns a dictionary of indexed fieldname -> infodict for the given
|
|
|
|
table, where each infodict is in the format:
|
|
|
|
{'primary_key': boolean representing whether it's the primary key,
|
|
|
|
'unique': boolean representing whether it's a unique index}
|
|
|
|
|
|
|
|
Only single-column indexes are introspected.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseIntrospection may require a get_indexes() method')
|
2012-04-30 19:05:30 +08:00
|
|
|
|
2012-08-02 22:08:39 +08:00
|
|
|
def get_constraints(self, cursor, table_name):
|
|
|
|
"""
|
2013-08-11 06:58:12 +08:00
|
|
|
Retrieves any constraints or keys (unique, pk, fk, check, index)
|
|
|
|
across one or more columns.
|
|
|
|
|
|
|
|
Returns a dict mapping constraint names to their attributes,
|
|
|
|
where attributes is a dict with keys:
|
|
|
|
* columns: List of columns this covers
|
|
|
|
* primary_key: True if primary key, False otherwise
|
|
|
|
* unique: True if this is a unique constraint, False otherwise
|
|
|
|
* foreign_key: (table, column) of target, or None
|
|
|
|
* check: True if check constraint, False otherwise
|
|
|
|
* index: True if index, False otherwise.
|
|
|
|
|
|
|
|
Some backends may return special constraint names that don't exist
|
|
|
|
if they don't name constraints of a certain type (e.g. SQLite)
|
2012-08-02 22:08:39 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseIntrospection may require a get_constraints() method')
|
2012-08-02 22:08:39 +08:00
|
|
|
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseClient(object):
|
|
|
|
"""
|
2008-09-09 10:13:58 +08:00
|
|
|
This class encapsulates all backend-specific methods for opening a
|
|
|
|
client shell.
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
2008-09-09 10:13:58 +08:00
|
|
|
# This should be a string representing the name of the executable
|
|
|
|
# (e.g., "psql"). Subclasses must override this.
|
|
|
|
executable_name = None
|
|
|
|
|
2009-03-11 11:39:34 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
# connection is an instance of BaseDatabaseWrapper.
|
|
|
|
self.connection = connection
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def runshell(self):
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of BaseDatabaseClient must provide a runshell() method')
|
2008-08-11 20:11:25 +08:00
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseValidation(object):
|
|
|
|
"""
|
2014-03-02 22:25:53 +08:00
|
|
|
This class encapsulates all backend-specific model validation.
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def validate_field(self, errors, opts, f):
|
2014-01-20 10:45:21 +08:00
|
|
|
"""
|
|
|
|
By default, there is no backend-specific validation.
|
|
|
|
|
|
|
|
This method has been deprecated by the new checks framework. New
|
|
|
|
backends should implement check_field instead.
|
|
|
|
"""
|
|
|
|
# This is deliberately commented out. It exists as a marker to
|
|
|
|
# remind us to remove this method, and the check_field() shim,
|
|
|
|
# when the time comes.
|
2014-02-27 05:48:20 +08:00
|
|
|
# warnings.warn('"validate_field" has been deprecated", RemovedInDjango19Warning)
|
2008-08-11 20:11:25 +08:00
|
|
|
pass
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
def check_field(self, field, **kwargs):
|
|
|
|
class ErrorList(list):
|
|
|
|
"""A dummy list class that emulates API used by the older
|
|
|
|
validate_field() method. When validate_field() is fully
|
|
|
|
deprecated, this dummy can be removed too.
|
|
|
|
"""
|
|
|
|
def add(self, opts, error_message):
|
|
|
|
self.append(checks.Error(error_message, hint=None, obj=field))
|
|
|
|
|
|
|
|
errors = ErrorList()
|
|
|
|
# Some tests create fields in isolation -- the fields are not attached
|
|
|
|
# to any model, so they have no `model` attribute.
|
|
|
|
opts = field.model._meta if hasattr(field, 'model') else None
|
|
|
|
self.validate_field(errors, field, opts)
|
|
|
|
return list(errors)
|