~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/dialects/oracle/cx_oracle.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-08-01 23:18:16 UTC
  • mfrom: (1.4.15 upstream) (16.1.14 experimental)
  • Revision ID: james.westby@ubuntu.com-20110801231816-6lx797pi3q1fpqst
Tags: 0.7.2-1
* New upstream release
* Bump minimum required python-mako version to 0.4.1 (closes: 635898)

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
from sqlalchemy import types as sqltypes, util, exc, processors
128
128
from datetime import datetime
129
129
import random
130
 
from decimal import Decimal
 
130
import collections
 
131
from sqlalchemy.util.compat import decimal
131
132
import re
132
133
 
133
134
class _OracleNumeric(sqltypes.Numeric):
154
155
                def to_decimal(value):
155
156
                    if value is None:
156
157
                        return None
157
 
                    elif isinstance(value, Decimal):
 
158
                    elif isinstance(value, decimal.Decimal):
158
159
                        return value
159
160
                    else:
160
 
                        return Decimal(fstring % value)
 
161
                        return decimal.Decimal(fstring % value)
161
162
                return to_decimal
162
163
            else:
163
164
                if self.precision is None and self.scale is None:
338
339
                                                        self.out_parameters[name]
339
340
 
340
341
    def create_cursor(self):
341
 
        c = self._connection.connection.cursor()
 
342
        c = self._dbapi_connection.cursor()
342
343
        if self.dialect.arraysize:
343
344
            c.arraysize = self.dialect.arraysize
344
345
 
428
429
        return ret
429
430
 
430
431
    def _buffer_rows(self):
431
 
        return [tuple(self._returning_params["ret_%d" % i] 
432
 
                    for i, c in enumerate(self._returning_params))]
 
432
        return collections.deque([tuple(self._returning_params["ret_%d" % i] 
 
433
                    for i, c in enumerate(self._returning_params))])
433
434
 
434
435
class OracleDialect_cx_oracle(OracleDialect):
435
436
    execution_ctx_cls = OracleExecutionContext_cx_oracle
580
581
            self._detect_decimal = \
581
582
                lambda value: _detect_decimal(value.replace(char, '.'))
582
583
            self._to_decimal = \
583
 
                lambda value: Decimal(value.replace(char, '.'))
 
584
                lambda value: decimal.Decimal(value.replace(char, '.'))
584
585
 
585
586
    def _detect_decimal(self, value):
586
587
        if "." in value:
587
 
            return Decimal(value)
 
588
            return decimal.Decimal(value)
588
589
        else:
589
590
            return int(value)
590
591
 
591
 
    _to_decimal = Decimal
 
592
    _to_decimal = decimal.Decimal
592
593
 
593
594
    def on_connect(self):
594
595
        if self.cx_oracle_ver < (5,):
684
685
                        for x in connection.connection.version.split('.')
685
686
                    )
686
687
 
687
 
    def is_disconnect(self, e):
 
688
    def is_disconnect(self, e, connection, cursor):
 
689
        error, = e.args
688
690
        if isinstance(e, self.dbapi.InterfaceError):
689
691
            return "not connected" in str(e)
 
692
        elif hasattr(error, 'code'):
 
693
            # ORA-00028: your session has been killed
 
694
            # ORA-03114: not connected to ORACLE
 
695
            # ORA-03113: end-of-file on communication channel
 
696
            # ORA-01033: ORACLE initialization or shutdown in progress
 
697
            return error.code in (28, 3114, 3113, 1033)
690
698
        else:
691
 
            return "ORA-03114" in str(e) or "ORA-03113" in str(e)
 
699
            return False
692
700
 
693
701
    def create_xid(self):
694
702
        """create a two-phase transaction ID.