| 1 |
""" |
|---|
| 2 |
This is the core database connection. |
|---|
| 3 |
|
|---|
| 4 |
All CMS code assumes database SELECT statements cast the resulting values as such: |
|---|
| 5 |
* booleans are mapped to Python booleans |
|---|
| 6 |
* dates are mapped to Python datetime.date objects |
|---|
| 7 |
* times are mapped to Python datetime.time objects |
|---|
| 8 |
* timestamps are mapped to Python datetime.datetime objects |
|---|
| 9 |
|
|---|
| 10 |
Right now, we're handling this by using psycopg's custom typecast definitions. |
|---|
| 11 |
If we move to a different database module, we should ensure that it either |
|---|
| 12 |
performs the appropriate typecasting out of the box, or that it has hooks that |
|---|
| 13 |
let us do that. |
|---|
| 14 |
""" |
|---|
| 15 |
|
|---|
| 16 |
from django.conf.settings import DATABASE_ENGINE |
|---|
| 17 |
|
|---|
| 18 |
try: |
|---|
| 19 |
dbmod = __import__('django.core.db.backends.%s' % DATABASE_ENGINE, '', '', ['']) |
|---|
| 20 |
except ImportError, exc: |
|---|
| 21 |
# The database backend wasn't found. Display a helpful error message |
|---|
| 22 |
# listing all possible database backends. |
|---|
| 23 |
from django.core.exceptions import ImproperlyConfigured |
|---|
| 24 |
import os |
|---|
| 25 |
backend_dir = os.path.join(__path__[0], 'backends') |
|---|
| 26 |
available_backends = [f[:-3] for f in os.listdir(backend_dir) if f.endswith('.py') and not f.startswith('__init__')] |
|---|
| 27 |
available_backends.sort() |
|---|
| 28 |
raise ImproperlyConfigured, "Could not load database backend: %s. Is your DATABASE_ENGINE setting (currently, %r) spelled correctly? Available options are: %s" % \ |
|---|
| 29 |
(exc, DATABASE_ENGINE, ", ".join(map(repr, available_backends))) |
|---|
| 30 |
|
|---|
| 31 |
DatabaseError = dbmod.DatabaseError |
|---|
| 32 |
db = dbmod.DatabaseWrapper() |
|---|
| 33 |
dictfetchone = dbmod.dictfetchone |
|---|
| 34 |
dictfetchmany = dbmod.dictfetchmany |
|---|
| 35 |
dictfetchall = dbmod.dictfetchall |
|---|
| 36 |
dictfetchall = dbmod.dictfetchall |
|---|
| 37 |
get_last_insert_id = dbmod.get_last_insert_id |
|---|
| 38 |
get_date_extract_sql = dbmod.get_date_extract_sql |
|---|
| 39 |
get_date_trunc_sql = dbmod.get_date_trunc_sql |
|---|
| 40 |
get_table_list = dbmod.get_table_list |
|---|
| 41 |
get_relations = dbmod.get_relations |
|---|
| 42 |
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING |
|---|
| 43 |
DATA_TYPES = dbmod.DATA_TYPES |
|---|
| 44 |
DATA_TYPES_REVERSE = dbmod.DATA_TYPES_REVERSE |
|---|
| 45 |
EMPTY_STR_EQUIV = dbmod.EMPTY_STR_EQUIV |
|---|