diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-03-17 15:15:10 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-03-17 15:15:10 +0000 |
commit | 05880daddd1a60c41267f395a55d01db943171eb (patch) | |
tree | 73e215404eb56b8d3fb2802e8cc09effcd83fd7f | |
parent | 86ff08dfea383cebd81347515c5b9affdfa589a1 (diff) | |
download | sqlalchemy-rel_0_4.tar.gz |
- Fixed SQLite reflection methods so that non-presentrel_0_4
cursor.description, which triggers an auto-cursor
close, will be detected so that no results doesn't
fail on recent versions of pysqlite which raise
an error when fetchone() called with no rows present.
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 15 |
2 files changed, 17 insertions, 5 deletions
@@ -44,6 +44,13 @@ CHANGES creates an arbitrarily large number of engines or dialects. There is a small performance penalty which will be resolved in 0.6. [ticket:1299] + +-sqlite + - Fixed SQLite reflection methods so that non-present + cursor.description, which triggers an auto-cursor + close, will be detected so that no results doesn't + fail on recent versions of pysqlite which raise + an error when fetchone() called with no rows present. - postgres - Added Index reflection support to Postgres, using a diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 04f59a839..d7d6d7a1f 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -333,7 +333,8 @@ class SQLiteDialect(default.DefaultDialect): else: pragma = "PRAGMA " qtable = quote(table_name) - cursor = connection.execute("%stable_info(%s)" % (pragma, qtable)) + cursor = _pragma_cursor(connection.execute("%stable_info(%s)" % (pragma, qtable))) + row = cursor.fetchone() # consume remaining rows, to work around @@ -351,7 +352,7 @@ class SQLiteDialect(default.DefaultDialect): pragma = "PRAGMA %s." % preparer.quote_identifier(table.schema) qtable = preparer.format_table(table, False) - c = connection.execute("%stable_info(%s)" % (pragma, qtable)) + c = _pragma_cursor(connection.execute("%stable_info(%s)" % (pragma, qtable))) found_table = False while True: row = c.fetchone() @@ -390,7 +391,7 @@ class SQLiteDialect(default.DefaultDialect): if not found_table: raise exceptions.NoSuchTableError(table.name) - c = connection.execute("%sforeign_key_list(%s)" % (pragma, qtable)) + c = _pragma_cursor(connection.execute("%sforeign_key_list(%s)" % (pragma, qtable))) fks = {} while True: row = c.fetchone() @@ -418,7 +419,7 @@ class SQLiteDialect(default.DefaultDialect): for name, value in fks.iteritems(): table.append_constraint(schema.ForeignKeyConstraint(value[0], value[1])) # check for UNIQUE indexes - c = connection.execute("%sindex_list(%s)" % (pragma, qtable)) + c = _pragma_cursor(connection.execute("%sindex_list(%s)" % (pragma, qtable))) unique_indexes = [] while True: row = c.fetchone() @@ -436,7 +437,11 @@ class SQLiteDialect(default.DefaultDialect): break cols.append(row[2]) - +def _pragma_cursor(cursor): + if cursor.closed or not cursor.cursor.description: + cursor._fetchone_impl = lambda: None + return cursor + class SQLiteCompiler(compiler.DefaultCompiler): functions = compiler.DefaultCompiler.functions.copy() functions.update ( |