From: Mike Bayer Date: Tue, 24 Apr 2012 20:25:20 +0000 (-0400) Subject: - [feature] Inspector.get_primary_keys() is X-Git-Tag: rel_0_8_0b1~452 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1fe06a551c28a6e0886f96334deebdee68d9fff9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [feature] Inspector.get_primary_keys() is deprecated; use Inspector.get_pk_constraint(). Courtesy Diana Clarke. [ticket:2422] - restored default get_primary_keys()/get_pk_constraint() wrapper to help maintain compatibility with third party dialects created against 0.6 or 0.7 --- 1fe06a551c28a6e0886f96334deebdee68d9fff9 diff --cc CHANGES index 8d3153bed1,88ddad8f8f..95ae66802c --- a/CHANGES +++ b/CHANGES @@@ -130,64 -27,8 +130,67 @@@ CHANGE - [bug] Fixed bug which would prevent OrderingList from being pickleable [ticket:2454]. Courtesy Jeff Dairiki + also in 0.7.7. + +- engine + - [feature] Added a new system + for registration of new dialects in-process + without using an entrypoint. See the + docs for "Registering New Dialects". + [ticket:2462] + + - [bug] The names of the columns on the + .c. attribute of a select().apply_labels() + is now based on _ instead + of _, for those columns + that have a distinctly named .key. + [ticket:2397] + ++ - [feature] Inspector.get_primary_keys() is ++ deprecated; use Inspector.get_pk_constraint(). ++ Courtesy Diana Clarke. [ticket:2422] - sql + - [feature] The Inspector object can now be + acquired using the new inspect() service, + part of [ticket:2208] + + - [feature] The column_reflect event now + accepts the Inspector object as the first + argument, preceding "table". Code which + uses the 0.7 version of this very new + event will need modification to add the + "inspector" object as the first argument. + [ticket:2418] + + - [feature] The behavior of column targeting + in result sets is now case sensitive by + default. SQLAlchemy for many years would + run a case-insensitive conversion on these values, + probably to alleviate early case sensitivity + issues with dialects like Oracle and + Firebird. These issues have been more cleanly + solved in more modern versions so the performance + hit of calling lower() on identifiers is removed. + The case insensitive comparisons can be re-enabled + by setting "case_insensitive=False" on + create_engine(). [ticket:2423] + + - [bug] All of UniqueConstraint, ForeignKeyConstraint, + CheckConstraint, and PrimaryKeyConstraint will + attach themselves to their parent table automatically + when they refer to a Table-bound Column object directly + (i.e. not just string column name), and refer to + one and only one Table. Prior to 0.8 this behavior + occurred for UniqueConstraint and PrimaryKeyConstraint, + but not ForeignKeyConstraint or CheckConstraint. + [ticket:2410] + + - [bug] column.label(None) now produces an + anonymous label, instead of returning the + column object itself, consistent with the behavior + of label(column, None). [ticket:2168] + - [bug] Removed warning when Index is created with no columns; while this might not be what the user intended, it is a valid use case diff --cc lib/sqlalchemy/engine/base.py index 93d2b19f10,10ce6d8190..a2695e3377 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@@ -259,17 -259,7 +259,19 @@@ class Dialect(object) raise NotImplementedError() + def get_primary_keys(self, connection, table_name, schema=None, **kw): + """Return information about primary keys in `table_name`. - - Given a :class:`.Connection`, a string - `table_name`, and an optional string `schema`, return primary - key information as a list of column names. - ++ ++ ++ Deprecated. This method is only called by the default ++ implementation of :meth:`get_pk_constraint()`. Dialects should ++ instead implement this method directly. ++ + """ ++ + raise NotImplementedError() + - def get_pk_constraint(self, table_name, schema=None, **kw): + def get_pk_constraint(self, connection, table_name, schema=None, **kw): """Return information about the primary key constraint on table_name`. diff --cc lib/sqlalchemy/engine/reflection.py index 4ad3595c3b,f94e9ee166..13a7e1b888 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@@ -26,12 -26,12 +26,13 @@@ methods such as get_table_names, get_co import sqlalchemy from sqlalchemy import exc, sql + from sqlalchemy import schema as sa_schema from sqlalchemy import util - from sqlalchemy.util import topological from sqlalchemy.types import TypeEngine - from sqlalchemy import schema as sa_schema + from sqlalchemy.util import deprecated + from sqlalchemy.util import topological - +from sqlalchemy import inspection +from sqlalchemy.engine.base import Connectable @util.decorator def cache(fn, self, con, *args, **kw): @@@ -240,11 -238,10 +243,9 @@@ class Inspector(object) primary key information as a list of column names. """ - pkeys = self.dialect.get_primary_keys(self.bind, table_name, schema, - info_cache=self.info_cache, - **kw) - - return pkeys - pkeys = self.dialect.get_pk_constraint(self.bind, table_name, schema, ++ return self.dialect.get_pk_constraint(self.bind, table_name, schema, + info_cache=self.info_cache, + **kw)['constrained_columns'] - return pkeys def get_pk_constraint(self, table_name, schema=None, **kw): """Return information about primary key constraint on `table_name`. @@@ -259,12 -256,12 +260,10 @@@ optional name of the primary key constraint. """ -- pkeys = self.dialect.get_pk_constraint(self.bind, table_name, schema, ++ return self.dialect.get_pk_constraint(self.bind, table_name, schema, info_cache=self.info_cache, **kw) -- return pkeys -- def get_foreign_keys(self, table_name, schema=None, **kw): """Return information about foreign_keys in `table_name`. @@@ -293,10 -290,10 +292,9 @@@ """ -- fk_defs = self.dialect.get_foreign_keys(self.bind, table_name, schema, ++ return self.dialect.get_foreign_keys(self.bind, table_name, schema, info_cache=self.info_cache, **kw) -- return fk_defs def get_indexes(self, table_name, schema=None, **kw): """Return information about indexes in `table_name`. @@@ -317,10 -314,10 +315,9 @@@ other options passed to the dialect's get_indexes() method. """ -- indexes = self.dialect.get_indexes(self.bind, table_name, ++ return self.dialect.get_indexes(self.bind, table_name, schema, info_cache=self.info_cache, **kw) -- return indexes def reflecttable(self, table, include_columns, exclude_columns=()): """Given a Table object, load its internal constructs based on introspection. diff --cc test/engine/test_reflection.py index 371a4c1b4b,cca67e64bc..6bfc3246a1 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@@ -1,14 -1,17 +1,15 @@@ - from test.lib.testing import eq_, assert_raises, assert_raises_message - import StringIO, unicodedata + import unicodedata + import sqlalchemy as sa + from sqlalchemy import exc as sa_exc from sqlalchemy import types as sql_types -from sqlalchemy import schema, events, event +from sqlalchemy import schema, events, event, inspect from sqlalchemy import MetaData, Integer, String - from test.lib.schema import Table, Column - import sqlalchemy as sa + from sqlalchemy.engine.reflection import Inspector from test.lib import ComparesTables, \ - testing, engines, AssertsCompiledSQL - from test.lib import fixtures + testing, engines, AssertsCompiledSQL, fixtures + from test.lib.schema import Table, Column + from test.lib.testing import eq_, assert_raises, assert_raises_message -create_inspector = Inspector.from_engine - metadata, users = None, None class ReflectionTest(fixtures.TestBase, ComparesTables): @@@ -1483,17 -1486,17 +1484,17 @@@ class ComponentReflectionTest(fixtures. self._test_get_columns(schema='test_schema', table_type='view') @testing.provide_metadata - def _test_get_primary_keys(self, schema=None): + def _test_get_pk_constraint(self, schema=None): meta = self.metadata - users, addresses, dingalings = createTables(meta, schema) + users, addresses, _ = createTables(meta, schema) meta.create_all() - insp = Inspector(meta.bind) + insp = inspect(meta.bind) - users_pkeys = insp.get_primary_keys(users.name, - schema=schema) + + users_cons = insp.get_pk_constraint(users.name, schema=schema) + users_pkeys = users_cons['constrained_columns'] eq_(users_pkeys, ['user_id']) - addr_cons = insp.get_pk_constraint(addresses.name, - schema=schema) + addr_cons = insp.get_pk_constraint(addresses.name, schema=schema) addr_pkeys = addr_cons['constrained_columns'] eq_(addr_pkeys, ['address_id'])