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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2012-03-15 21:05:49 UTC
  • mfrom: (1.4.19)
  • Revision ID: package-import@ubuntu.com-20120315210549-fiuynu6jue9keqlh
Tags: 0.7.6-1
* New upstream release
* debhelper's compatibility bumped to 7
* Standards-Version bumped to 3.9.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
Precision Numerics
78
78
------------------
79
79
 
80
 
The SQLAlchemy dialect goes thorugh a lot of steps to ensure
 
80
The SQLAlchemy dialect goes through a lot of steps to ensure
81
81
that decimal numbers are sent and received with full accuracy.
82
82
An "outputtypehandler" callable is associated with each
83
83
cx_oracle connection object which detects numeric types and
89
89
the ``asdecimal`` flag is ``False`` (default on :class:`.Float`,
90
90
optional on :class:`.Numeric`).
91
91
 
 
92
Because the handler coerces to ``Decimal`` in all cases first,
 
93
the feature can detract significantly from performance.
 
94
If precision numerics aren't required, the decimal handling
 
95
can be disabled by passing the flag ``coerce_to_decimal=False``
 
96
to :func:`.create_engine`::
 
97
 
 
98
    engine = create_engine("oracle+cx_oracle://dsn", 
 
99
                        coerce_to_decimal=False)
 
100
 
 
101
The ``coerce_to_decimal`` flag is new in 0.7.6.
 
102
 
 
103
Another alternative to performance is to use the 
 
104
`cdecimal <http://pypi.python.org/pypi/cdecimal/>`_ library; 
 
105
see :class:`.Numeric` for additional notes.
 
106
 
92
107
The handler attempts to use the "precision" and "scale"
93
108
attributes of the result set column to best determine if
94
109
subsequent incoming values should be received as ``Decimal`` as
468
483
                auto_convert_lobs=True, 
469
484
                threaded=True, 
470
485
                allow_twophase=True, 
 
486
                coerce_to_decimal=True,
471
487
                arraysize=50, **kwargs):
472
488
        OracleDialect.__init__(self, **kwargs)
473
489
        self.threaded = threaded
491
507
        self._cx_oracle_unicode_types = types("UNICODE", "NCLOB")
492
508
        self._cx_oracle_binary_types = types("BFILE", "CLOB", "NCLOB", "BLOB") 
493
509
        self.supports_unicode_binds = self.cx_oracle_ver >= (5, 0)
494
 
        self.supports_native_decimal = self.cx_oracle_ver >= (5, 0)
 
510
 
 
511
        self.supports_native_decimal = (
 
512
                                        self.cx_oracle_ver >= (5, 0) and 
 
513
                                        coerce_to_decimal
 
514
                                    )
 
515
 
495
516
        self._cx_oracle_native_nvarchar = self.cx_oracle_ver >= (5, 0)
496
517
 
497
518
        if self.cx_oracle_ver is None:
603
624
                                    size, precision, scale):
604
625
            # convert all NUMBER with precision + positive scale to Decimal
605
626
            # this almost allows "native decimal" mode.
606
 
            if defaultType == cx_Oracle.NUMBER and precision and scale > 0:
 
627
            if self.supports_native_decimal and \
 
628
                    defaultType == cx_Oracle.NUMBER and \
 
629
                    precision and scale > 0:
607
630
                return cursor.var(
608
631
                            cx_Oracle.STRING, 
609
632
                            255, 
614
637
            # make a decision based on each value received - the type 
615
638
            # may change from row to row (!).   This kills
616
639
            # off "native decimal" mode, handlers still needed.
617
 
            elif defaultType == cx_Oracle.NUMBER \
 
640
            elif self.supports_native_decimal and \
 
641
                    defaultType == cx_Oracle.NUMBER \
618
642
                    and not precision and scale <= 0:
619
643
                return cursor.var(
620
644
                            cx_Oracle.STRING,