Connections — SQLAlchemy 0.5.0 Documentation

# SQLAlchemy 0.5.0 Documentation

Search:
Version: 0.5.0 Last Updated: 01/06/2009 13:41:02

# Connections

## Creating Engines

`sqlalchemy.` `create_engine`(*args, **kwargs)

  Create a new Engine instance.

  The standard method of specifying the engine is via URL as the first positional argument, to indicate the appropriate database dialect and connection arguments, with additional keyword arguments sent as options to the dialect and resulting Engine.

  The URL is a string in the form `dialect://user:password@host/dbname[?key=value..]`, where `dialect` is a name such as `mysql`, `oracle`, `postgres`, etc. Alternatively, the URL can be an instance of `URL`.

  **kwargs takes a wide variety of options which are routed towards their appropriate components. Arguments may be specific to the Engine, the underlying Dialect, as well as the Pool. Specific dialects also accept keyword arguments that are unique to that dialect. Here, we describe the parameters that are common to most `create_engine()` usage.

  Parameters: | assert_unicode=False – When set to `True` alongside convert_unicode=``True``, asserts that incoming string bind parameters are instances of `unicode`, otherwise raises an error. Only takes effect when `convert_unicode==True`. This flag is also available on the `String` type and its descendants. New in 0.4.2. connect_args – a dictionary of options which will be passed directly to the DBAPI’s `connect()` method as additional keyword arguments. convert_unicode=False – if set to True, all String/character based types will convert Unicode values to raw byte values going into the database, and all raw byte values to Python Unicode coming out in result sets. This is an engine-wide method to provide unicode conversion across the board. For unicode conversion on a column-by-column level, use the `Unicode` column type instead, described in types. creator – a callable which returns a DBAPI connection. This creation function will be passed to the underlying connection pool and will be used to create all new database connections. Usage of this function causes connection parameters specified in the URL argument to be bypassed. echo=False – if True, the Engine will log all statements as well as a repr() of their parameter lists to the engines logger, which defaults to sys.stdout. The `echo` attribute of `Engine` can be modified at any time to turn logging on and off. If set to the string `"debug"`, result rows will be printed to the standard output as well. This flag ultimately controls a Python logger; see dbengine_logging at the end of this chapter for information on how to configure logging directly. echo_pool=False – if True, the connection pool will log all checkouts/checkins to the logging stream, which defaults to sys.stdout. This flag ultimately controls a Python logger; see dbengine_logging for information on how to configure logging directly. encoding=’utf-8’ – the encoding to use for all Unicode translations, both by engine-wide unicode conversion as well as the `Unicode` type object. 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. module=None – used by database implementations which support multiple DBAPI modules, this is a reference to a DBAPI2 module to be used instead of the engine’s default module. For Postgres, the default is psycopg2. For Oracle, it’s cx_Oracle. pool=None – an already-constructed instance of `Pool`, such as a `QueuePool` instance. If non-None, this pool will be used directly as the underlying connection pool for the engine, bypassing whatever connection parameters are present in the URL argument. For information on constructing connection pools manually, see pooling. poolclass=None – a `Pool` subclass, which will be used to create a connection pool instance using the connection parameters given in the URL. Note this differs from `pool` in that you don’t actually instantiate the pool in this case, you just indicate what type of pool to be used. max_overflow=10 – the number of connections to allow in connection pool “overflow”, that is connections that can be opened above and beyond the pool_size setting, which defaults to five. this is only used with `QueuePool`. pool_size=5 – the number of connections to keep open inside the connection pool. This used with `QueuePool` as well as `SingletonThreadPool`. pool_recycle=-1 – this setting causes the pool to recycle connections after the given number of seconds has passed. It defaults to -1, or no timeout. For example, setting to 3600 means connections will be recycled after one hour. Note that MySQL in particular will `disconnect automatically` if no activity is detected on a connection for eight hours (although this is configurable with the MySQLDB connection itself and the server configuration as well). pool_timeout=30 – number of seconds to wait before giving up on getting a connection from the pool. This is only used with `QueuePool`. strategy=’plain’ – used to invoke alternate `` implementations. Currently available is the `threadlocal` strategy, which is described in Using the Threadlocal Execution Strategy.

`sqlalchemy.` `engine_from_config`(configuration, prefix='sqlalchemy.', **kwargs)

  Create a new Engine instance using a configuration dictionary.

  The dictionary is typically produced from a config file where keys are prefixed, such as sqlalchemy.url, sqlalchemy.echo, etc. The ‘prefix’ argument indicates the prefix to be searched for.

  A select set of keyword arguments will be “coerced” to their expected type based on string values. In a future release, this functionality will be expanded and include dialect-specific arguments.

class `sqlalchemy.engine.url.` `URL`(drivername, username=None, password=None, host=None, port=None, database=None, query=None)

  Represent the components of a URL used to connect to a database.

  This object is suitable to be passed directly to a `create_engine()` call. The fields of the URL are parsed from a string by the `module-level make_url()` function. the string format of the URL is an RFC-1738-style string.

  All initialization parameters are available as public attributes.

  Parameters: | drivername – the name of the database backend. This name will correspond to a module in sqlalchemy/databases or a third party plug-in. username – The user name. password – database password. host – The name of the host. port – The port number. database – The database name. query – A dictionary of options to be passed to the dialect and/or the DBAPI upon connect.

  `__init__`(drivername, username=None, password=None, host=None, port=None, database=None, query=None)
  `get_dialect`()
    Return the SQLAlchemy database dialect class corresponding to this URL’s driver name.
  `translate_connect_args`(names=[], **kw)

    Translate url attributes into a dictionary of connection arguments.

    Returns attributes of this url (host, database, username, password, port) as a plain dictionary. The attribute names are used as the keys by default. Unset or false attributes are omitted from the final dictionary.

    Parameters: | **kw – Optional, alternate key names for url attributes. names – Deprecated. Same purpose as the keyword-based alternate names, but correlates the name to the original positionally.

## Connectables

class `sqlalchemy.engine.base.` `Engine`(pool, dialect, url, echo=None, proxy=None)

  Connects a `Pool` and `Dialect` together to provide a source of database connectivity and behavior.

  `__init__`(pool, dialect, url, echo=None, proxy=None)
  `connect`(**kwargs)
    Return a newly allocated Connection object.
  `contextual_connect`(close_with_result=False, **kwargs)

    Return a Connection object which may be newly allocated, or may be part of some ongoing context.

    This Connection is meant to be used by the various “auto-connecting” operations.

  `create`(entity, connection=None, **kwargs)
    Create a table or index within this engine’s database connection given a schema.Table object.
  `drop`(entity, connection=None, **kwargs)
    Drop a table or index within this engine’s database connection given a schema.Table object.
  `echo`

    When `True`, enable log output for this element.

    This has the effect of setting the Python logging level for the namespace of this element’s class and object reference. A value of boolean `True` indicates that the loglevel `logging.INFO` will be set for the logger, whereas the string value `debug` will set the loglevel to `logging.DEBUG`.

  `name`
    String name of the `Dialect` in use by this `Engine`.
  `raw_connection`()
    Return a DB-API connection.
  `reflecttable`(table, connection=None, include_columns=None)
    Given a Table object, reflects its columns and properties from the database.
  `table_names`(schema=None, connection=None)

    Return a list of all table names available in the database.

    schema:
      Optional, retrieve names from a non-default schema.
    connection:
      Optional, use a specified connection. Default is the `contextual_connect` for this `Engine`.
  `text`(text, *args, **kwargs)
    Return a sql.text() object for performing literal queries.
  `transaction`(callable_, connection=None, *args, **kwargs)

    Execute the given function within a transaction boundary.

    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, as well as the Connection used in the transaction.

class `sqlalchemy.engine.base.` `Connection`(engine, connection=None, close_with_result=False, _branch=False)

  Provides high-level functionality for a wrapped DB-API connection.

  Provides execution support for string-based SQL statements as well as ClauseElement, Compiled and DefaultGenerator objects. Provides a begin method to return Transaction objects.

  The Connection object is not thread-safe.

  `__init__`(engine, connection=None, close_with_result=False, _branch=False)

    Construct a new Connection.

    Connection objects are typically constructed by an `Engine`, see the `connect()` and `contextual_connect()` methods of Engine.

  `begin`()

    Begin a transaction and return a Transaction handle.

    Repeated calls to `begin` on the same Connection will create a lightweight, emulated nested transaction. Only the outermost transaction may `commit`. Calls to `commit` on inner transactions are ignored. Any transaction in the hierarchy may `rollback`, however.

  `begin_nested`()

    Begin a nested transaction and return a Transaction handle.

    Nested transactions require SAVEPOINT support in the underlying database. Any transaction in the hierarchy may `commit` and `rollback`, however the outermost transaction still controls the overall `commit` or `rollback` of the transaction of a whole.

  `begin_twophase`(xid=None)

    Begin a two-phase or XA transaction and return a Transaction handle.

    xid
      the two phase transaction id. If not supplied, a random id will be generated.
  `close`()
    Close this Connection.
  `closed`
    return True if this connection is closed.
  `connect`()

    Returns self.

    This `Connectable` interface method returns self, allowing Connections to be used interchangably with Engines in most situations that require a bind.

  `connection`
    The underlying DB-API connection managed by this Connection.
  `contextual_connect`(**kwargs)

    Returns self.

    This `Connectable` interface method returns self, allowing Connections to be used interchangably with Engines in most situations that require a bind.

  `create`(entity, **kwargs)
    Create a Table or Index given an appropriate Schema object.
  `detach`()

    Detach the underlying DB-API connection from its connection pool.

    This Connection instance will remain useable. When closed, the DB-API connection will be literally closed and not returned to its pool. The pool will typically lazily create a new connection to replace the detached connection.

    This method can be used to insulate the rest of an application from a modified state on a connection (such as a transaction isolation level or similar). Also see `PoolListener` for a mechanism to modify connection state when connections leave and return to their connection pool.

  `dialect`
    Dialect used by this Connection.
  `drop`(entity, **kwargs)
    Drop a Table or Index given an appropriate Schema object.
  `execute`(object, *multiparams, **params)
    Executes and returns a ResultProxy.
  `in_transaction`()
    Return True if a transaction is in progress.
  `info`
    A collection of per-DB-API connection instance properties.
  `invalidate`(exception=None)

    Invalidate the underlying DBAPI connection associated with this Connection.

    The underlying DB-API connection is literally closed (if possible), and is discarded. Its source connection pool will typically lazily create a new connection to replace it.

    Upon the next usage, this Connection will attempt to reconnect to the pool with a new connection.

    Transactions in progress remain in an “opened” state (even though the actual transaction is gone); these must be explicitly rolled back before a reconnect on this Connection can proceed. This is to prevent applications from accidentally continuing their transactional operations in a non-transactional state.

  `invalidated`
    return True if this connection was invalidated.
  `reflecttable`(table, include_columns=None)
    Reflect the columns in the given string table name from the database.
  `scalar`(object, *multiparams, **params)

    Executes and returns the first column of the first row.

    The underlying result/cursor is closed after execution.

  `should_close_with_result`
    Indicates if this Connection should be closed when a corresponding ResultProxy is closed; this is essentially an auto-release mode.

class `sqlalchemy.engine.base.` `Connectable`

  Interface for an object which supports execution of SQL constructs.

  The two implementations of `Connectable` are `Connection` and `Engine`.

  `contextual_connect`()
    Return a Connection object which may be part of an ongoing context.
  `create`(entity, **kwargs)
    Create a table or index given an appropriate schema object.
  `drop`(entity, **kwargs)
    Drop a table or index given an appropriate schema object.
  `execute`(object, *multiparams, **params)

## Result Objects

class `sqlalchemy.engine.base.` `ResultProxy`(context)

  Wraps a DB-API cursor object to provide easier access to row columns.

  Individual columns may be accessed by their integer position, case-insensitive column name, or by `schema.Column` object. e.g.:

      row = fetchone()

      col1 = row[0]    # access via integer position

      col2 = row['col2']   # access via name

      col3 = row[mytable.c.mycol] # access via Column object.

  ResultProxy also contains a map of TypeEngine objects and will invoke the appropriate `result_processor()` method before returning columns, as well as the ExecutionContext corresponding to the statement execution. It provides several methods for which to obtain information from the underlying ExecutionContext.

  `__init__`(context)
    ResultProxy objects are constructed via the execute() method on SQLEngine.
  `close`()

    Close this ResultProxy.

    Closes the underlying DBAPI cursor corresponding to the execution.

    If this ResultProxy was generated from an implicit execution, the underlying Connection will also be closed (returns the underlying DBAPI connection to the connection pool.)

    This method is called automatically when:

    > - all result rows are exhausted using the fetchXXX() methods.
    > - cursor.description is None.

  `fetchall`()
    Fetch all rows, just like DB-API `cursor.fetchall()`.
  `fetchmany`(size=None)
    Fetch many rows, just like DB-API `cursor.fetchmany(size=cursor.arraysize)`.
  `fetchone`()
    Fetch one row, just like DB-API `cursor.fetchone()`.
  `last_inserted_ids`()

    Return `last_inserted_ids()` from the underlying ExecutionContext.

    See ExecutionContext for details.

  `last_inserted_params`()

    Return `last_inserted_params()` from the underlying ExecutionContext.

    See ExecutionContext for details.

  `last_updated_params`()

    Return `last_updated_params()` from the underlying ExecutionContext.

    See ExecutionContext for details.

  `lastrow_has_defaults`()

    Return `lastrow_has_defaults()` from the underlying ExecutionContext.

    See ExecutionContext for details.

  `postfetch_cols`()

    Return `postfetch_cols()` from the underlying ExecutionContext.

    See ExecutionContext for details.

  `scalar`()
    Fetch the first column of the first row, and close the result set.
  `supports_sane_multi_rowcount`()
    Return `supports_sane_multi_rowcount` from the dialect.
  `supports_sane_rowcount`()
    Return `supports_sane_rowcount` from the dialect.

class `sqlalchemy.engine.base.` `RowProxy`(parent, row)

  Proxy a single cursor row for a parent ResultProxy.

  Mostly follows “ordered dictionary” behavior, mapping result values to the string-based column name, the integer position of the result in the row, as well as Column instances which can be mapped to the original Columns that produced this result set (for results that correspond to constructed SQL expressions).

  `__init__`(parent, row)
    RowProxy objects are constructed by ResultProxy objects.
  `close`()
    Close the parent ResultProxy.
  `has_key`(key)
    Return True if this RowProxy contains the given key.
  `items`()
    Return a list of tuples, each tuple containing a key/value pair.
  `keys`()
    Return the list of keys as strings represented by this RowProxy.
  `values`()
    Return the values represented by this RowProxy as a list.

## Transactions

class `sqlalchemy.engine.base.` `Transaction`(connection, parent)

  Represent a Transaction in progress.

  The Transaction object is not threadsafe.

  `__init__`(connection, parent)
  `close`()

    Close this transaction.

    If this transaction is the base transaction in a begin/commit nesting, the transaction will rollback(). Otherwise, the method returns.

    This is used to cancel a Transaction without affecting the scope of an enclosing transaction.

  `commit`()
  `rollback`()

## Internals

`sqlalchemy.engine.base.` `connection_memoize`(key)

  Decorator, memoize a function in a connection.info stash.

  Only applicable to functions which take no arguments other than a connection. The memo will be stored in `connection.info[key]`.

class `sqlalchemy.engine.base.` `Dialect`

  Define the behavior of a specific database and DB-API combination.

  Any aspect of metadata definition, SQL query generation, execution, result-set handling, or anything else which varies between databases is defined under the general category of the Dialect. The Dialect acts as a factory for other database-specific object implementations including ExecutionContext, Compiled, DefaultGenerator, and TypeEngine.

  All Dialects implement the following attributes:

  name
    identifying name for the dialect (i.e. ‘sqlite’)
  positional
    True if the paramstyle for this Dialect is positional.
  paramstyle
    the paramstyle to be used (some DB-APIs support multiple paramstyles).
  convert_unicode
    True if Unicode conversion should be applied to all `str` types.
  encoding
    type of encoding to use for unicode, usually defaults to ‘utf-8’.
  schemagenerator
    a `SchemaVisitor` class which generates schemas.
  schemadropper
    a `SchemaVisitor` class which drops schemas.
  defaultrunner
    a `SchemaVisitor` class which executes defaults.
  statement_compiler
    a `Compiled` class used to compile SQL statements
  preparer
    a `IdentifierPreparer` class used to quote identifiers.
  supports_alter
    `True` if the database supports `ALTER TABLE`.
  max_identifier_length
    The maximum length of identifier names.
  supports_unicode_statements
    Indicate whether the DB-API can receive SQL statements as Python unicode strings
  supports_sane_rowcount
    Indicate whether the dialect properly implements rowcount for `UPDATE` and `DELETE` statements.
  supports_sane_multi_rowcount
    Indicate whether the dialect properly implements rowcount for `UPDATE` and `DELETE` statements when executed via executemany.
  preexecute_pk_sequences
    Indicate if the dialect should pre-execute sequences on primary key columns during an INSERT, if it’s desired that the new row’s primary key be available after execution.
  supports_pk_autoincrement
    Indicates if the dialect should allow the database to passively assign a primary key column value.
  dbapi_type_map

    A mapping of DB-API type objects present in this Dialect’s DB-API implmentation mapped to TypeEngine implementations used by the dialect.

    This is used to apply types to result sets based on the DB-API types present in cursor.description; it only takes effect for result sets against textual statements where no explicit typemap was present.

  supports_default_values
    Indicates if the construct `INSERT INTO tablename DEFAULT VALUES` is supported
  description_encoding
    type of encoding to use for unicode when working with metadata descriptions. If set to `None` no encoding will be done. This usually defaults to ‘utf-8’.
  `create_connect_args`(url)

    Build DB-API compatible connection arguments.

    Given a `URL` object, returns a tuple consisting of a *args/**kwargs suitable to send directly to the dbapi’s connect function.

  `create_xid`()

    Create a two-phase transaction ID.

    This id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). Its format is unspecified.

  `do_begin`(connection)
    Provide an implementation of connection.begin(), given a DB-API connection.
  `do_begin_twophase`(connection, xid)
    Begin a two phase transaction on the given connection.
  `do_commit`(connection)
    Provide an implementation of connection.commit(), given a DB-API connection.
  `do_commit_twophase`(connection, xid, is_prepared=True, recover=False)
    Commit a two phase transaction on the given connection.
  `do_execute`(cursor, statement, parameters, context=None)
    Provide an implementation of cursor.execute(statement, parameters).
  `do_executemany`(cursor, statement, parameters, context=None)
    Provide an implementation of cursor.executemany(statement, parameters).
  `do_prepare_twophase`(connection, xid)
    Prepare a two phase transaction on the given connection.
  `do_recover_twophase`(connection)
    Recover list of uncommited prepared two phase transaction identifiers on the given connection.
  `do_release_savepoint`(connection, name)
    Release the named savepoint on a SQL Alchemy connection.
  `do_rollback`(connection)
    Provide an implementation of connection.rollback(), given a DB-API connection.
  `do_rollback_to_savepoint`(connection, name)
    Rollback a SQL Alchemy connection to the named savepoint.
  `do_rollback_twophase`(connection, xid, is_prepared=True, recover=False)
    Rollback a two phase transaction on the given connection.
  `do_savepoint`(connection, name)
    Create a savepoint with the given name on a SQLAlchemy connection.
  `get_default_schema_name`(connection)
    Return the string name of the currently selected schema given a `Connection`.
  `has_sequence`(connection, sequence_name, schema=None)

    Check the existence of a particular sequence in the database.

    Given a `Connection` object and a string sequence_name, return True if the given sequence exists in the database, False otherwise.

  `has_table`(connection, table_name, schema=None)

    Check the existence of a particular table in the database.

    Given a `Connection` object and a string table_name, return True if the given table (possibly within the specified schema) exists in the database, False otherwise.

  `is_disconnect`(e)
    Return True if the given DB-API error indicates an invalid connection
  `reflecttable`(connection, table, include_columns=None)

    Load table description from the database.

    Given a `Connection` and a `Table` object, reflect its columns and properties from the database. If include_columns (a list or set) is specified, limit the autoload to the given column names.

  `server_version_info`(connection)
    Return a tuple of the database’s version number.
  `type_descriptor`(typeobj)

    Transform a generic type to a database-specific type.

    Transforms the given `TypeEngine` instance from generic to database-specific.

    Subclasses will usually use the `adapt_type()` method in the types module to make this job easy.

class `sqlalchemy.engine.default.` `DefaultDialect`(convert_unicode=False, assert_unicode=False, encoding='utf-8', paramstyle=None, dbapi=None, label_length=None, **kwargs)

  Bases: `sqlalchemy.engine.base.Dialect`

  Default implementation of Dialect

  `__init__`(convert_unicode=False, assert_unicode=False, encoding='utf-8', paramstyle=None, dbapi=None, label_length=None, **kwargs)
  `create_xid`()

    Create a random two-phase transaction ID.

    This id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). Its format is unspecified.

  `defaultrunner`()

    A visitor which accepts ColumnDefault objects, produces the dialect-specific SQL corresponding to their execution, and executes the SQL, returning the result value.

    DefaultRunners are used internally by Engines and Dialects. Specific database modules should provide their own subclasses of DefaultRunner to allow database-specific behavior.

  `do_begin`(connection)
    Implementations might want to put logic here for turning autocommit on/off, etc.
  `do_commit`(connection)
    Implementations might want to put logic here for turning autocommit on/off, etc.
  `do_rollback`(connection)
    Implementations might want to put logic here for turning autocommit on/off, etc.
  `preparer`()
    Handle quoting and case-folding of identifiers based on options.
  `statement_compiler`()

    Default implementation of Compiled.

    Compiles ClauseElements into SQL strings. Uses a similar visit paradigm as visitors.ClauseVisitor but implements its own traversal.

  `type_descriptor`(typeobj)

    Provide a database-specific `TypeEngine` object, given the generic object which comes from the types module.

    Subclasses will usually use the `adapt_type()` method in the types module to make this job easy.

class `sqlalchemy.engine.default.` `DefaultExecutionContext`(dialect, connection, compiled=None, statement=None, parameters=None)

  Bases: `sqlalchemy.engine.base.ExecutionContext`

  `__init__`(dialect, connection, compiled=None, statement=None, parameters=None)
  `set_input_sizes`()
    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.

class `sqlalchemy.engine.base.` `DefaultRunner`(context)

  Bases: `sqlalchemy.schema.SchemaVisitor`

  A visitor which accepts ColumnDefault objects, produces the dialect-specific SQL corresponding to their execution, and executes the SQL, returning the result value.

  DefaultRunners are used internally by Engines and Dialects. Specific database modules should provide their own subclasses of DefaultRunner to allow database-specific behavior.

  `__init__`(context)
  `execute_string`(stmt, params=None)
    execute a string statement, using the raw cursor, and return a scalar result.

class `sqlalchemy.engine.base.` `ExecutionContext`

  A messenger object for a Dialect that corresponds to a single execution.

  ExecutionContext should have these datamembers:

  connection
    Connection object which can be freely used by default value generators to execute SQL. This Connection should reference the same underlying connection/transactional resources of root_connection.
  root_connection
    Connection object which is the source of this ExecutionContext. This Connection may have close_with_result=True set, in which case it can only be used once.
  dialect
    dialect which created this ExecutionContext.
  cursor
    DB-API cursor procured from the connection,
  compiled
    if passed to constructor, sqlalchemy.engine.base.Compiled object being executed,
  statement
    string version of the statement to be executed. Is either passed to the constructor, or must be created from the sql.Compiled object by the time pre_exec() has completed.
  parameters
    bind parameters passed to the execute() method. For compiled statements, this is a dictionary or list of dictionaries. For textual statements, it should be in a format suitable for the dialect’s paramstyle (i.e. dict or list of dicts for non positional, list or list of lists/tuples for positional).
  isinsert
    True if the statement is an INSERT.
  isupdate
    True if the statement is an UPDATE.
  should_autocommit
    True if the statement is a “committable” statement
  postfetch_cols
    a list of Column objects for which a server-side default or inline SQL expression value was fired off. applies to inserts and updates.
  `create_cursor`()

    Return a new cursor generated from this ExecutionContext’s connection.

    Some dialects may wish to change the behavior of connection.cursor(), such as postgres which may return a PG “server side” cursor.

  `handle_dbapi_exception`(e)
    Receive a DBAPI exception which occured upon execute, result fetch, etc.
  `last_inserted_ids`()

    Return the list of the primary key values for the last insert statement executed.

    This does not apply to straight textual clauses; only to `sql.Insert` objects compiled against a `schema.Table` object. The order of items in the list is the same as that of the Table’s ‘primary_key’ attribute.

  `last_inserted_params`()

    Return a dictionary of the full parameter dictionary for the last compiled INSERT statement.

    Includes any ColumnDefaults or Sequences that were pre-executed.

  `last_updated_params`()

    Return a dictionary of the full parameter dictionary for the last compiled UPDATE statement.

    Includes any ColumnDefaults that were pre-executed.

  `lastrow_has_defaults`()
    Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
  `post_exec`()

    Called after the execution of a compiled statement.

    If a compiled statement was passed to this ExecutionContext, the last_insert_ids, last_inserted_params, etc. datamembers should be available after this method completes.

  `pre_exec`()

    Called before an execution of a compiled statement.

    If a compiled statement was passed to this ExecutionContext, the statement and parameters datamembers must be initialized after this statement is complete.

  `result`()

    Return a result object corresponding to this ExecutionContext.

    Returns a ResultProxy.

  `should_autocommit_text`(statement)
    Parse the given textual statement and return True if it refers to a “committable” statement

class `sqlalchemy.engine.base.` `SchemaIterator`(connection)

  Bases: `sqlalchemy.schema.SchemaVisitor`

  A visitor that can gather text into a buffer and execute the contents of the buffer.

  `__init__`(connection)
    Construct a new SchemaIterator.
  `append`(s)
    Append content to the SchemaIterator’s query buffer.
  `execute`()
    Execute the contents of the SchemaIterator’s buffer.