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`.
102
102
:func:`.create_engine`.
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``.
169
175
If this function returns a list of HSTORE identifiers, we then determine that
170
176
the ``HSTORE`` extension is present.
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
271
277
return super(_PGJSON, self).result_processor(dialect, coltype)
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(
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):
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]
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,
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'
510
524
idx = str_e.find(msg)
511
525
if idx >= 0 and '"' not in str_e[:idx]: