Django

Code

Changeset 1632

Show
Ignore:
Timestamp:
12/13/05 23:21:44 (3 years ago)
Author:
adrian
Message:

magic-removal: Moved django.core.db.backends to django.db.backends

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/backends/ado_mssql/wrapper.py

    r1541 r1632  
    110110    return "RAND()" 
    111111 
    112 def get_table_list(cursor): 
    113     raise NotImplementedError 
    114  
    115 def get_table_description(cursor, table_name): 
    116     raise NotImplementedError 
    117  
    118 def get_relations(cursor, table_name): 
    119     raise NotImplementedError 
    120  
    121112OPERATOR_MAPPING = { 
    122113    'exact': '= %s', 
     
    162153} 
    163154 
    164 DATA_TYPES_REVERSE = {} 
  • django/branches/magic-removal/django/db/backends/mysql/wrapper.py

    r1541 r1632  
    120120    return "RAND()" 
    121121 
    122 def get_table_list(cursor): 
    123     "Returns a list of table names in the current database." 
    124     cursor.execute("SHOW TABLES") 
    125     return [row[0] for row in cursor.fetchall()] 
    126  
    127 def get_table_description(cursor, table_name): 
    128     "Returns a description of the table, with the DB-API cursor.description interface." 
    129     cursor.execute("SELECT * FROM %s LIMIT 1" % table_name) 
    130     return cursor.description 
    131  
    132 def get_relations(cursor, table_name): 
    133     raise NotImplementedError 
    134  
    135122OPERATOR_MAPPING = { 
    136123    'exact': '= %s', 
     
    179166    'USStateField':      'varchar(2)', 
    180167} 
    181  
    182 DATA_TYPES_REVERSE = { 
    183     FIELD_TYPE.BLOB: 'TextField', 
    184     FIELD_TYPE.CHAR: 'CharField', 
    185     FIELD_TYPE.DECIMAL: 'FloatField', 
    186     FIELD_TYPE.DATE: 'DateField', 
    187     FIELD_TYPE.DATETIME: 'DateTimeField', 
    188     FIELD_TYPE.DOUBLE: 'FloatField', 
    189     FIELD_TYPE.FLOAT: 'FloatField', 
    190     FIELD_TYPE.INT24: 'IntegerField', 
    191     FIELD_TYPE.LONG: 'IntegerField', 
    192     FIELD_TYPE.LONGLONG: 'IntegerField', 
    193     FIELD_TYPE.SHORT: 'IntegerField', 
    194     FIELD_TYPE.STRING: 'TextField', 
    195     FIELD_TYPE.TIMESTAMP: 'DateTimeField', 
    196     FIELD_TYPE.TINY_BLOB: 'TextField', 
    197     FIELD_TYPE.MEDIUM_BLOB: 'TextField', 
    198     FIELD_TYPE.LONG_BLOB: 'TextField', 
    199     FIELD_TYPE.VAR_STRING: 'CharField', 
    200 } 
  • django/branches/magic-removal/django/db/backends/postgresql/wrapper.py

    r1583 r1632  
    9090    return "RANDOM()" 
    9191 
    92 def get_table_list(cursor): 
    93     "Returns a list of table names in the current database." 
    94     cursor.execute(""" 
    95         SELECT c.relname 
    96         FROM pg_catalog.pg_class c 
    97         LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace 
    98         WHERE c.relkind IN ('r', 'v', '') 
    99             AND n.nspname NOT IN ('pg_catalog', 'pg_toast') 
    100             AND pg_catalog.pg_table_is_visible(c.oid)""") 
    101     return [row[0] for row in cursor.fetchall()] 
    102  
    103 def get_table_description(cursor, table_name): 
    104     "Returns a description of the table, with the DB-API cursor.description interface." 
    105     cursor.execute("SELECT * FROM %s LIMIT 1" % table_name) 
    106     return cursor.description 
    107  
    108 def get_relations(cursor, table_name): 
    109     """ 
    110     Returns a dictionary of {field_index: (field_index_other_table, other_table)} 
    111     representing all relationships to the given table. Indexes are 0-based. 
    112     """ 
    113     cursor.execute(""" 
    114         SELECT con.conkey, con.confkey, c2.relname 
    115         FROM pg_constraint con, pg_class c1, pg_class c2 
    116         WHERE c1.oid = con.conrelid 
    117             AND c2.oid = con.confrelid 
    118             AND c1.relname = %s 
    119             AND con.contype = 'f'""", [table_name]) 
    120     relations = {} 
    121     for row in cursor.fetchall(): 
    122         try: 
    123             # row[0] and row[1] are like "{2}", so strip the curly braces. 
    124             relations[int(row[0][1:-1]) - 1] = (int(row[1][1:-1]) - 1, row[2]) 
    125         except ValueError: 
    126             continue 
    127     return relations 
    128  
    12992# Register these custom typecasts, because Django expects dates/times to be 
    13093# in Python's native (standard-library) datetime/time format, whereas psycopg 
     
    184147    'USStateField':      'varchar(2)', 
    185148} 
    186  
    187 # Maps type codes to Django Field types. 
    188 DATA_TYPES_REVERSE = { 
    189     16: 'BooleanField', 
    190     21: 'SmallIntegerField', 
    191     23: 'IntegerField', 
    192     25: 'TextField', 
    193     869: 'IPAddressField', 
    194     1043: 'CharField', 
    195     1082: 'DateField', 
    196     1083: 'TimeField', 
    197     1114: 'DateTimeField', 
    198     1184: 'DateTimeField', 
    199     1266: 'TimeField', 
    200     1700: 'FloatField', 
    201 } 
  • django/branches/magic-removal/django/db/backends/sqlite3/wrapper.py

    r1541 r1632  
    124124        return "%i-%02i-%02i 00:00:00" % (dt.year, dt.month, dt.day) 
    125125 
    126 def get_table_list(cursor): 
    127     cursor.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name") 
    128     return [row[0] for row in cursor.fetchall()] 
    129  
    130 def get_table_description(cursor, table_name): 
    131     cursor.execute("PRAGMA table_info(%s)" % table_name) 
    132     return [(row[1], row[2], None, None) for row in cursor.fetchall()] 
    133  
    134 def get_relations(cursor, table_name): 
    135     raise NotImplementedError 
    136  
    137126# Operators and fields ######################################################## 
    138127 
     
    185174    'USStateField':                 'varchar(2)', 
    186175} 
    187  
    188 # Maps SQL types to Django Field types. Some of the SQL types have multiple 
    189 # entries here because SQLite allows for anything and doesn't normalize the 
    190 # field type; it uses whatever was given. 
    191 BASE_DATA_TYPES_REVERSE = { 
    192     'bool': 'BooleanField', 
    193     'boolean': 'BooleanField', 
    194     'smallint': 'SmallIntegerField', 
    195     'smallinteger': 'SmallIntegerField', 
    196     'int': 'IntegerField', 
    197     'integer': 'IntegerField', 
    198     'text': 'TextField', 
    199     'char': 'CharField', 
    200     'date': 'DateField', 
    201     'datetime': 'DateTimeField', 
    202     'time': 'TimeField', 
    203 } 
    204  
    205 # This light wrapper "fakes" a dictionary interface, because some SQLite data 
    206 # types include variables in them -- e.g. "varchar(30)" -- and can't be matched 
    207 # as a simple dictionary lookup. 
    208 class FlexibleFieldLookupDict: 
    209     def __getitem__(self, key): 
    210         key = key.lower() 
    211         try: 
    212             return BASE_DATA_TYPES_REVERSE[key] 
    213         except KeyError: 
    214             import re 
    215             m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key) 
    216             if m: 
    217                 return ('CharField', {'maxlength': m.group(1)}) 
    218             raise KeyError 
    219  
    220 DATA_TYPES_REVERSE = FlexibleFieldLookupDict()