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

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/dialects/postgresql/base.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:
73
73
* ``REPEATABLE READ``
74
74
* ``SERIALIZABLE``
75
75
 
76
 
The :mod:`~sqlalchemy.dialects.postgresql.psycopg2` dialect also offers the special level ``AUTOCOMMIT``.  See
77
 
:ref:`psycopg2_isolation_level` for details.
 
76
The :mod:`~sqlalchemy.dialects.postgresql.psycopg2` and
 
77
:mod:`~sqlalchemy.dialects.postgresql.pg8000` dialects also offer the
 
78
special level ``AUTOCOMMIT``.
 
79
 
 
80
.. seealso::
 
81
 
 
82
    :ref:`psycopg2_isolation_level`
 
83
 
 
84
    :ref:`pg8000_isolation_level`
78
85
 
79
86
.. _postgresql_schema_reflection:
80
87
 
402
409
PGMacAddr = MACADDR
403
410
 
404
411
 
 
412
class OID(sqltypes.TypeEngine):
 
413
    """Provide the Postgresql OID type.
 
414
 
 
415
    .. versionadded:: 0.9.5
 
416
 
 
417
    """
 
418
    __visit_name__ = "OID"
 
419
 
 
420
 
405
421
class TIMESTAMP(sqltypes.TIMESTAMP):
406
422
    def __init__(self, timezone=False, precision=None):
407
423
        super(TIMESTAMP, self).__init__(timezone=timezone)
702
718
        """Define comparison operations for :class:`.ARRAY`."""
703
719
 
704
720
        def __getitem__(self, index):
 
721
            shift_indexes = 1 if self.expr.type.zero_indexes else 0
705
722
            if isinstance(index, slice):
 
723
                if shift_indexes:
 
724
                    index = slice(
 
725
                        index.start + shift_indexes,
 
726
                        index.stop + shift_indexes,
 
727
                        index.step
 
728
                    )
706
729
                index = _Slice(index, self)
707
730
                return_type = self.type
708
731
            else:
 
732
                index += shift_indexes
709
733
                return_type = self.type.item_type
 
734
 
710
735
            return self._binary_operate(self.expr, operators.getitem, index,
711
736
                            result_type=return_type)
712
737
 
797
822
 
798
823
    comparator_factory = Comparator
799
824
 
800
 
    def __init__(self, item_type, as_tuple=False, dimensions=None):
 
825
    def __init__(self, item_type, as_tuple=False, dimensions=None,
 
826
                 zero_indexes=False):
801
827
        """Construct an ARRAY.
802
828
 
803
829
        E.g.::
824
850
         meaning they can store any number of dimensions no matter how
825
851
         they were declared.
826
852
 
 
853
        :param zero_indexes=False: when True, index values will be converted
 
854
         between Python zero-based and Postgresql one-based indexes, e.g.
 
855
         a value of one will be added to all index values before passing
 
856
         to the database.
 
857
 
 
858
         .. versionadded:: 0.9.5
 
859
 
827
860
        """
828
861
        if isinstance(item_type, ARRAY):
829
862
            raise ValueError("Do not nest ARRAY types; ARRAY(basetype) "
833
866
        self.item_type = item_type
834
867
        self.as_tuple = as_tuple
835
868
        self.dimensions = dimensions
 
869
        self.zero_indexes = zero_indexes
836
870
 
837
871
    @property
838
872
    def python_type(self):
1055
1089
    'bit': BIT,
1056
1090
    'bit varying': BIT,
1057
1091
    'macaddr': MACADDR,
 
1092
    'oid': OID,
1058
1093
    'double precision': DOUBLE_PRECISION,
1059
1094
    'timestamp': TIMESTAMP,
1060
1095
    'timestamp with time zone': TIMESTAMP,
1328
1363
    def visit_MACADDR(self, type_):
1329
1364
        return "MACADDR"
1330
1365
 
 
1366
    def visit_OID(self, type_):
 
1367
        return "OID"
 
1368
 
1331
1369
    def visit_FLOAT(self, type_):
1332
1370
        if not type_.precision:
1333
1371
            return "FLOAT"