~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/dialects/postgresql/psycopg2.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
  way of enabling this mode on a per-execution basis.
31
31
* ``use_native_unicode``: Enable the usage of Psycopg2 "native unicode" mode
32
32
  per connection.  True by default.
33
 
* ``isolation_level``: This option, available for all Posgtresql dialects,
 
33
* ``isolation_level``: This option, available for all PostgreSQL dialects,
34
34
  includes the ``AUTOCOMMIT`` isolation level when using the psycopg2
35
35
  dialect.  See :ref:`psycopg2_isolation_level`.
36
36
 
102
102
    :func:`.create_engine`.
103
103
 
104
104
SQLAlchemy can also be instructed to skip the usage of the psycopg2
105
 
``UNICODE`` extension and to instead utilize it's own unicode encode/decode
 
105
``UNICODE`` extension and to instead utilize its own unicode encode/decode
106
106
services, which are normally reserved only for those DBAPIs that don't
107
107
fully support unicode directly.  Passing ``use_native_unicode=False`` to
108
108
:func:`.create_engine` will disable usage of ``psycopg2.extensions.UNICODE``.
144
144
.. versionadded:: 0.8.2 support for AUTOCOMMIT isolation level when using
145
145
   psycopg2.
146
146
 
 
147
.. seealso::
 
148
 
 
149
    :ref:`postgresql_isolation_level`
 
150
 
 
151
    :ref:`pg8000_isolation_level`
 
152
 
147
153
 
148
154
NOTICE logging
149
155
---------------
169
175
   If this function returns a list of HSTORE identifiers, we then determine that
170
176
   the ``HSTORE`` extension is present.
171
177
 
172
 
2. If the ``use_native_hstore`` flag is at it's default of ``True``, and
 
178
2. If the ``use_native_hstore`` flag is at its default of ``True``, and
173
179
   we've detected that ``HSTORE`` oids are available, the
174
180
   ``psycopg2.extensions.register_hstore()`` extension is invoked for all
175
181
   connections.
270
276
        else:
271
277
            return super(_PGJSON, self).result_processor(dialect, coltype)
272
278
 
273
 
# When we're handed literal SQL, ensure it's a SELECT-query. Since
 
279
# When we're handed literal SQL, ensure it's a SELECT query. Since
274
280
# 8.3, combining cursors and "FOR UPDATE" has been fine.
275
281
SERVER_SIDE_CURSOR_RE = re.compile(
276
282
    r'\s*SELECT',
489
495
 
490
496
    def is_disconnect(self, e, connection, cursor):
491
497
        if isinstance(e, self.dbapi.Error):
 
498
            # check the "closed" flag.  this might not be
 
499
            # present on old psycopg2 versions
 
500
            if getattr(connection, 'closed', False):
 
501
                return True
 
502
 
 
503
            # legacy checks based on strings.  the "closed" check
 
504
            # above most likely obviates the need for any of these.
492
505
            str_e = str(e).partition("\n")[0]
493
506
            for msg in [
494
507
                # these error messages from libpq: interfaces/libpq/fe-misc.c
495
508
                # and interfaces/libpq/fe-secure.c.
496
 
                # TODO: these are sent through gettext in libpq and we can't
497
 
                # check within other locales - consider using connection.closed
498
509
                'terminating connection',
499
510
                'closed the connection',
500
511
                'connection not open',
501
512
                'could not receive data from server',
502
513
                'could not send data to server',
503
 
                # psycopg2 client errors, psycopg2/conenction.h, psycopg2/cursor.h
 
514
                # psycopg2 client errors, psycopg2/conenction.h,
 
515
                # psycopg2/cursor.h
504
516
                'connection already closed',
505
517
                'cursor already closed',
506
518
                # not sure where this path is originally from, it may
507
519
                # be obsolete.   It really says "losed", not "closed".
508
 
                'losed the connection unexpectedly'
 
520
                'losed the connection unexpectedly',
 
521
                # this can occur in newer SSL
 
522
                'connection has been closed unexpectedly'
509
523
            ]:
510
524
                idx = str_e.find(msg)
511
525
                if idx >= 0 and '"' not in str_e[:idx]: