2005-07-13 09:25:57 +08:00
"""
This is the core database connection .
2005-11-01 09:28:42 +08:00
All Django code assumes database SELECT statements cast the resulting values as such :
2005-07-13 09:25:57 +08:00
* 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
"""
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 , ' ' , ' ' , [ ' ' ] )
2005-07-21 21:57:42 +08:00
except ImportError , exc :
2005-07-20 03:04:12 +08:00
# The database backend wasn't found. Display a helpful error message
# listing all possible database backends.
2005-07-18 04:03:24 +08:00
from django . core . exceptions import ImproperlyConfigured
2005-07-20 03:04:12 +08:00
import os
backend_dir = os . path . join ( __path__ [ 0 ] , ' backends ' )
available_backends = [ f [ : - 3 ] for f in os . listdir ( backend_dir ) if f . endswith ( ' .py ' ) and not f . startswith ( ' __init__ ' ) ]
available_backends . sort ( )
2005-07-21 23:01:31 +08:00
raise ImproperlyConfigured , " Could not load database backend: %s . Is your DATABASE_ENGINE setting (currently, %r ) spelled correctly? Available options are: %s " % \
( exc , DATABASE_ENGINE , " , " . join ( map ( repr , available_backends ) ) )
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-08-20 05:51:14 +08:00
get_limit_offset_sql = dbmod . get_limit_offset_sql
2005-09-03 04:46:00 +08:00
get_random_function_sql = dbmod . get_random_function_sql
2005-08-03 01:08:24 +08:00
get_table_list = dbmod . get_table_list
2005-11-29 10:05:32 +08:00
get_table_description = dbmod . get_table_description
2005-08-03 06:33:39 +08:00
get_relations = dbmod . get_relations
2005-07-13 09:25:57 +08:00
OPERATOR_MAPPING = dbmod . OPERATOR_MAPPING
DATA_TYPES = dbmod . DATA_TYPES
2005-08-03 01:08:24 +08:00
DATA_TYPES_REVERSE = dbmod . DATA_TYPES_REVERSE