def test_interval(self):
     for type_, expected in [(oracle.INTERVAL(),
                             'INTERVAL DAY TO SECOND'),
                             (oracle.INTERVAL(day_precision=3),
                             'INTERVAL DAY(3) TO SECOND'),
                             (oracle.INTERVAL(second_precision=5),
                             'INTERVAL DAY TO SECOND(5)'),
                             (oracle.INTERVAL(day_precision=2,
                             second_precision=5),
                             'INTERVAL DAY(2) TO SECOND(5)')]:
         self.assert_compile(type_, expected)
     metadata = MetaData(testing.db)
     interval_table = Table('intervaltable', metadata, Column('id',
                            Integer, primary_key=True,
                            test_needs_autoincrement=True),
                            Column('day_interval',
                            oracle.INTERVAL(day_precision=3)))
     metadata.create_all()
     try:
         interval_table.insert().\
             execute(day_interval=datetime.timedelta(days=35,
                 seconds=5743))
         row = interval_table.select().execute().first()
         eq_(row['day_interval'], datetime.timedelta(days=35,
             seconds=5743))
     finally:
         metadata.drop_all()
예제 #2
0
 def test_interval(self):
     for type_, expected in [
         (oracle.INTERVAL(), 'INTERVAL DAY TO SECOND'),
         (oracle.INTERVAL(day_precision=3), 'INTERVAL DAY(3) TO SECOND'),
         (oracle.INTERVAL(second_precision=5), 'INTERVAL DAY TO SECOND(5)'),
         (oracle.INTERVAL(day_precision=2, second_precision=5),
          'INTERVAL DAY(2) TO SECOND(5)')
     ]:
         self.assert_compile(type_, expected)
예제 #3
0
 def test_interval(self):
     metadata = self.metadata
     interval_table = Table('intervaltable', metadata, Column('id',
                            Integer, primary_key=True,
                            test_needs_autoincrement=True),
                            Column('day_interval',
                            oracle.INTERVAL(day_precision=3)))
     metadata.create_all()
     interval_table.insert().\
         execute(day_interval=datetime.timedelta(days=35, seconds=5743))
     row = interval_table.select().execute().first()
     eq_(row['day_interval'], datetime.timedelta(days=35,
         seconds=5743))
예제 #4
0
 def test_interval(self, metadata, connection):
     interval_table = Table(
         "intervaltable",
         metadata,
         Column(
             "id", Integer, primary_key=True, test_needs_autoincrement=True
         ),
         Column("day_interval", oracle.INTERVAL(day_precision=3)),
     )
     metadata.create_all(connection)
     connection.execute(
         interval_table.insert(),
         dict(day_interval=datetime.timedelta(days=35, seconds=5743)),
     )
     row = connection.execute(interval_table.select()).first()
     eq_(row["day_interval"], datetime.timedelta(days=35, seconds=5743))
예제 #5
0
 def test_reflect_dates(self, metadata, connection):
     Table(
         "date_types",
         metadata,
         Column("d1", sqltypes.DATE),
         Column("d2", oracle.DATE),
         Column("d3", TIMESTAMP),
         Column("d4", TIMESTAMP(timezone=True)),
         Column("d5", oracle.INTERVAL(second_precision=5)),
     )
     metadata.create_all(connection)
     m = MetaData()
     t1 = Table("date_types", m, autoload_with=connection)
     assert isinstance(t1.c.d1.type, oracle.DATE)
     assert isinstance(t1.c.d1.type, DateTime)
     assert isinstance(t1.c.d2.type, oracle.DATE)
     assert isinstance(t1.c.d2.type, DateTime)
     assert isinstance(t1.c.d3.type, TIMESTAMP)
     assert not t1.c.d3.type.timezone
     assert isinstance(t1.c.d4.type, TIMESTAMP)
     assert t1.c.d4.type.timezone
     assert isinstance(t1.c.d5.type, oracle.INTERVAL)
예제 #6
0
 def test_reflect_dates(self):
     metadata = self.metadata
     Table(
         "date_types",
         metadata,
         Column('d1', sqltypes.DATE),
         Column('d2', oracle.DATE),
         Column('d3', TIMESTAMP),
         Column('d4', TIMESTAMP(timezone=True)),
         Column('d5', oracle.INTERVAL(second_precision=5)),
     )
     metadata.create_all()
     m = MetaData(testing.db)
     t1 = Table("date_types", m, autoload=True)
     assert isinstance(t1.c.d1.type, oracle.DATE)
     assert isinstance(t1.c.d1.type, DateTime)
     assert isinstance(t1.c.d2.type, oracle.DATE)
     assert isinstance(t1.c.d2.type, DateTime)
     assert isinstance(t1.c.d3.type, TIMESTAMP)
     assert not t1.c.d3.type.timezone
     assert isinstance(t1.c.d4.type, TIMESTAMP)
     assert t1.c.d4.type.timezone
     assert isinstance(t1.c.d5.type, oracle.INTERVAL)
예제 #7
0
class DialectTypesTest(fixtures.TestBase, AssertsCompiledSQL):
    __dialect__ = oracle.OracleDialect()

    def test_no_clobs_for_string_params(self):
        """test that simple string params get a DBAPI type of
        VARCHAR, not CLOB. This is to prevent setinputsizes
        from setting up cx_oracle.CLOBs on
        string-based bind params [ticket:793]."""

        class FakeDBAPI(object):
            def __getattr__(self, attr):
                return attr

        dialect = oracle.OracleDialect()
        dbapi = FakeDBAPI()

        b = bindparam("foo", "hello world!")
        eq_(b.type.dialect_impl(dialect).get_dbapi_type(dbapi), "STRING")

        b = bindparam("foo", "hello world!")
        eq_(b.type.dialect_impl(dialect).get_dbapi_type(dbapi), "STRING")

    def test_long(self):
        self.assert_compile(oracle.LONG(), "LONG")

    @testing.combinations(
        (Date(), cx_oracle._OracleDate),
        (oracle.OracleRaw(), cx_oracle._OracleRaw),
        (String(), String),
        (VARCHAR(), cx_oracle._OracleString),
        (DATE(), cx_oracle._OracleDate),
        (oracle.DATE(), oracle.DATE),
        (String(50), cx_oracle._OracleString),
        (Unicode(), cx_oracle._OracleUnicodeStringCHAR),
        (Text(), cx_oracle._OracleText),
        (UnicodeText(), cx_oracle._OracleUnicodeTextCLOB),
        (CHAR(), cx_oracle._OracleChar),
        (NCHAR(), cx_oracle._OracleNChar),
        (NVARCHAR(), cx_oracle._OracleUnicodeStringNCHAR),
        (oracle.RAW(50), cx_oracle._OracleRaw),
    )
    def test_type_adapt(self, start, test):
        dialect = cx_oracle.dialect()

        assert isinstance(
            start.dialect_impl(dialect), test
        ), "wanted %r got %r" % (test, start.dialect_impl(dialect))

    @testing.combinations(
        (String(), String),
        (VARCHAR(), cx_oracle._OracleString),
        (String(50), cx_oracle._OracleString),
        (Unicode(), cx_oracle._OracleUnicodeStringNCHAR),
        (Text(), cx_oracle._OracleText),
        (UnicodeText(), cx_oracle._OracleUnicodeTextNCLOB),
        (NCHAR(), cx_oracle._OracleNChar),
        (NVARCHAR(), cx_oracle._OracleUnicodeStringNCHAR),
    )
    def test_type_adapt_nchar(self, start, test):
        dialect = cx_oracle.dialect(use_nchar_for_unicode=True)

        assert isinstance(
            start.dialect_impl(dialect), test
        ), "wanted %r got %r" % (test, start.dialect_impl(dialect))

    def test_raw_compile(self):
        self.assert_compile(oracle.RAW(), "RAW")
        self.assert_compile(oracle.RAW(35), "RAW(35)")

    def test_char_length(self):
        self.assert_compile(VARCHAR(50), "VARCHAR(50 CHAR)")

        oracle8dialect = oracle.dialect()
        oracle8dialect.server_version_info = (8, 0)
        self.assert_compile(VARCHAR(50), "VARCHAR(50)", dialect=oracle8dialect)

        self.assert_compile(NVARCHAR(50), "NVARCHAR2(50)")
        self.assert_compile(CHAR(50), "CHAR(50)")

    @testing.combinations(
        (String(50), "VARCHAR2(50 CHAR)"),
        (Unicode(50), "VARCHAR2(50 CHAR)"),
        (NVARCHAR(50), "NVARCHAR2(50)"),
        (VARCHAR(50), "VARCHAR(50 CHAR)"),
        (oracle.NVARCHAR2(50), "NVARCHAR2(50)"),
        (oracle.VARCHAR2(50), "VARCHAR2(50 CHAR)"),
        (String(), "VARCHAR2"),
        (Unicode(), "VARCHAR2"),
        (NVARCHAR(), "NVARCHAR2"),
        (VARCHAR(), "VARCHAR"),
        (oracle.NVARCHAR2(), "NVARCHAR2"),
        (oracle.VARCHAR2(), "VARCHAR2"),
    )
    def test_varchar_types(self, typ, exp):
        dialect = oracle.dialect()
        self.assert_compile(typ, exp, dialect=dialect)

    @testing.combinations(
        (String(50), "VARCHAR2(50 CHAR)"),
        (Unicode(50), "NVARCHAR2(50)"),
        (NVARCHAR(50), "NVARCHAR2(50)"),
        (VARCHAR(50), "VARCHAR(50 CHAR)"),
        (oracle.NVARCHAR2(50), "NVARCHAR2(50)"),
        (oracle.VARCHAR2(50), "VARCHAR2(50 CHAR)"),
        (String(), "VARCHAR2"),
        (Unicode(), "NVARCHAR2"),
        (NVARCHAR(), "NVARCHAR2"),
        (VARCHAR(), "VARCHAR"),
        (oracle.NVARCHAR2(), "NVARCHAR2"),
        (oracle.VARCHAR2(), "VARCHAR2"),
    )
    def test_varchar_use_nchar_types(self, typ, exp):
        dialect = oracle.dialect(use_nchar_for_unicode=True)
        self.assert_compile(typ, exp, dialect=dialect)

    @testing.combinations(
        (oracle.INTERVAL(), "INTERVAL DAY TO SECOND"),
        (oracle.INTERVAL(day_precision=3), "INTERVAL DAY(3) TO SECOND"),
        (oracle.INTERVAL(second_precision=5), "INTERVAL DAY TO SECOND(5)"),
        (
            oracle.INTERVAL(day_precision=2, second_precision=5),
            "INTERVAL DAY(2) TO SECOND(5)",
        ),
    )
    def test_interval(self, type_, expected):
        self.assert_compile(type_, expected)