Changeset 1632
- Timestamp:
- 12/13/05 23:21:44 (3 years ago)
- Files:
-
- django/branches/magic-removal/django/core/db/backends (deleted)
- django/branches/magic-removal/django/db/backends (added)
- django/branches/magic-removal/django/db/backends/ado_mssql (added)
- django/branches/magic-removal/django/db/backends/ado_mssql/__init__.py (added)
- django/branches/magic-removal/django/db/backends/ado_mssql/introspection.py (added)
- django/branches/magic-removal/django/db/backends/ado_mssql/wrapper.py (copied) (copied from django/branches/magic-removal/django/core/db/backends/ado_mssql.py) (2 diffs)
- django/branches/magic-removal/django/db/backends/__init__.py (added)
- django/branches/magic-removal/django/db/backends/mysql (added)
- django/branches/magic-removal/django/db/backends/mysql/__init__.py (added)
- django/branches/magic-removal/django/db/backends/mysql/introspection.py (added)
- django/branches/magic-removal/django/db/backends/mysql/wrapper.py (copied) (copied from django/branches/magic-removal/django/core/db/backends/mysql.py) (2 diffs)
- django/branches/magic-removal/django/db/backends/postgresql (added)
- django/branches/magic-removal/django/db/backends/postgresql/__init__.py (added)
- django/branches/magic-removal/django/db/backends/postgresql/introspection.py (added)
- django/branches/magic-removal/django/db/backends/postgresql/wrapper.py (copied) (copied from django/branches/magic-removal/django/core/db/backends/postgresql.py) (2 diffs)
- django/branches/magic-removal/django/db/backends/sqlite3 (added)
- django/branches/magic-removal/django/db/backends/sqlite3/__init__.py (added)
- django/branches/magic-removal/django/db/backends/sqlite3/introspection.py (added)
- django/branches/magic-removal/django/db/backends/sqlite3/wrapper.py (copied) (copied from django/branches/magic-removal/django/core/db/backends/sqlite3.py) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/db/backends/ado_mssql/wrapper.py
r1541 r1632 110 110 return "RAND()" 111 111 112 def get_table_list(cursor):113 raise NotImplementedError114 115 def get_table_description(cursor, table_name):116 raise NotImplementedError117 118 def get_relations(cursor, table_name):119 raise NotImplementedError120 121 112 OPERATOR_MAPPING = { 122 113 'exact': '= %s', … … 162 153 } 163 154 164 DATA_TYPES_REVERSE = {}django/branches/magic-removal/django/db/backends/mysql/wrapper.py
r1541 r1632 120 120 return "RAND()" 121 121 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.description131 132 def get_relations(cursor, table_name):133 raise NotImplementedError134 135 122 OPERATOR_MAPPING = { 136 123 'exact': '= %s', … … 179 166 'USStateField': 'varchar(2)', 180 167 } 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 90 90 return "RANDOM()" 91 91 92 def get_table_list(cursor):93 "Returns a list of table names in the current database."94 cursor.execute("""95 SELECT c.relname96 FROM pg_catalog.pg_class c97 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace98 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.description107 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.relname115 FROM pg_constraint con, pg_class c1, pg_class c2116 WHERE c1.oid = con.conrelid117 AND c2.oid = con.confrelid118 AND c1.relname = %s119 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 continue127 return relations128 129 92 # Register these custom typecasts, because Django expects dates/times to be 130 93 # in Python's native (standard-library) datetime/time format, whereas psycopg … … 184 147 'USStateField': 'varchar(2)', 185 148 } 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 124 124 return "%i-%02i-%02i 00:00:00" % (dt.year, dt.month, dt.day) 125 125 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 NotImplementedError136 137 126 # Operators and fields ######################################################## 138 127 … … 185 174 'USStateField': 'varchar(2)', 186 175 } 187 188 # Maps SQL types to Django Field types. Some of the SQL types have multiple189 # entries here because SQLite allows for anything and doesn't normalize the190 # 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 data206 # types include variables in them -- e.g. "varchar(30)" -- and can't be matched207 # 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 re215 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 KeyError219 220 DATA_TYPES_REVERSE = FlexibleFieldLookupDict()
