From a7d7941d3ebafd16f603785c4677e371c675d1c0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 10 Aug 2015 10:07:17 -0400 Subject: [PATCH] - Fixed two issues regarding Sybase reflection, allowing tables without primary keys to be reflected as well as ensured that a SQL statement involved in foreign key detection is pre-fetched up front to avoid driver issues upon nested queries. Fixes here courtesy Eugene Zapolsky; note that we cannot currently test Sybase to locally verify these changes. fixes #3508 fixes #3509 --- doc/build/changelog/changelog_10.rst | 11 +++++++++++ lib/sqlalchemy/dialects/sybase/base.py | 15 +++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 593c26e001..ad9c1473d0 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,17 @@ .. changelog:: :version: 1.0.9 + .. change:: + :tags: bug, sybase + :tickets: 3508, 3509 + + Fixed two issues regarding Sybase reflection, allowing tables + without primary keys to be reflected as well as ensured that + a SQL statement involved in foreign key detection is pre-fetched up + front to avoid driver issues upon nested queries. Fixes here + courtesy Eugene Zapolsky; note that we cannot currently test + Sybase to locally verify these changes. + .. change:: :tags: bug, postgresql :pullreq: github:190 diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index ae0473a3ef..b3f8e307af 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -608,8 +608,8 @@ class SybaseDialect(default.DefaultDialect): FROM sysreferences r JOIN sysobjects o on r.tableid = o.id WHERE r.tableid = :table_id """) - referential_constraints = connection.execute(REFCONSTRAINT_SQL, - table_id=table_id) + referential_constraints = connection.execute( + REFCONSTRAINT_SQL, table_id=table_id).fetchall() REFTABLE_SQL = text(""" SELECT o.name AS name, u.name AS 'schema' @@ -740,10 +740,13 @@ class SybaseDialect(default.DefaultDialect): results.close() constrained_columns = [] - for i in range(1, pks["count"] + 1): - constrained_columns.append(pks["pk_%i" % (i,)]) - return {"constrained_columns": constrained_columns, - "name": pks["name"]} + if pks: + for i in range(1, pks["count"] + 1): + constrained_columns.append(pks["pk_%i" % (i,)]) + return {"constrained_columns": constrained_columns, + "name": pks["name"]} + else: + return {"constrained_columns": [], "name": None} @reflection.cache def get_schema_names(self, connection, **kw): -- 2.47.3