]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [feature] Inspector.get_primary_keys() is
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 20:25:20 +0000 (16:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 20:25:20 +0000 (16:25 -0400)
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

1  2 
CHANGES
lib/sqlalchemy/dialects/informix/base.py
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/reflection.py
test/engine/test_reflection.py

diff --cc CHANGES
index 8d3153bed1872f6455ac10826f3f264eaa107104,88ddad8f8f38c33493ff6d375b96e663d1f9e004..95ae66802c9814e8b2c391ea63abf2dcc3339b5f
+++ 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 <tablename>_<colkey> instead
 +    of <tablename>_<colname>, 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 
Simple merge
Simple merge
index 93d2b19f10e32b490b8743e369668f6e507952d4,10ce6d819077d6e0bdbc158d296cbe413bb1e816..a2695e3377bba2663771590aeb7cd6781e2abebf
@@@ -259,17 -259,7 +259,19 @@@ class Dialect(object)
  
          raise NotImplementedError()
  
-         Given a :class:`.Connection`, a string
-         `table_name`, and an optional string `schema`, return primary
-         key information as a list of column names.
 +    def get_primary_keys(self, connection, table_name, schema=None, **kw):
 +        """Return information about primary keys in `table_name`.
-     def get_pk_constraint(self, table_name, schema=None, **kw):
++        
++        
++        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, connection, table_name, schema=None, **kw):
          """Return information about the primary key constraint on
          table_name`.
  
index 4ad3595c3b06bfc813acbd5b7079d5fdb85261ba,f94e9ee1663176edde592fa5bfcb062cf7f09368..13a7e1b888d5ca167d3f2ca7eb2ff046d4926601
@@@ -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`.
            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`.
  
          """
  
--        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`.
            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.
index 371a4c1b4b62e4bc5108764ebdce9f4e382bdc6a,cca67e64bc198d23347046d14a8b1f2dc35f901c..6bfc3246a16218d5fd392e6b9216bff1cf84909e
@@@ -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'])