2005-07-13 09:25:57 +08:00
|
|
|
"""
|
|
|
|
This is the core database connection.
|
|
|
|
|
|
|
|
All CMS code assumes database SELECT statements cast the resulting values as such:
|
|
|
|
* booleans are mapped to Python booleans
|
|
|
|
* dates are mapped to Python datetime.date objects
|
|
|
|
* times are mapped to Python datetime.time objects
|
|
|
|
* timestamps are mapped to Python datetime.datetime objects
|
|
|
|
|
|
|
|
Right now, we're handling this by using psycopg's custom typecast definitions.
|
|
|
|
If we move to a different database module, we should ensure that it either
|
|
|
|
performs the appropriate typecasting out of the box, or that it has hooks that
|
|
|
|
let us do that.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.conf.settings import DATABASE_ENGINE
|
|
|
|
|
2005-07-18 04:03:24 +08:00
|
|
|
try:
|
|
|
|
dbmod = __import__('django.core.db.backends.%s' % DATABASE_ENGINE, '', '', [''])
|
|
|
|
except ImportError:
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
raise ImproperlyConfigured, "Your DATABASE_ENGINE setting, %r, is invalid. Is it spelled correctly?" % DATABASE_ENGINE
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
DatabaseError = dbmod.DatabaseError
|
|
|
|
db = dbmod.DatabaseWrapper()
|
|
|
|
dictfetchone = dbmod.dictfetchone
|
|
|
|
dictfetchmany = dbmod.dictfetchmany
|
|
|
|
dictfetchall = dbmod.dictfetchall
|
|
|
|
dictfetchall = dbmod.dictfetchall
|
|
|
|
get_last_insert_id = dbmod.get_last_insert_id
|
2005-07-18 02:23:34 +08:00
|
|
|
get_date_extract_sql = dbmod.get_date_extract_sql
|
2005-07-18 04:16:06 +08:00
|
|
|
get_date_trunc_sql = dbmod.get_date_trunc_sql
|
2005-07-13 09:25:57 +08:00
|
|
|
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
|
|
|
|
DATA_TYPES = dbmod.DATA_TYPES
|