diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-23 11:30:07 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-23 11:30:07 -0400 |
| commit | c7ab095fdbb13d045376df3f997a30058d7c82dd (patch) | |
| tree | 6c58c2a05aefdbe6ab6a10fd54737ae4ed5a5ef4 /lib/sqlalchemy/dialects/sqlite/base.py | |
| parent | d345789fa510e0ae0983dec0bc253ac337405543 (diff) | |
| download | sqlalchemy-c7ab095fdbb13d045376df3f997a30058d7c82dd.tar.gz | |
- [bug] Adjusted column default reflection code to
convert non-string values to string, to accommodate
old SQLite versions that don't deliver
default info as a string. [ticket:2265]
- factor sqlite column reflection to be like we did for postgresql,
in a separate method.
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/base.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 651fa05e5..837f1adcd 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -714,42 +714,50 @@ class SQLiteDialect(default.DefaultDialect): c = _pragma_cursor( connection.execute("%stable_info(%s)" % (pragma, qtable))) - found_table = False + + rows = c.fetchall() columns = [] - while True: - row = c.fetchone() - if row is None: - break - (name, type_, nullable, default, has_default, primary_key) = \ + for row in rows: + (name, type_, nullable, default, primary_key) = \ (row[1], row[2].upper(), not row[3], - row[4], row[4] is not None, row[5]) - match = re.match(r'(\w+)(\(.*?\))?', type_) - if match: - coltype = match.group(1) - args = match.group(2) - else: - coltype = "VARCHAR" - args = '' - try: - coltype = self.ischema_names[coltype] - if args is not None: - args = re.findall(r'(\d+)', args) - coltype = coltype(*[int(a) for a in args]) - except KeyError: - util.warn("Did not recognize type '%s' of column '%s'" % - (coltype, name)) - coltype = sqltypes.NullType() - - columns.append({ - 'name' : name, - 'type' : coltype, - 'nullable' : nullable, - 'default' : default, - 'autoincrement':default is None, - 'primary_key': primary_key - }) + row[4], row[5]) + + columns.append(self._get_column_info(name, type_, nullable, + default, primary_key)) return columns + def _get_column_info(self, name, type_, nullable, + default, primary_key): + + match = re.match(r'(\w+)(\(.*?\))?', type_) + if match: + coltype = match.group(1) + args = match.group(2) + else: + coltype = "VARCHAR" + args = '' + try: + coltype = self.ischema_names[coltype] + if args is not None: + args = re.findall(r'(\d+)', args) + coltype = coltype(*[int(a) for a in args]) + except KeyError: + util.warn("Did not recognize type '%s' of column '%s'" % + (coltype, name)) + coltype = sqltypes.NullType() + + if default is not None: + default = unicode(default) + + return { + 'name': name, + 'type': coltype, + 'nullable': nullable, + 'default': default, + 'autoincrement': default is None, + 'primary_key': primary_key + } + @reflection.cache def get_pk_constraint(self, connection, table_name, schema=None, **kw): cols = self.get_columns(connection, table_name, schema, **kw) @@ -789,7 +797,7 @@ class SQLiteDialect(default.DefaultDialect): fk = fks[numerical_id] except KeyError: fk = { - 'name' : None, + 'name': None, 'constrained_columns' : [], 'referred_schema' : None, 'referred_table' : rtbl, @@ -845,4 +853,5 @@ def _pragma_cursor(cursor): if cursor.closed: cursor.fetchone = lambda: None + cursor.fetchall = lambda: [] return cursor |
