From: Mike Bayer Date: Tue, 17 Mar 2009 15:09:49 +0000 (+0000) Subject: - Fixed SQLite reflection methods so that non-present X-Git-Tag: rel_0_5_3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ecf84f5adb428f814cd18b47ac65d133112cbf0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/CHANGES b/CHANGES index 503031d411..3e1c6f9ecd 100644 --- a/CHANGES +++ b/CHANGES @@ -112,6 +112,13 @@ CHANGES 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 - Index reflection won't fail when an index with multiple expressions is encountered. diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 8b46132f3e..77eb30ff81 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -439,7 +439,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 @@ -457,7 +458,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() @@ -496,7 +497,7 @@ class SQLiteDialect(default.DefaultDialect): if not found_table: raise exc.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() @@ -524,7 +525,7 @@ class SQLiteDialect(default.DefaultDialect): for name, value in fks.iteritems(): table.append_constraint(schema.ForeignKeyConstraint(value[0], value[1], link_to_name=True)) # 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() @@ -542,7 +543,11 @@ class SQLiteDialect(default.DefaultDialect): break cols.append(row[2]) - +def _pragma_cursor(cursor): + if cursor.closed: + cursor._fetchone_impl = lambda: None + return cursor + class SQLiteCompiler(compiler.DefaultCompiler): functions = compiler.DefaultCompiler.functions.copy() functions.update (