diff options
author | Benjamin Trofatter <bentrofatter@gmail.com> | 2012-10-30 17:47:04 -0500 |
---|---|---|
committer | Benjamin Trofatter <bentrofatter@gmail.com> | 2012-10-30 17:47:04 -0500 |
commit | 8fcd985e41fce74c26043985e497e6149f60b65b (patch) | |
tree | 1ad52039d7cbec228c36895d471d43a9f61dfb79 | |
parent | 05314919616cde74f4cb3393b25dbf5d062fa64c (diff) | |
download | sqlalchemy-8fcd985e41fce74c26043985e497e6149f60b65b.tar.gz |
Added sybase requirements to testing and improved view reflection.
-rw-r--r-- | lib/sqlalchemy/dialects/sybase/base.py | 50 | ||||
-rw-r--r-- | test/requirements.py | 23 |
2 files changed, 34 insertions, 39 deletions
diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index e62d37447..c858d012b 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -459,7 +459,7 @@ class SybaseDialect(default.DefaultDialect): FROM sysobjects o JOIN sysusers u ON o.uid=u.uid WHERE u.name = :schema_name AND o.name = :table_name - AND o.type = 'U' + AND o.type in ('U', 'V') """) # Py2K @@ -547,6 +547,7 @@ class SybaseDialect(default.DefaultDialect): @reflection.cache def get_foreign_keys(self, connection, table_name, schema=None, **kw): + table_id = self.get_table_id(connection, table_name, schema, info_cache=kw.get("info_cache")) @@ -554,7 +555,7 @@ class SybaseDialect(default.DefaultDialect): column_cache = {} foreign_keys = [] - table_cache[table_id] = table_name + table_cache[table_id] = {"name": table_name, "schema": schema} COLUMN_SQL = text(""" SELECT c.colid AS id, c.name AS name @@ -591,7 +592,7 @@ class SybaseDialect(default.DefaultDialect): table_id=table_id) REFTABLE_SQL = text(""" - SELECT o.id AS id, o.name AS name, u.name AS 'schema' + SELECT o.name AS name, u.name AS 'schema' FROM sysobjects o JOIN sysusers u ON o.uid = u.uid WHERE o.id = :table_id """) @@ -604,9 +605,12 @@ class SybaseDialect(default.DefaultDialect): c = connection.execute(REFTABLE_SQL, table_id=reftable_id) reftable = c.fetchone() c.close() - table_cache[reftable_id] = {"name": reftable["name"], - "schema": reftable["schema"]} - + table_info = {"name": reftable["name"], "schema": None} + if (schema is not None or + reftable["schema"] != self.default_schema_name): + table_info["schema"] = reftable["schema"] + + table_cache[reftable_id] = table_info results = connection.execute(COLUMN_SQL, table_id=reftable_id) reftable_columns = {} for col in results: @@ -621,7 +625,7 @@ class SybaseDialect(default.DefaultDialect): for i in range(1, r["count"]+1): constrained_columns.append(columns[r["fokey%i" % i]]) referred_columns.append(reftable_columns[r["refkey%i" % i]]) - + fk_info = { "constrained_columns": constrained_columns, "referred_schema": reftable["schema"], @@ -665,7 +669,6 @@ class SybaseDialect(default.DefaultDialect): AND o.id = :table_id AND (i.status & 2048) = 0 AND i.indid BETWEEN 1 AND 254 - AND o.type = 'U' """) results = connection.execute(INDEX_SQL, table_id=table_id) @@ -711,7 +714,6 @@ class SybaseDialect(default.DefaultDialect): AND o.id = :table_id AND (i.status & 2048) = 2048 AND i.indid BETWEEN 1 AND 254 - AND o.type = 'U' """) results = connection.execute(PK_SQL, table_id=table_id) @@ -794,27 +796,9 @@ class SybaseDialect(default.DefaultDialect): return [v["name"] for v in views] def has_table(self, connection, table_name, schema=None): - if schema is None: - schema = self.default_schema_name - - HAS_TABLE_SQL = text(""" - SELECT o.name - FROM sysobjects o JOIN sysusers u ON o.uid = u.uid - WHERE o.name = :table_name - AND u.name = :schema_name - AND o.type = 'U' - """) - - # Py2K - if isinstance(schema, unicode): - schema = schema.encode("ascii") - if isinstance(table_name, unicode): - table_name = table_name.encode("ascii") - # end Py2K - result = connection.execute(HAS_TABLE_SQL, table_name=table_name, - schema_name=schema) - return result.scalar() is not None - - #def reflecttable(self, connection, table, include_columns): - # raise NotImplementedError() - + try: + self.get_table_id(connection, table_name, schema) + except exc.NoSuchTableError: + return False + else: + return True diff --git a/test/requirements.py b/test/requirements.py index b88b77432..6e28aeac7 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -293,16 +293,22 @@ class DefaultRequirements(SuiteRequirements): def empty_strings_varchar(self): """target database can persist/return an empty string with a varchar.""" - return fails_if("oracle", 'oracle converts empty ' - 'strings to a blank space') + return fails_if(["oracle"], + 'oracle converts empty strings to a blank space') @property def empty_strings_text(self): """target database can persist/return an empty string with an unbounded text.""" - return fails_if("oracle", 'oracle converts empty ' - 'strings to a blank space') + return fails_if(["oracle"], + 'oracle converts empty strings to a blank space') + + @property + def unicode_data(self): + return skip_if([ + no_support("sybase", "no unicode driver support") + ]) @property def unicode_connections(self): @@ -337,7 +343,6 @@ class DefaultRequirements(SuiteRequirements): lambda: not self._has_cextensions(), "C extensions not installed" ) - @property def emulated_lastrowid(self): """"target dialect retrieves cursor.lastrowid or an equivalent @@ -348,6 +353,12 @@ class DefaultRequirements(SuiteRequirements): 'mssql+pyodbc', 'mssql+mxodbc') @property + def implements_get_lastrowid(self): + return skip_if([ + no_support('sybase', 'not supported by database'), + ]) + + @property def dbapi_lastrowid(self): """"target backend includes a 'lastrowid' accessor on the DBAPI cursor object. @@ -372,7 +383,7 @@ class DefaultRequirements(SuiteRequirements): def reflects_pk_names(self): """Target driver reflects the name of primary key constraints.""" - return fails_on_everything_except('postgresql', 'oracle') + return fails_on_everything_except('postgresql', 'oracle', 'sybase') @property def python2(self): |