diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-02 14:23:42 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-02 14:23:42 -0500 |
commit | 350aed3fdb9f1e73e69655e53f44ca6a91c196da (patch) | |
tree | 3d2a128667b5f6ca6d0b4e1f4865fc98aac6b60b /lib/sqlalchemy/engine | |
parent | 71f92436bdc86f30e2c21d8f5244733601e8c39e (diff) | |
download | sqlalchemy-350aed3fdb9f1e73e69655e53f44ca6a91c196da.tar.gz |
- whitespace removal bonanza
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r-- | lib/sqlalchemy/engine/__init__.py | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 344 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/ddl.py | 14 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/default.py | 150 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 54 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/strategies.py | 22 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/threadlocal.py | 28 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/url.py | 10 |
8 files changed, 316 insertions, 316 deletions
diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py index 9dd7f0653..aebf35436 100644 --- a/lib/sqlalchemy/engine/__init__.py +++ b/lib/sqlalchemy/engine/__init__.py @@ -51,7 +51,7 @@ url.py """ # not sure what this was used for -#import sqlalchemy.databases +#import sqlalchemy.databases from sqlalchemy.engine.base import ( BufferedColumnResultProxy, @@ -174,17 +174,17 @@ def create_engine(*args, **kwargs): :param execution_options: Dictionary execution options which will be applied to all connections. See :meth:`~sqlalchemy.engine.base.Connection.execution_options` - + :param label_length=None: optional integer value which limits the size of dynamically generated column labels to that many characters. If less than 6, labels are generated as "_(counter)". If ``None``, the value of ``dialect.max_identifier_length`` is used instead. - + :param listeners: A list of one or more :class:`~sqlalchemy.interfaces.PoolListener` objects which will receive connection pool events. - + :param logging_name: String identifier which will be used within the "name" field of logging records generated within the "sqlalchemy.engine" logger. Defaults to a hexstring of the @@ -246,7 +246,7 @@ def create_engine(*args, **kwargs): :param strategy='plain': selects alternate engine implementations. Currently available is the ``threadlocal`` strategy, which is described in :ref:`threadlocal_strategy`. - + """ strategy = kwargs.pop('strategy', default_strategy) diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 49355bf65..eb48c29d6 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -71,19 +71,19 @@ class Dialect(object): a tuple containing a version number for the DB backend in use. This value is only available for supporting dialects, and is typically populated during the initial connection to the database. - + default_schema_name the name of the default schema. This value is only available for supporting dialects, and is typically populated during the initial connection to the database. - + execution_ctx_cls a :class:`ExecutionContext` class used to handle statement execution execute_sequence_format either the 'tuple' or 'list' type, depending on what cursor.execute() accepts for the second argument (they vary). - + preparer a :class:`~sqlalchemy.sql.compiler.IdentifierPreparer` class used to quote identifiers. @@ -115,7 +115,7 @@ class Dialect(object): True if 'implicit' primary key functions must be executed separately in order to get their value. This is currently oriented towards Postgresql. - + implicit_returning use RETURNING or equivalent during INSERT execution in order to load newly generated primary keys and other column defaults in one execution, @@ -123,7 +123,7 @@ class Dialect(object): If an insert statement has returning() specified explicitly, the "implicit" functionality is not used and inserted_primary_key will not be available. - + dbapi_type_map A mapping of DB-API type objects present in this Dialect's DB-API implementation mapped to TypeEngine implementations used @@ -143,17 +143,17 @@ class Dialect(object): supports_default_values Indicates if the construct ``INSERT INTO tablename DEFAULT VALUES`` is supported - + supports_sequences Indicates if the dialect supports CREATE SEQUENCE or similar. - + sequences_optional If True, indicates if the "optional" flag on the Sequence() construct should signal to not generate a CREATE SEQUENCE. Applies only to dialects that support sequences. Currently used only to allow Postgresql SERIAL to be used on a column that specifies Sequence() for usage on other backends. - + supports_native_enum Indicates if the dialect supports a native ENUM construct. This will prevent types.Enum from generating a CHECK @@ -163,7 +163,7 @@ class Dialect(object): Indicates if the dialect supports a native boolean construct. This will prevent types.Boolean from generating a CHECK constraint when that type is used. - + """ def create_connect_args(self, url): @@ -172,7 +172,7 @@ class Dialect(object): Given a :class:`~sqlalchemy.engine.url.URL` object, returns a tuple consisting of a `*args`/`**kwargs` suitable to send directly to the dbapi's connect function. - + """ raise NotImplementedError() @@ -187,7 +187,7 @@ class Dialect(object): The returned result is cached *per dialect class* so can contain no dialect-instance state. - + """ raise NotImplementedError() @@ -198,13 +198,13 @@ class Dialect(object): Allows dialects to configure options based on server version info or other properties. - + The connection passed here is a SQLAlchemy Connection object, with full capabilities. - + The initalize() method of the base dialect should be called via super(). - + """ pass @@ -217,12 +217,12 @@ class Dialect(object): properties from the database. If include_columns (a list or set) is specified, limit the autoload to the given column names. - + The default implementation uses the :class:`~sqlalchemy.engine.reflection.Inspector` interface to provide the output, building upon the granular table/column/ constraint etc. methods of :class:`Dialect`. - + """ raise NotImplementedError() @@ -356,7 +356,7 @@ class Dialect(object): def normalize_name(self, name): """convert the given name to lowercase if it is detected as case insensitive. - + this method is only used if the dialect defines requires_name_normalize=True. @@ -366,13 +366,13 @@ class Dialect(object): def denormalize_name(self, name): """convert the given name to a case insensitive identifier for the backend if it is an all-lowercase name. - + this method is only used if the dialect defines requires_name_normalize=True. """ raise NotImplementedError() - + def has_table(self, connection, table_name, schema=None): """Check the existence of a particular table in the database. @@ -396,15 +396,15 @@ class Dialect(object): def _get_server_version_info(self, connection): """Retrieve the server version info from the given connection. - + This is used by the default implementation to populate the "server_version_info" attribute and is called exactly once upon first connect. - + """ raise NotImplementedError() - + def _get_default_schema_name(self, connection): """Return the string name of the currently selected schema from the given connection. @@ -412,7 +412,7 @@ class Dialect(object): This is used by the default implementation to populate the "default_schema_name" attribute and is called exactly once upon first connect. - + """ raise NotImplementedError() @@ -512,7 +512,7 @@ class Dialect(object): The callable accepts a single argument "conn" which is the DBAPI connection itself. It has no return value. - + This is used to set dialect-wide per-connection options such as isolation modes, unicode modes, etc. @@ -645,7 +645,7 @@ class ExecutionContext(object): in some dialects; this is indicated by the ``supports_sane_rowcount`` and ``supports_sane_multi_rowcount`` dialect attributes. - + """ raise NotImplementedError() @@ -691,13 +691,13 @@ class Compiled(object): @property def sql_compiler(self): """Return a Compiled that is capable of processing SQL expressions. - + If this compiler is one, it would likely just return 'self'. - + """ - + raise NotImplementedError() - + def process(self, obj, **kwargs): return obj._compiler_dispatch(self, **kwargs) @@ -705,7 +705,7 @@ class Compiled(object): """Return the string text of the generated SQL or DDL.""" return self.string or '' - + def construct_params(self, params=None): """Return the bind params for this compiled object. @@ -793,7 +793,7 @@ class Connection(Connectable): shared among threads using properly synchronized access, it is still possible that the underlying DBAPI connection may not support shared access between threads. Check the DBAPI documentation for details. - + The Connection object represents a single dbapi connection checked out from the connection pool. In this state, the connection pool has no affect upon the connection, including its expiration or timeout state. For the @@ -803,9 +803,9 @@ class Connection(Connectable): .. index:: single: thread safety; Connection - + """ - + def __init__(self, engine, connection=None, close_with_result=False, _branch=False, _execution_options=None): """Construct a new Connection. @@ -813,7 +813,7 @@ class Connection(Connectable): The constructor here is not public and is only called only by an :class:`.Engine`. See :meth:`.Engine.connect` and :meth:`.Engine.contextual_connect` methods. - + """ self.engine = engine self.dialect = engine.dialect @@ -850,21 +850,21 @@ class Connection(Connectable): c = self.__class__.__new__(self.__class__) c.__dict__ = self.__dict__.copy() return c - + def execution_options(self, **opt): """ Set non-SQL options for the connection which take effect during execution. - + The method returns a copy of this :class:`Connection` which references the same underlying DBAPI connection, but also defines the given execution options which will take effect for a call to :meth:`execute`. As the new :class:`Connection` references the same underlying resource, it is probably best to ensure that the copies would be discarded immediately, which is implicit if used as in:: - + result = connection.execution_options(stream_results=True).\ execute(stmt) - + The options are the same as those accepted by :meth:`sqlalchemy.sql.expression.Executable.execution_options`. @@ -872,7 +872,7 @@ class Connection(Connectable): c = self._clone() c._execution_options = c._execution_options.union(opt) return c - + @property def closed(self): """Return True if this connection is closed.""" @@ -894,7 +894,7 @@ class Connection(Connectable): return self.__connection except AttributeError: return self._revalidate_connection() - + def _revalidate_connection(self): if self.__invalid: if self.__transaction is not None: @@ -905,13 +905,13 @@ class Connection(Connectable): self.__invalid = False return self.__connection raise exc.ResourceClosedError("This Connection is closed") - + @property def _connection_is_valid(self): # use getattr() for is_valid to support exceptions raised in # dialect initializer, where the connection is not wrapped in # _ConnectionFairy - + return getattr(self.__connection, 'is_valid', False) @property @@ -960,7 +960,7 @@ class Connection(Connectable): """ if self.invalidated: return - + if self.closed: raise exc.ResourceClosedError("This Connection is closed") @@ -968,8 +968,8 @@ class Connection(Connectable): self.__connection.invalidate(exception) del self.__connection self.__invalid = True - - + + def detach(self): """Detach the underlying DB-API connection from its connection pool. @@ -1140,7 +1140,7 @@ class Connection(Connectable): self.__invalid = False del self.__connection self.__transaction = None - + def scalar(self, object, *multiparams, **params): """Executes and returns the first column of the first row. @@ -1151,9 +1151,9 @@ class Connection(Connectable): def execute(self, object, *multiparams, **params): """Executes the given construct and returns a :class:`.ResultProxy`. - + The construct can be one of: - + * a textual SQL string * any :class:`.ClauseElement` construct that is also a subclass of :class:`.Executable`, such as a @@ -1164,7 +1164,7 @@ class Connection(Connectable): * a :class:`.DDLElement` object * a :class:`.DefaultGenerator` object * a :class:`.Compiled` object - + """ for c in type(object).__mro__: @@ -1186,7 +1186,7 @@ class Connection(Connectable): In the case of 'raw' execution which accepts positional parameters, it may be a list of tuples or lists. - + """ if not multiparams: @@ -1219,28 +1219,28 @@ class Connection(Connectable): def _execute_default(self, default, multiparams, params): """Execute a schema.ColumnDefault object.""" - + try: try: conn = self.__connection except AttributeError: conn = self._revalidate_connection() - + dialect = self.dialect ctx = dialect.execution_ctx_cls._init_default( dialect, self, conn) except Exception, e: self._handle_dbapi_exception(e, None, None, None, None) raise - + ret = ctx._exec_default(default) if self.should_close_with_result: self.close() return ret - + def _execute_ddl(self, ddl, params, multiparams): """Execute a schema.DDL object.""" - + dialect = self.dialect return self._execute_context( dialect, @@ -1252,7 +1252,7 @@ class Connection(Connectable): def _execute_clauseelement(self, elem, multiparams, params): """Execute a sql.ClauseElement object.""" - + params = self.__distill_params(multiparams, params) if params: keys = params[0].keys() @@ -1298,7 +1298,7 @@ class Connection(Connectable): def _execute_text(self, statement, multiparams, params): """Execute a string SQL statement.""" - + dialect = self.dialect parameters = self.__distill_params(multiparams, params) return self._execute_context( @@ -1316,13 +1316,13 @@ class Connection(Connectable): statement, parameters, *args): """Create an :class:`.ExecutionContext` and execute, returning a :class:`.ResultProxy`.""" - + try: try: conn = self.__connection except AttributeError: conn = self._revalidate_connection() - + context = constructor(dialect, self, conn, *args) except Exception, e: self._handle_dbapi_exception(e, @@ -1332,14 +1332,14 @@ class Connection(Connectable): if context.compiled: context.pre_exec() - + cursor, statement, parameters = context.cursor, \ context.statement, \ context.parameters - + if not context.executemany: parameters = parameters[0] - + if self._before_cursor_execute: statement, parameters = self._before_cursor_execute( context, @@ -1376,13 +1376,13 @@ class Connection(Connectable): if self._after_cursor_execute: self._after_cursor_execute(context, cursor, statement, parameters) - + if context.compiled: context.post_exec() - + if context.isinsert and not context.executemany: context.post_insert() - + # create a resultproxy, get rowcount/implicit RETURNING # rows, close cursor if no further results pending result = context.get_result_proxy() @@ -1399,25 +1399,25 @@ class Connection(Connectable): # such as kintersbasdb, mxodbc), result.rowcount result.close(_autoclose_connection=False) - + if self.__transaction is None and context.should_autocommit: self._commit_impl() - + if result.closed and self.should_close_with_result: self.close() - + return result def _cursor_execute(self, cursor, statement, parameters): """Execute a statement + params on the given cursor. Adds appropriate logging and exception handling. - + This method is used by DefaultDialect for special-case - executions, such as for sequences and column defaults. + executions, such as for sequences and column defaults. The path of statement execution in the majority of cases terminates at _execute_context(). - + """ if self._echo: self.engine.logger.info(statement) @@ -1439,7 +1439,7 @@ class Connection(Connectable): def _safe_close_cursor(self, cursor): """Close the given cursor, catching exceptions and turning into log warnings. - + """ try: cursor.close() @@ -1452,7 +1452,7 @@ class Connection(Connectable): if isinstance(e, (SystemExit, KeyboardInterrupt)): raise - + def _handle_dbapi_exception(self, e, statement, @@ -1499,7 +1499,7 @@ class Connection(Connectable): connection_invalidated=is_disconnect), \ None, sys.exc_info()[2] # end Py2K - + finally: del self._reentrant_error @@ -1538,9 +1538,9 @@ class Connection(Connectable): This is a shortcut for explicitly calling `begin()` and `commit()` and optionally `rollback()` when exceptions are raised. The given `*args` and `**kwargs` will be passed to the function. - + See also transaction() on engine. - + """ trans = self.begin() @@ -1564,7 +1564,7 @@ class Transaction(object): also implements a context manager interface so that the Python ``with`` statement can be used with the :meth:`.Connection.begin` method. - + The Transaction object is **not** threadsafe. .. index:: @@ -1575,7 +1575,7 @@ class Transaction(object): """The constructor for :class:`.Transaction` is private and is called from within the :class:`.Connection.begin` implementation. - + """ self.connection = connection self._parent = parent or self @@ -1590,7 +1590,7 @@ class Transaction(object): This is used to cancel a Transaction without affecting the scope of an enclosing transaction. - + """ if not self._parent.is_active: return @@ -1599,7 +1599,7 @@ class Transaction(object): def rollback(self): """Roll back this :class:`.Transaction`. - + """ if not self._parent.is_active: return @@ -1611,7 +1611,7 @@ class Transaction(object): def commit(self): """Commit this :class:`.Transaction`.""" - + if not self._parent.is_active: raise exc.InvalidRequestError("This transaction is inactive") self._do_commit() @@ -1679,13 +1679,13 @@ class TwoPhaseTransaction(Transaction): def _do_commit(self): self.connection._commit_twophase_impl(self.xid, self._is_prepared) - + class Engine(Connectable, log.Identified): """ Connects a :class:`~sqlalchemy.pool.Pool` and :class:`~sqlalchemy.engine.base.Dialect` together to provide a source of database connectivity and behavior. - + An :class:`Engine` object is instantiated publically using the :func:`~sqlalchemy.create_engine` function. @@ -1693,7 +1693,7 @@ class Engine(Connectable, log.Identified): _execution_options = util.frozendict() Connection = Connection - + def __init__(self, pool, dialect, url, logging_name=None, echo=None, proxy=None, execution_options=None @@ -1711,17 +1711,17 @@ class Engine(Connectable, log.Identified): if execution_options: self.update_execution_options(**execution_options) - + dispatch = event.dispatcher(events.EngineEvents) - + def update_execution_options(self, **opt): """update the execution_options dictionary of this :class:`Engine`. - + For details on execution_options, see :meth:`Connection.execution_options` as well as :meth:`sqlalchemy.sql.expression.Executable.execution_options`. - - + + """ self._execution_options = \ self._execution_options.union(opt) @@ -1751,23 +1751,23 @@ class Engine(Connectable, log.Identified): A new connection pool is created immediately after the old one has been disposed. This new pool, like all SQLAlchemy connection pools, does not make any actual connections to the database until one is - first requested. - + first requested. + This method has two general use cases: - + * When a dropped connection is detected, it is assumed that all connections held by the pool are potentially dropped, and the entire pool is replaced. - + * An application may want to use :meth:`dispose` within a test suite that is creating multiple engines. - + It is critical to note that :meth:`dispose` does **not** guarantee that the application will release all open database connections - only - those connections that are checked into the pool are closed. + those connections that are checked into the pool are closed. Connections which remain checked out or have been detached from the engine are not affected. - + """ self.pool.dispose() self.pool = self.pool.recreate() @@ -1804,11 +1804,11 @@ class Engine(Connectable, log.Identified): def text(self, text, *args, **kwargs): """Return a :func:`~sqlalchemy.sql.expression.text` construct, bound to this engine. - + This is equivalent to:: - + text("SELECT * FROM table", bind=engine) - + """ return expression.text(text, bind=self, *args, **kwargs) @@ -1832,13 +1832,13 @@ class Engine(Connectable, log.Identified): This is a shortcut for explicitly calling `begin()` and `commit()` and optionally `rollback()` when exceptions are raised. The given `*args` and `**kwargs` will be passed to the function. - + The connection used is that of contextual_connect(). - + See also the similar method on Connection itself. - + """ - + conn = self.contextual_connect() try: return conn.transaction(callable_, *args, **kwargs) @@ -1854,10 +1854,10 @@ class Engine(Connectable, log.Identified): def execute(self, statement, *multiparams, **params): """Executes the given construct and returns a :class:`.ResultProxy`. - + The arguments are the same as those used by :meth:`.Connection.execute`. - + Here, a :class:`.Connection` is acquired using the :meth:`~.Engine.contextual_connect` method, and the statement executed with that connection. The returned :class:`.ResultProxy` is flagged @@ -1865,7 +1865,7 @@ class Engine(Connectable, log.Identified): underlying cursor is closed, the :class:`.Connection` created here will also be closed, which allows its associated DBAPI connection resource to be returned to the connection pool. - + """ connection = self.contextual_connect(close_with_result=True) @@ -1884,29 +1884,29 @@ class Engine(Connectable, log.Identified): def connect(self, **kwargs): """Return a new :class:`.Connection` object. - + The :class:`.Connection`, upon construction, will procure a DBAPI connection from the :class:`.Pool` referenced by this :class:`.Engine`, returning it back to the :class:`.Pool` after the :meth:`.Connection.close` method is called. - + """ return self.Connection(self, **kwargs) def contextual_connect(self, close_with_result=False, **kwargs): """Return a :class:`.Connection` object which may be part of some ongoing context. - + By default, this method does the same thing as :meth:`.Engine.connect`. Subclasses of :class:`.Engine` may override this method to provide contextual behavior. :param close_with_result: When True, the first :class:`.ResultProxy` created by the :class:`.Connection` will call the :meth:`.Connection.close` method - of that connection as soon as any pending result rows are exhausted. + of that connection as soon as any pending result rows are exhausted. This is used to supply the "connectionless execution" behavior provided by the :meth:`.Engine.execute` method. - + """ return self.Connection(self, @@ -1960,25 +1960,25 @@ class Engine(Connectable, log.Identified): def _listener_connection_cls(cls, dispatch): """Produce a wrapper for :class:`.Connection` which will apply event dispatch to each method. - + :class:`.Connection` does not provide event dispatch built in so that method call overhead is avoided in the absense of any listeners. - + """ class EventListenerConnection(cls): def execute(self, clauseelement, *multiparams, **params): for fn in dispatch.before_execute: clauseelement, multiparams, params = \ fn(self, clauseelement, multiparams, params) - + ret = super(EventListenerConnection, self).\ execute(clauseelement, *multiparams, **params) for fn in dispatch.after_execute: fn(self, clauseelement, multiparams, params, ret) - + return ret - + def _execute_clauseelement(self, clauseelement, multiparams=None, params=None): return self.execute(clauseelement, @@ -1992,7 +1992,7 @@ def _listener_connection_cls(cls, dispatch): fn(self, cursor, statement, parameters, context, context.executemany) return statement, parameters - + def _after_cursor_execute(self, context, cursor, statement, parameters): dispatch.after_cursor_execute(self, cursor, @@ -2000,12 +2000,12 @@ def _listener_connection_cls(cls, dispatch): parameters, context, context.executemany) - + def _begin_impl(self): dispatch.begin(self) return super(EventListenerConnection, self).\ _begin_impl() - + def _rollback_impl(self): dispatch.rollback(self) return super(EventListenerConnection, self).\ @@ -2020,17 +2020,17 @@ def _listener_connection_cls(cls, dispatch): dispatch.savepoint(self, name) return super(EventListenerConnection, self).\ _savepoint_impl(name=name) - + def _rollback_to_savepoint_impl(self, name, context): dispatch.rollback_savepoint(self, name, context) return super(EventListenerConnection, self).\ _rollback_to_savepoint_impl(name, context) - + def _release_savepoint_impl(self, name, context): dispatch.release_savepoint(self, name, context) return super(EventListenerConnection, self).\ _release_savepoint_impl(name, context) - + def _begin_twophase_impl(self, xid): dispatch.begin_twophase(self, xid) return super(EventListenerConnection, self).\ @@ -2203,12 +2203,12 @@ try: Sequence.register(RowProxy) except ImportError: pass - + class ResultMetaData(object): """Handle cursor.description, applying additional info from an execution context.""" - + def __init__(self, parent, metadata): self._processors = processors = [] @@ -2224,7 +2224,7 @@ class ResultMetaData(object): for i, rec in enumerate(metadata): colname = rec[0] coltype = rec[1] - + if dialect.description_encoding: colname = dialect._description_decoder(colname) @@ -2239,14 +2239,14 @@ class ResultMetaData(object): colname, None, typemap.get(coltype, types.NULLTYPE) processor = type_._cached_result_processor(dialect, coltype) - + processors.append(processor) rec = (processor, i) # indexes as keys. This is only needed for the Python version of # RowProxy (the C version uses a faster path for integer indexes). keymap[i] = rec - + # Column names as keys if keymap.setdefault(name.lower(), rec) is not rec: # We do not raise an exception directly because several @@ -2257,7 +2257,7 @@ class ResultMetaData(object): if dialect.requires_name_normalize: colname = dialect.normalize_name(colname) - + self.keys.append(colname) if obj: for o in obj: @@ -2266,19 +2266,19 @@ class ResultMetaData(object): if parent._echo: context.engine.logger.debug( "Col %r", tuple(x[0] for x in metadata)) - + def _set_keymap_synonym(self, name, origname): """Set a synonym for the given name. - + Some dialects (SQLite at the moment) may use this to adjust the column names that are significant within a row. - + """ rec = (processor, i) = self._keymap[origname.lower()] if self._keymap.setdefault(name, rec) is not rec: self._keymap[name] = (processor, None) - + def _key_fallback(self, key): map = self._keymap result = None @@ -2318,7 +2318,7 @@ class ResultMetaData(object): ), 'keys': self.keys } - + def __setstate__(self, state): # the row has been processed at pickling time so we don't need any # processor anymore @@ -2329,7 +2329,7 @@ class ResultMetaData(object): self.keys = state['keys'] self._echo = False - + class ResultProxy(object): """Wraps a DB-API cursor object to provide easier access to row columns. @@ -2354,7 +2354,7 @@ class ResultProxy(object): _process_row = RowProxy out_parameters = None _can_close_connection = False - + def __init__(self, context): self.context = context self.dialect = context.dialect @@ -2371,23 +2371,23 @@ class ResultProxy(object): self._metadata = None else: self._metadata = ResultMetaData(self, metadata) - + def keys(self): """Return the current set of string keys for rows.""" if self._metadata: return self._metadata.keys else: return [] - + @util.memoized_property def rowcount(self): """Return the 'rowcount' for this result. - + The 'rowcount' reports the number of rows affected by an UPDATE or DELETE statement. It has *no* other uses and is not intended to provide the number of rows present from a SELECT. - + Note that this row count may not be properly implemented in some dialects; this is indicated by :meth:`~sqlalchemy.engine.base.ResultProxy.supports_sane_rowcount()` @@ -2395,37 +2395,37 @@ class ResultProxy(object): :meth:`~sqlalchemy.engine.base.ResultProxy.supports_sane_multi_rowcount()`. ``rowcount()`` also may not work at this time for a statement that uses ``returning()``. - + """ return self.context.rowcount @property def lastrowid(self): """return the 'lastrowid' accessor on the DBAPI cursor. - + This is a DBAPI specific method and is only functional for those backends which support it, for statements where it is appropriate. It's behavior is not consistent across backends. - + Usage of this method is normally unnecessary; the :attr:`~ResultProxy.inserted_primary_key` attribute provides a tuple of primary key values for a newly inserted row, regardless of database backend. - + """ return self._saved_cursor.lastrowid - + def _cursor_description(self): """May be overridden by subclasses.""" - + return self._saved_cursor.description - + def close(self, _autoclose_connection=True): """Close this ResultProxy. Closes the underlying DBAPI cursor corresponding to the execution. - + Note that any data cached within this ResultProxy is still available. For some types of results, this may include buffered rows. @@ -2437,7 +2437,7 @@ class ResultProxy(object): * all result rows are exhausted using the fetchXXX() methods. * cursor.description is None. - + """ if not self.closed: @@ -2448,7 +2448,7 @@ class ResultProxy(object): self.connection.close() # allow consistent errors self.cursor = None - + def __iter__(self): while True: row = self.fetchone() @@ -2456,11 +2456,11 @@ class ResultProxy(object): raise StopIteration else: yield row - + @util.memoized_property def inserted_primary_key(self): """Return the primary key for the row just inserted. - + This only applies to single row insert() constructs which did not explicitly specify returning(). @@ -2473,19 +2473,19 @@ class ResultProxy(object): raise exc.InvalidRequestError( "Can't call inserted_primary_key when returning() " "is used.") - + return self.context.inserted_primary_key @util.deprecated("0.6", "Use :attr:`.ResultProxy.inserted_primary_key`") def last_inserted_ids(self): """Return the primary key for the row just inserted.""" - + return self.inserted_primary_key - + def last_updated_params(self): """Return the collection of updated parameters from this execution. - + """ if self.context.executemany: return self.context.compiled_parameters @@ -2495,7 +2495,7 @@ class ResultProxy(object): def last_inserted_params(self): """Return the collection of inserted parameters from this execution. - + """ if self.context.executemany: return self.context.compiled_parameters @@ -2549,7 +2549,7 @@ class ResultProxy(object): return self.cursor.fetchall() except AttributeError: self._non_result() - + def _non_result(self): if self._metadata is None: raise exc.ResourceClosedError( @@ -2558,7 +2558,7 @@ class ResultProxy(object): ) else: raise exc.ResourceClosedError("This result object is closed.") - + def process_rows(self, rows): process_row = self._process_row metadata = self._metadata @@ -2591,10 +2591,10 @@ class ResultProxy(object): def fetchmany(self, size=None): """Fetch many rows, just like DB-API ``cursor.fetchmany(size=cursor.arraysize)``. - + If rows are present, the cursor remains open after this is called. Else the cursor is automatically closed and an empty list is returned. - + """ try: @@ -2610,10 +2610,10 @@ class ResultProxy(object): def fetchone(self): """Fetch one row, just like DB-API ``cursor.fetchone()``. - + If a row is present, the cursor remains open after this is called. Else the cursor is automatically closed and None is returned. - + """ try: row = self._fetchone_impl() @@ -2630,9 +2630,9 @@ class ResultProxy(object): def first(self): """Fetch the first row and then close the result set unconditionally. - + Returns None if no row is present. - + """ if self._metadata is None: self._non_result() @@ -2652,12 +2652,12 @@ class ResultProxy(object): return None finally: self.close() - + def scalar(self): """Fetch the first column of the first row, and close the result set. - + Returns None if no row is present. - + """ row = self.first() if row is not None: @@ -2726,11 +2726,11 @@ class BufferedRowResultProxy(ResultProxy): class FullyBufferedResultProxy(ResultProxy): """A result proxy that buffers rows fully upon creation. - + Used for operations where a result is to be delivered after the database conversation can not be continued, such as MSSQL INSERT...OUTPUT after an autocommit. - + """ def _init_metadata(self): super(FullyBufferedResultProxy, self)._init_metadata() @@ -2738,7 +2738,7 @@ class FullyBufferedResultProxy(ResultProxy): def _buffer_rows(self): return self.cursor.fetchall() - + def _fetchone_impl(self): if self.__rowbuffer: return self.__rowbuffer.pop(0) @@ -2772,7 +2772,7 @@ class BufferedColumnRow(RowProxy): row = tuple(row) super(BufferedColumnRow, self).__init__(parent, row, processors, keymap) - + class BufferedColumnResultProxy(ResultProxy): """A ResultProxy with column buffering behavior. @@ -2782,7 +2782,7 @@ class BufferedColumnResultProxy(ResultProxy): databases where result rows contain "live" results that fall out of scope unless explicitly fetched. Currently this includes cx_Oracle LOB objects. - + """ _process_row = BufferedColumnRow diff --git a/lib/sqlalchemy/engine/ddl.py b/lib/sqlalchemy/engine/ddl.py index 10c7d55f2..6b5684f64 100644 --- a/lib/sqlalchemy/engine/ddl.py +++ b/lib/sqlalchemy/engine/ddl.py @@ -34,20 +34,20 @@ class SchemaGenerator(DDLBase): else: tables = metadata.tables.values() collection = [t for t in sql_util.sort_tables(tables) if self._can_create(t)] - + metadata.dispatch.before_create(metadata, self.connection, tables=collection) - + for table in collection: self.traverse_single(table, create_ok=True) - + metadata.dispatch.after_create(metadata, self.connection, tables=collection) def visit_table(self, table, create_ok=False): if not create_ok and not self._can_create(table): return - + table.dispatch.before_create(table, self.connection) for column in table.columns: @@ -88,10 +88,10 @@ class SchemaDropper(DDLBase): else: tables = metadata.tables.values() collection = [t for t in reversed(sql_util.sort_tables(tables)) if self._can_drop(t)] - + metadata.dispatch.before_drop(metadata, self.connection, tables=collection) - + for table in collection: self.traverse_single(table, drop_ok=True) @@ -118,7 +118,7 @@ class SchemaDropper(DDLBase): self.traverse_single(column.default) self.connection.execute(schema.DropTable(table)) - + table.dispatch.after_drop(table, self.connection) def visit_sequence(self, sequence): diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 8721b97aa..76077778c 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -34,23 +34,23 @@ class DefaultDialect(base.Dialect): supports_alter = True # most DBAPIs happy with this for execute(). - # not cx_oracle. + # not cx_oracle. execute_sequence_format = tuple - + supports_sequences = False sequences_optional = False preexecute_autoincrement_sequences = False postfetch_lastrowid = True implicit_returning = False - + supports_native_enum = False supports_native_boolean = False - + # if the NUMERIC type # returns decimal.Decimal. # *not* the FLOAT type however. supports_native_decimal = False - + # Py3K #supports_unicode_statements = True #supports_unicode_binds = True @@ -63,18 +63,18 @@ class DefaultDialect(base.Dialect): name = 'default' - + # length at which to truncate # any identifier. max_identifier_length = 9999 - + # length at which to truncate # the name of an index. # Usually None to indicate # 'use max_identifier_length'. # thanks to MySQL, sigh max_index_name_length = None - + supports_sane_rowcount = True supports_sane_multi_rowcount = True dbapi_type_map = {} @@ -82,28 +82,28 @@ class DefaultDialect(base.Dialect): default_paramstyle = 'named' supports_default_values = False supports_empty_insert = True - + server_version_info = None - + # indicates symbol names are # UPPERCASEd if they are case insensitive # within the database. # if this is True, the methods normalize_name() # and denormalize_name() must be provided. requires_name_normalize = False - + reflection_options = () def __init__(self, convert_unicode=False, assert_unicode=False, encoding='utf-8', paramstyle=None, dbapi=None, implicit_returning=None, label_length=None, **kwargs): - + if not getattr(self, 'ported_sqla_06', True): util.warn( "The %s dialect is not yet ported to SQLAlchemy 0.6" % self.name) - + self.convert_unicode = convert_unicode if assert_unicode: util.warn_deprecated( @@ -114,7 +114,7 @@ class DefaultDialect(base.Dialect): "received. " "This does *not* apply to DBAPIs that coerce Unicode " "natively.") - + self.encoding = encoding self.positional = False self._ischema = None @@ -137,32 +137,32 @@ class DefaultDialect(base.Dialect): " maximum identifier length of %d" % (label_length, self.max_identifier_length)) self.label_length = label_length - + if not hasattr(self, 'description_encoding'): self.description_encoding = getattr( self, 'description_encoding', encoding) - + if self.description_encoding: self._description_decoder = processors.to_unicode_processor_factory( self.description_encoding ) self._encoder = codecs.getencoder(self.encoding) self._decoder = processors.to_unicode_processor_factory(self.encoding) - + @util.memoized_property def _type_memos(self): return weakref.WeakKeyDictionary() - + @property def dialect_description(self): return self.name + "+" + self.driver - + @classmethod def get_pool_class(cls, url): return getattr(cls, 'poolclass', pool.QueuePool) - + def initialize(self, connection): try: self.server_version_info = \ @@ -176,23 +176,23 @@ class DefaultDialect(base.Dialect): self.default_schema_name = None self.returns_unicode_strings = self._check_unicode_returns(connection) - + self.do_rollback(connection.connection) def on_connect(self): """return a callable which sets up a newly created DBAPI connection. - + This is used to set dialect-wide per-connection options such as isolation modes, unicode modes, etc. - + If a callable is returned, it will be assembled into a pool listener that receives the direct DBAPI connection, with all wrappers removed. - + If None is returned, no listener will be generated. - + """ return None - + def _check_unicode_returns(self, connection): # Py2K if self.supports_unicode_statements: @@ -215,22 +215,22 @@ class DefaultDialect(base.Dialect): ) ) row = cursor.fetchone() - + return isinstance(row[0], unicode) finally: cursor.close() - + # detect plain VARCHAR unicode_for_varchar = check_unicode(sqltypes.VARCHAR(60)) - + # detect if there's an NVARCHAR type with different behavior available unicode_for_unicode = check_unicode(sqltypes.Unicode(60)) - + if unicode_for_unicode and not unicode_for_varchar: return "conditional" else: return unicode_for_varchar - + def type_descriptor(self, typeobj): """Provide a database-specific ``TypeEngine`` object, given the generic object which comes from the types module. @@ -249,14 +249,14 @@ class DefaultDialect(base.Dialect): def get_pk_constraint(self, conn, table_name, schema=None, **kw): """Compatiblity method, adapts the result of get_primary_keys() for those dialects which don't implement get_pk_constraint(). - + """ return { 'constrained_columns': self.get_primary_keys(conn, table_name, schema=schema, **kw) } - + def validate_identifier(self, ident): if len(ident) > self.max_identifier_length: raise exc.IdentifierError( @@ -332,11 +332,11 @@ class DefaultExecutionContext(base.ExecutionContext): statement = None _is_implicit_returning = False _is_explicit_returning = False - + @classmethod def _init_ddl(cls, dialect, connection, dbapi_connection, compiled_ddl): """Initialize execution context for a DDLElement construct.""" - + self = cls.__new__(cls) self.dialect = dialect self.root_connection = connection @@ -356,7 +356,7 @@ class DefaultExecutionContext(base.ExecutionContext): self.statement = dialect._encoder(self.unicode_statement)[0] else: self.statement = self.unicode_statement = unicode(compiled) - + self.cursor = self.create_cursor() self.compiled_parameters = [] @@ -366,7 +366,7 @@ class DefaultExecutionContext(base.ExecutionContext): self.parameters = [{}] return self - + @classmethod def _init_compiled(cls, dialect, connection, dbapi_connection, compiled, parameters): """Initialize execution context for a Compiled construct.""" @@ -401,7 +401,7 @@ class DefaultExecutionContext(base.ExecutionContext): self.isinsert = compiled.isinsert self.isupdate = compiled.isupdate self.isdelete = compiled.isdelete - + if self.isinsert or self.isupdate or self.isdelete: self._is_explicit_returning = compiled.statement._returning self._is_implicit_returning = compiled.returning and \ @@ -413,7 +413,7 @@ class DefaultExecutionContext(base.ExecutionContext): self.compiled_parameters = \ [compiled.construct_params(m, _group_number=grp) for grp,m in enumerate(parameters)] - + self.executemany = len(parameters) > 1 self.cursor = self.create_cursor() @@ -421,7 +421,7 @@ class DefaultExecutionContext(base.ExecutionContext): self.__process_defaults() self.postfetch_cols = self.compiled.postfetch self.prefetch_cols = self.compiled.prefetch - + processors = compiled._bind_processors # Convert the dictionary of bind parameter values @@ -456,9 +456,9 @@ class DefaultExecutionContext(base.ExecutionContext): param[key] = compiled_params[key] parameters.append(param) self.parameters = dialect.execute_sequence_format(parameters) - + return self - + @classmethod def _init_statement(cls, dialect, connection, dbapi_connection, statement, parameters): """Initialize execution context for a string SQL statement.""" @@ -490,18 +490,18 @@ class DefaultExecutionContext(base.ExecutionContext): else: self.parameters = [dialect.execute_sequence_format(p) for p in parameters] - + self.executemany = len(parameters) > 1 - + if not dialect.supports_unicode_statements and isinstance(statement, unicode): self.unicode_statement = statement self.statement = dialect._encoder(statement)[0] else: self.statement = self.unicode_statement = statement - + self.cursor = self.create_cursor() return self - + @classmethod def _init_default(cls, dialect, connection, dbapi_connection): """Initialize execution context for a ColumnDefault construct.""" @@ -514,11 +514,11 @@ class DefaultExecutionContext(base.ExecutionContext): self.execution_options = connection._execution_options self.cursor = self.create_cursor() return self - + @util.memoized_property def is_crud(self): return self.isinsert or self.isupdate or self.isdelete - + @util.memoized_property def should_autocommit(self): autocommit = self.execution_options.get('autocommit', @@ -526,20 +526,20 @@ class DefaultExecutionContext(base.ExecutionContext): self.statement and expression.PARSE_AUTOCOMMIT or False) - + if autocommit is expression.PARSE_AUTOCOMMIT: return self.should_autocommit_text(self.unicode_statement) else: return autocommit - + def _execute_scalar(self, stmt): """Execute a string statement on the current cursor, returning a scalar result. - + Used to fire off sequences, default phrases, and "select lastrowid" types of statements individually or in the context of a parent INSERT or UPDATE statement. - + """ conn = self.root_connection @@ -551,10 +551,10 @@ class DefaultExecutionContext(base.ExecutionContext): default_params = self.dialect.execute_sequence_format() else: default_params = {} - + conn._cursor_execute(self.cursor, stmt, default_params) return self.cursor.fetchone()[0] - + @property def connection(self): return self.root_connection._branch() @@ -570,32 +570,32 @@ class DefaultExecutionContext(base.ExecutionContext): def post_exec(self): pass - + def get_lastrowid(self): """return self.cursor.lastrowid, or equivalent, after an INSERT. - + This may involve calling special cursor functions, issuing a new SELECT on the cursor (or a new one), or returning a stored value that was calculated within post_exec(). - + This function will only be called for dialects which support "implicit" primary key generation, keep preexecute_autoincrement_sequences set to False, and when no explicit id value was bound to the statement. - + The function is called once, directly after post_exec() and before the transaction is committed or ResultProxy is generated. If the post_exec() method assigns a value to `self._lastrowid`, the value is used in place of calling get_lastrowid(). - + Note that this method is *not* equivalent to the ``lastrowid`` method on ``ResultProxy``, which is a direct proxy to the DBAPI ``lastrowid`` accessor in all cases. - + """ return self.cursor.lastrowid @@ -604,7 +604,7 @@ class DefaultExecutionContext(base.ExecutionContext): def get_result_proxy(self): return base.ResultProxy(self) - + @property def rowcount(self): return self.cursor.rowcount @@ -614,19 +614,19 @@ class DefaultExecutionContext(base.ExecutionContext): def supports_sane_multi_rowcount(self): return self.dialect.supports_sane_multi_rowcount - + def post_insert(self): if self.dialect.postfetch_lastrowid and \ (not self.inserted_primary_key or \ None in self.inserted_primary_key): - + table = self.compiled.statement.table lastrowid = self.get_lastrowid() self.inserted_primary_key = [ c is table._autoincrement_column and lastrowid or v for c, v in zip(table.primary_key, self.inserted_primary_key) ] - + def _fetch_implicit_returning(self, resultproxy): table = self.compiled.statement.table row = resultproxy.fetchone() @@ -637,9 +637,9 @@ class DefaultExecutionContext(base.ExecutionContext): ipk.append(v) else: ipk.append(row[c]) - + self.inserted_primary_key = ipk - + def lastrow_has_defaults(self): return (self.isinsert or self.isupdate) and \ bool(self.postfetch_cols) @@ -648,10 +648,10 @@ class DefaultExecutionContext(base.ExecutionContext): """Given a cursor and ClauseParameters, call the appropriate style of ``setinputsizes()`` on the cursor, using DB-API types from the bind parameter's ``TypeEngine`` objects. - + This method only called by those dialects which require it, currently cx_oracle. - + """ if not hasattr(self.compiled, 'bind_names'): @@ -696,12 +696,12 @@ class DefaultExecutionContext(base.ExecutionContext): elif default.is_clause_element: # TODO: expensive branching here should be # pulled into _exec_scalar() - conn = self.connection + conn = self.connection c = expression.select([default.arg]).compile(bind=conn) return conn._execute_compiled(c, (), {}).scalar() else: return default.arg - + def get_insert_default(self, column): if column.default is None: return None @@ -713,7 +713,7 @@ class DefaultExecutionContext(base.ExecutionContext): return None else: return self._exec_default(column.onupdate) - + def __process_defaults(self): """Generate default values for compiled insert/update statements, and generate inserted_primary_key collection. @@ -722,7 +722,7 @@ class DefaultExecutionContext(base.ExecutionContext): if self.executemany: if len(self.compiled.prefetch): scalar_defaults = {} - + # pre-determine scalar Python-side defaults # to avoid many calls of get_insert_default()/ # get_update_default() @@ -731,7 +731,7 @@ class DefaultExecutionContext(base.ExecutionContext): scalar_defaults[c] = c.default.arg elif self.isupdate and c.onupdate and c.onupdate.is_scalar: scalar_defaults[c] = c.onupdate.arg - + for param in self.compiled_parameters: self.current_parameters = param for c in self.compiled.prefetch: @@ -757,7 +757,7 @@ class DefaultExecutionContext(base.ExecutionContext): if val is not None: compiled_parameters[c.key] = val del self.current_parameters - + if self.isinsert: self.inserted_primary_key = [ self.compiled_parameters[0].get(c.key, None) @@ -765,5 +765,5 @@ class DefaultExecutionContext(base.ExecutionContext): statement.table.primary_key ] - + DefaultDialect.execution_ctx_cls = DefaultExecutionContext diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 964e9fbee..cf254cba6 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -55,17 +55,17 @@ class Inspector(object): :class:`~sqlalchemy.engine.base.Dialect`, providing a consistent interface as well as caching support for previously fetched metadata. - + The preferred method to construct an :class:`.Inspector` is via the :meth:`Inspector.from_engine` method. I.e.:: - + engine = create_engine('...') insp = Inspector.from_engine(engine) - + Where above, the :class:`~sqlalchemy.engine.base.Dialect` may opt to return an :class:`.Inspector` subclass that provides additional methods specific to the dialect's target database. - + """ def __init__(self, bind): @@ -75,7 +75,7 @@ class Inspector(object): which is typically an instance of :class:`~sqlalchemy.engine.base.Engine` or :class:`~sqlalchemy.engine.base.Connection`. - + For a dialect-specific instance of :class:`.Inspector`, see :meth:`Inspector.from_engine` @@ -83,10 +83,10 @@ class Inspector(object): # ensure initialized bind.connect() - + # this might not be a connection, it could be an engine. self.bind = bind - + # set the engine if hasattr(bind, 'engine'): self.engine = bind.engine @@ -103,14 +103,14 @@ class Inspector(object): which is typically an instance of :class:`~sqlalchemy.engine.base.Engine` or :class:`~sqlalchemy.engine.base.Connection`. - + This method differs from direct a direct constructor call of :class:`.Inspector` in that the :class:`~sqlalchemy.engine.base.Dialect` is given a chance to provide a dialect-specific :class:`.Inspector` instance, which may provide additional methods. - + See the example at :class:`.Inspector`. - + """ if hasattr(bind.dialect, 'inspector'): return bind.dialect.inspector(bind) @@ -120,10 +120,10 @@ class Inspector(object): def default_schema_name(self): """Return the default schema name presented by the dialect for the current engine's database user. - + E.g. this is typically ``public`` for Postgresql and ``dbo`` for SQL Server. - + """ return self.dialect.default_schema_name @@ -174,9 +174,9 @@ class Inspector(object): def get_table_options(self, table_name, schema=None, **kw): """Return a dictionary of options specified when the table of the given name was created. - + This currently includes some options that apply to MySQL tables. - + """ if hasattr(self.dialect, 'get_table_options'): return self.dialect.get_table_options(self.bind, table_name, schema, @@ -252,10 +252,10 @@ class Inspector(object): Given a string `table_name`, and an optional string `schema`, return primary key information as a dictionary with these keys: - + constrained_columns a list of column names that make up the primary key - + name optional name of the primary key constraint. @@ -265,7 +265,7 @@ class Inspector(object): **kw) return pkeys - + def get_foreign_keys(self, table_name, schema=None, **kw): """Return information about foreign_keys in `table_name`. @@ -288,7 +288,7 @@ class Inspector(object): name optional name of the foreign key constraint. - + \**kw other options passed to the dialect's get_foreign_keys() method. @@ -313,7 +313,7 @@ class Inspector(object): unique boolean - + \**kw other options passed to the dialect's get_indexes() method. """ @@ -325,23 +325,23 @@ class Inspector(object): def reflecttable(self, table, include_columns): """Given a Table object, load its internal constructs based on introspection. - + This is the underlying method used by most dialects to produce table reflection. Direct usage is like:: - + from sqlalchemy import create_engine, MetaData, Table from sqlalchemy.engine import reflection - + engine = create_engine('...') meta = MetaData() user_table = Table('user', meta) insp = Inspector.from_engine(engine) insp.reflecttable(user_table, None) - + :param table: a :class:`~sqlalchemy.schema.Table` instance. :param include_columns: a list of string column names to include in the reflection process. If ``None``, all columns are reflected. - + """ dialect = self.bind.dialect @@ -393,13 +393,13 @@ class Inspector(object): col_kw['autoincrement'] = col_d['autoincrement'] if 'quote' in col_d: col_kw['quote'] = col_d['quote'] - + colargs = [] if col_d.get('default') is not None: # the "default" value is assumed to be a literal SQL expression, # so is wrapped in text() so that no quoting occurs on re-issuance. colargs.append(sa_schema.DefaultClause(sql.text(col_d['default']))) - + if 'sequence' in col_d: # TODO: mssql, maxdb and sybase are using this. seq = col_d['sequence'] @@ -409,7 +409,7 @@ class Inspector(object): if 'increment' in seq: sequence.increment = seq['increment'] colargs.append(sequence) - + col = sa_schema.Column(name, coltype, *colargs, **col_kw) table.append_column(col) diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index df3d5b64a..e49d0e99e 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -28,7 +28,7 @@ class EngineStrategy(object): Provides a ``create`` method that receives input arguments and produces an instance of base.Engine or a subclass. - + """ def __init__(self): @@ -85,7 +85,7 @@ class DefaultEngineStrategy(EngineStrategy): import sys raise exc.DBAPIError.instance(None, None, e), None, sys.exc_info()[2] # end Py2K - + creator = kwargs.pop('creator', connect) poolclass = kwargs.pop('poolclass', None) @@ -120,7 +120,7 @@ class DefaultEngineStrategy(EngineStrategy): engine_args[k] = kwargs.pop(k) _initialize = kwargs.pop('_initialize', True) - + # all kwargs should be consumed if kwargs: raise TypeError( @@ -131,7 +131,7 @@ class DefaultEngineStrategy(EngineStrategy): dialect.__class__.__name__, pool.__class__.__name__, engineclass.__name__)) - + engine = engineclass(pool, dialect, u, **engine_args) if _initialize: @@ -142,10 +142,10 @@ class DefaultEngineStrategy(EngineStrategy): if conn is None: return do_on_connect(conn) - + event.listen(pool, 'first_connect', on_connect) event.listen(pool, 'connect', on_connect) - + def first_connect(dbapi_connection, connection_record): c = base.Connection(engine, connection=dbapi_connection) dialect.initialize(c) @@ -159,13 +159,13 @@ class PlainEngineStrategy(DefaultEngineStrategy): name = 'plain' engine_cls = base.Engine - + PlainEngineStrategy() class ThreadLocalEngineStrategy(DefaultEngineStrategy): """Strategy for configuring an Engine with thredlocal behavior.""" - + name = 'threadlocal' engine_cls = threadlocal.TLEngine @@ -177,11 +177,11 @@ class MockEngineStrategy(EngineStrategy): Produces a single mock Connectable object which dispatches statement execution to a passed-in function. - + """ name = 'mock' - + def create(self, name_or_url, executor, **kwargs): # create url.URL object u = url.make_url(name_or_url) @@ -218,7 +218,7 @@ class MockEngineStrategy(EngineStrategy): def create(self, entity, **kwargs): kwargs['checkfirst'] = False from sqlalchemy.engine import ddl - + ddl.SchemaGenerator(self.dialect, self, **kwargs).traverse(entity) def drop(self, entity, **kwargs): diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index a083d0113..2ce0922bf 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -19,11 +19,11 @@ class TLConnection(base.Connection): def __init__(self, *arg, **kw): super(TLConnection, self).__init__(*arg, **kw) self.__opencount = 0 - + def _increment_connect(self): self.__opencount += 1 return self - + def close(self): if self.__opencount == 1: base.Connection.close(self) @@ -52,21 +52,21 @@ class TLEngine(base.Engine): self._connections = util.threading.local() dispatch = event.dispatcher(TLEvents) - + def contextual_connect(self, **kw): if not hasattr(self._connections, 'conn'): connection = None else: connection = self._connections.conn() - + if connection is None or connection.closed: # guards against pool-level reapers, if desired. # or not connection.connection.is_valid: connection = self.TLConnection(self, self.pool.connect(), **kw) self._connections.conn = conn = weakref.ref(connection) - + return connection._increment_connect() - + def begin_twophase(self, xid=None): if not hasattr(self._connections, 'trans'): self._connections.trans = [] @@ -76,42 +76,42 @@ class TLEngine(base.Engine): if not hasattr(self._connections, 'trans'): self._connections.trans = [] self._connections.trans.append(self.contextual_connect().begin_nested()) - + def begin(self): if not hasattr(self._connections, 'trans'): self._connections.trans = [] self._connections.trans.append(self.contextual_connect().begin()) - + def prepare(self): if not hasattr(self._connections, 'trans') or \ not self._connections.trans: return self._connections.trans[-1].prepare() - + def commit(self): if not hasattr(self._connections, 'trans') or \ not self._connections.trans: return trans = self._connections.trans.pop(-1) trans.commit() - + def rollback(self): if not hasattr(self._connections, 'trans') or \ not self._connections.trans: return trans = self._connections.trans.pop(-1) trans.rollback() - + def dispose(self): self._connections = util.threading.local() super(TLEngine, self).dispose() - + @property def closed(self): return not hasattr(self._connections, 'conn') or \ self._connections.conn() is None or \ self._connections.conn().closed - + def close(self): if not self.closed: self.contextual_connect().close() @@ -119,6 +119,6 @@ class TLEngine(base.Engine): connection._force_close() del self._connections.conn self._connections.trans = [] - + def __repr__(self): return 'TLEngine(%s)' % str(self.url) diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 199b37c46..9f4c2dbdf 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -113,25 +113,25 @@ class URL(object): return module else: raise - + def _load_entry_point(self): """attempt to load this url's dialect from entry points, or return None if pkg_resources is not installed or there is no matching entry point. - + Raise ImportError if the actual load fails. - + """ try: import pkg_resources except ImportError: return None - + for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'): if res.name == self.drivername: return res.load() else: return None - + def translate_connect_args(self, names=[], **kw): """Translate url attributes into a dictionary of connection arguments. |