Example #1
0
    def setup(self):
        metadata.create_all()
        t.insert().execute(
            [
                dict(
                    ("field%d" % fnum, u("value%d" % fnum))
                    for fnum in range(NUM_FIELDS)
                )
                for r_num in range(NUM_RECORDS)
            ]
        )
        t2.insert().execute(
            [
                dict(
                    ("field%d" % fnum, u("value%d" % fnum))
                    for fnum in range(NUM_FIELDS)
                )
                for r_num in range(NUM_RECORDS)
            ]
        )

        # warm up type caches
        t.select().execute().fetchall()
        t2.select().execute().fetchall()
        testing.db.execute(
            "SELECT %s FROM table1"
            % (", ".join("field%d" % fnum for fnum in range(NUM_FIELDS)))
        ).fetchall()
        testing.db.execute(
            "SELECT %s FROM table2"
            % (", ".join("field%d" % fnum for fnum in range(NUM_FIELDS)))
        ).fetchall()
Example #2
0
 def test_composed_multiple(self):
     table = self.tables.some_table
     lx = (table.c.x + table.c.y).label('lx')
     ly = (func.lower(table.c.q) + table.c.p).label('ly')
     self._assert_result(
         select([lx, ly]).order_by(lx, ly.desc()),
         [(3, util.u('q1p3')), (5, util.u('q2p2')), (7, util.u('q3p1'))]
     )
Example #3
0
    def test_description_encoding(self):
        # amazingly, pysqlite seems to still deliver cursor.description
        # as encoded bytes in py2k

        t = Table("x", self.metadata, Column(u("méil"), Integer, primary_key=True), Column(ue("\u6e2c\u8a66"), Integer))
        self.metadata.create_all(testing.db)

        result = testing.db.execute(t.select())
        assert u("méil") in result.keys()
        assert ue("\u6e2c\u8a66") in result.keys()
Example #4
0
    def test_insert(self):
        t1.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 5})
        t2.insert().execute({u("a"): 1, u("b"): 1})
        t3.insert().execute(
            {ue("\u6e2c\u8a66_id"): 1, ue("unitable1_\u6e2c\u8a66"): 5, u("Unitéble2_b"): 1, ue("\u6e2c\u8a66_self"): 1}
        )

        assert t1.select().execute().fetchall() == [(1, 5)]
        assert t2.select().execute().fetchall() == [(1, 1)]
        assert t3.select().execute().fetchall() == [(1, 5, 1, 1)]
Example #5
0
    def test_reflect(self):
        t1.insert().execute({u('méil'): 2, ue('\u6e2c\u8a66'): 7})
        t2.insert().execute({u('a'): 2, u('b'): 2})
        t3.insert().execute({ue('\u6e2c\u8a66_id'): 2,
                             ue('unitable1_\u6e2c\u8a66'): 7,
                             u('Unitéble2_b'): 2,
                             ue('\u6e2c\u8a66_self'): 2})

        meta = MetaData(testing.db)
        tt1 = Table(t1.name, meta, autoload=True)
        tt2 = Table(t2.name, meta, autoload=True)
        tt3 = Table(t3.name, meta, autoload=True)

        tt1.insert().execute({u('méil'): 1, ue('\u6e2c\u8a66'): 5})
        tt2.insert().execute({u('méil'): 1, ue('\u6e2c\u8a66'): 1})
        tt3.insert().execute({ue('\u6e2c\u8a66_id'): 1,
                              ue('unitable1_\u6e2c\u8a66'): 5,
                              u('Unitéble2_b'): 1,
                              ue('\u6e2c\u8a66_self'): 1})

        self.assert_(tt1.select(order_by=desc(u('méil'))).execute().fetchall() ==
                     [(2, 7), (1, 5)])
        self.assert_(tt2.select(order_by=desc(u('méil'))).execute().fetchall() ==
                     [(2, 2), (1, 1)])
        self.assert_(tt3.select(order_by=desc(ue('\u6e2c\u8a66_id'))).
                     execute().fetchall() ==
                     [(2, 7, 2, 2), (1, 5, 1, 1)])
Example #6
0
    def test_reflect(self):
        t1.insert().execute({u("méil"): 2, ue("\u6e2c\u8a66"): 7})
        t2.insert().execute({u("a"): 2, u("b"): 2})
        t3.insert().execute(
            {ue("\u6e2c\u8a66_id"): 2, ue("unitable1_\u6e2c\u8a66"): 7, u("Unitéble2_b"): 2, ue("\u6e2c\u8a66_self"): 2}
        )

        meta = MetaData(unicode_bind)
        tt1 = Table(t1.name, meta, autoload=True)
        tt2 = Table(t2.name, meta, autoload=True)
        tt3 = Table(t3.name, meta, autoload=True)

        tt1.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 5})
        tt2.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 1})
        tt3.insert().execute(
            {ue("\u6e2c\u8a66_id"): 1, ue("unitable1_\u6e2c\u8a66"): 5, u("Unitéble2_b"): 1, ue("\u6e2c\u8a66_self"): 1}
        )

        self.assert_(tt1.select(order_by=desc(u("méil"))).execute().fetchall() == [(2, 7), (1, 5)])
        self.assert_(tt2.select(order_by=desc(u("méil"))).execute().fetchall() == [(2, 2), (1, 1)])
        self.assert_(
            tt3.select(order_by=desc(ue("\u6e2c\u8a66_id"))).execute().fetchall() == [(2, 7, 2, 2), (1, 5, 1, 1)]
        )
        meta.drop_all()
        metadata.create_all()
Example #7
0
    def test_insert(self):
        t1.insert().execute({u('méil'):1, ue('\u6e2c\u8a66'):5})
        t2.insert().execute({u('a'):1, u('b'):1})
        t3.insert().execute({ue('\u6e2c\u8a66_id'): 1,
                             ue('unitable1_\u6e2c\u8a66'): 5,
                             u('Unitéble2_b'): 1,
                             ue('\u6e2c\u8a66_self'): 1})

        assert t1.select().execute().fetchall() == [(1, 5)]
        assert t2.select().execute().fetchall() == [(1, 1)]
        assert t3.select().execute().fetchall() == [(1, 5, 1, 1)]
Example #8
0
 def test_wrap_unicode_arg(self):
     # this is not supported by the API but oslo_db is doing it
     orig = sa_exceptions.DBAPIError(False, False, False)
     orig.args = [u('méil')]
     eq_(
         compat.text_type(orig),
         compat.u(
             "méil (Background on this error at: "
             "http://sqlalche.me/e/dbapi)")
     )
     eq_(orig.args, (u('méil'),))
Example #9
0
    def test_create_drop_enum(self):
        # test escaping and unicode within CREATE TYPE for ENUM
        typ = postgresql.ENUM("val1", "val2", "val's 3", u("méil"), name="myname")
        self.assert_compile(
            postgresql.CreateEnumType(typ), u("CREATE TYPE myname AS " "ENUM ('val1', 'val2', 'val''s 3', 'méil')")
        )

        typ = postgresql.ENUM("val1", "val2", "val's 3", name="PleaseQuoteMe")
        self.assert_compile(
            postgresql.CreateEnumType(typ), 'CREATE TYPE "PleaseQuoteMe" AS ENUM ' "('val1', 'val2', 'val''s 3')"
        )
Example #10
0
    def setup(self):
        metadata.create_all()
        t.insert().execute([dict(('field%d' % fnum, u('value%d' % fnum))
                                 for fnum in range(NUM_FIELDS)) for r_num in
                            range(NUM_RECORDS)])
        t2.insert().execute([dict(('field%d' % fnum, u('value%d' % fnum))
                                  for fnum in range(NUM_FIELDS)) for r_num in
                             range(NUM_RECORDS)])

        # warm up type caches
        t.select().execute().fetchall()
        t2.select().execute().fetchall()
Example #11
0
    def test_quoted_column_non_unicode(self):
        metadata = self.metadata
        table = Table(
            "atable",
            metadata,
            Column("_underscorecolumn", Unicode(255), primary_key=True),
        )
        metadata.create_all()

        table.insert().execute({"_underscorecolumn": u("’é")})
        result = testing.db.execute(
            table.select().where(table.c._underscorecolumn == u("’é"))
        ).scalar()
        eq_(result, u("’é"))
Example #12
0
    def test_col_targeting(self):
        t1.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 5})
        t2.insert().execute({u("a"): 1, u("b"): 1})
        t3.insert().execute(
            {
                ue("\u6e2c\u8a66_id"): 1,
                ue("unitable1_\u6e2c\u8a66"): 5,
                u("Unitéble2_b"): 1,
                ue("\u6e2c\u8a66_self"): 1,
            }
        )

        row = t1.select().execute().first()
        eq_(row[t1.c[u("méil")]], 1)
        eq_(row[t1.c[ue("\u6e2c\u8a66")]], 5)

        row = t2.select().execute().first()
        eq_(row[t2.c[u("a")]], 1)
        eq_(row[t2.c[u("b")]], 1)

        row = t3.select().execute().first()
        eq_(row[t3.c[ue("\u6e2c\u8a66_id")]], 1)
        eq_(row[t3.c[ue("unitable1_\u6e2c\u8a66")]], 5)
        eq_(row[t3.c[u("Unitéble2_b")]], 1)
        eq_(row[t3.c[ue("\u6e2c\u8a66_self")]], 1)
Example #13
0
 def test_unicode_nchar_mode(self):
     self._test_setinputsizes(
         Unicode(30),
         u("test"),
         testing.db.dialect.dbapi.NCHAR,
         set_nchar_flag=True,
     )
Example #14
0
 def test_unicodetext_nchar_mode(self):
     self._test_setinputsizes(
         UnicodeText(),
         u("test"),
         testing.db.dialect.dbapi.NCLOB,
         set_nchar_flag=True,
     )
Example #15
0
    def test_reflect_nvarchar(self):
        metadata = self.metadata
        Table(
            "tnv",
            metadata,
            Column("nv_data", sqltypes.NVARCHAR(255)),
            Column("c_data", sqltypes.NCHAR(20)),
        )
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("tnv", m2, autoload=True)
        assert isinstance(t2.c.nv_data.type, sqltypes.NVARCHAR)
        assert isinstance(t2.c.c_data.type, sqltypes.NCHAR)

        if testing.against("oracle+cx_oracle"):
            assert isinstance(
                t2.c.nv_data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleUnicodeStringNCHAR,
            )

            assert isinstance(
                t2.c.c_data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleUnicodeStringNCHAR,
            )

        data = u("m’a réveillé.")
        with testing.db.connect() as conn:
            conn.execute(t2.insert(), dict(nv_data=data, c_data=data))
            nv_data, c_data = conn.execute(t2.select()).first()
            eq_(nv_data, data)
            eq_(c_data, data + (" " * 7))  # char is space padded
            assert isinstance(nv_data, util.text_type)
            assert isinstance(c_data, util.text_type)
Example #16
0
 def test_string_text_explicit_literal_binds(self):
     # the literal experssion here coerces the right side to
     # Unicode on Python 3 for plain string, test with unicode
     # string just to confirm literal is doing this
     self.assert_compile(
         column("x", String()) == literal(util.u("foo")),
         "x = N'foo'",
         literal_binds=True,
     )
Example #17
0
    def setup_class(cls):
        global metadata, t1, t2, t3

        metadata = MetaData(testing.db)
        t1 = Table(u('unitable1'), metadata,
                   Column(u('méil'), Integer, primary_key=True),
                   Column(ue('\u6e2c\u8a66'), Integer),
                   test_needs_fk=True,
                   )
        t2 = Table(
            u('Unitéble2'),
            metadata,
            Column(
                u('méil'),
                Integer,
                primary_key=True,
                key="a"),
            Column(
                ue('\u6e2c\u8a66'),
                Integer,
                ForeignKey(
                    u('unitable1.méil')),
                key="b"),
            test_needs_fk=True,
        )

        # Few DBs support Unicode foreign keys
        if testing.against('sqlite'):
            t3 = Table(ue('\u6e2c\u8a66'), metadata,
                       Column(ue('\u6e2c\u8a66_id'), Integer, primary_key=True,
                              autoincrement=False),
                       Column(ue('unitable1_\u6e2c\u8a66'), Integer,
                              ForeignKey(ue('unitable1.\u6e2c\u8a66'))
                              ),
                       Column(u('Unitéble2_b'), Integer,
                              ForeignKey(u('Unitéble2.b'))
                              ),
                       Column(ue('\u6e2c\u8a66_self'), Integer,
                              ForeignKey(ue('\u6e2c\u8a66.\u6e2c\u8a66_id'))
                              ),
                       test_needs_fk=True,
                       )
        else:
            t3 = Table(ue('\u6e2c\u8a66'), metadata,
                       Column(ue('\u6e2c\u8a66_id'), Integer, primary_key=True,
                              autoincrement=False),
                       Column(ue('unitable1_\u6e2c\u8a66'), Integer),
                       Column(u('Unitéble2_b'), Integer),
                       Column(ue('\u6e2c\u8a66_self'), Integer),
                       test_needs_fk=True,
                       )
        metadata.create_all()
Example #18
0
    def test_no_convert_unicode(self):
        """test no utf-8 encoding occurs"""

        dialect = sqlite.dialect()
        for t in (
            String(convert_unicode=True),
            CHAR(convert_unicode=True),
            Unicode(),
            UnicodeText(),
            String(convert_unicode=True),
            CHAR(convert_unicode=True),
            Unicode(),
            UnicodeText(),
        ):
            bindproc = t.dialect_impl(dialect).bind_processor(dialect)
            assert not bindproc or isinstance(bindproc(util.u("some string")), util.text_type)
Example #19
0
    def setup_class(cls):
        global unicode_bind, metadata, t1, t2, t3

        unicode_bind = utf8_engine()

        metadata = MetaData(unicode_bind)
        t1 = Table(
            u("unitable1"),
            metadata,
            Column(u("méil"), Integer, primary_key=True),
            Column(ue("\u6e2c\u8a66"), Integer),
            test_needs_fk=True,
        )
        t2 = Table(
            u("Unitéble2"),
            metadata,
            Column(u("méil"), Integer, primary_key=True, key="a"),
            Column(ue("\u6e2c\u8a66"), Integer, ForeignKey(u("unitable1.méil")), key="b"),
            test_needs_fk=True,
        )

        # Few DBs support Unicode foreign keys
        if testing.against("sqlite"):
            t3 = Table(
                ue("\u6e2c\u8a66"),
                metadata,
                Column(ue("\u6e2c\u8a66_id"), Integer, primary_key=True, autoincrement=False),
                Column(ue("unitable1_\u6e2c\u8a66"), Integer, ForeignKey(ue("unitable1.\u6e2c\u8a66"))),
                Column(u("Unitéble2_b"), Integer, ForeignKey(u("Unitéble2.b"))),
                Column(ue("\u6e2c\u8a66_self"), Integer, ForeignKey(ue("\u6e2c\u8a66.\u6e2c\u8a66_id"))),
                test_needs_fk=True,
            )
        else:
            t3 = Table(
                ue("\u6e2c\u8a66"),
                metadata,
                Column(ue("\u6e2c\u8a66_id"), Integer, primary_key=True, autoincrement=False),
                Column(ue("unitable1_\u6e2c\u8a66"), Integer),
                Column(u("Unitéble2_b"), Integer),
                Column(ue("\u6e2c\u8a66_self"), Integer),
                test_needs_fk=True,
            )
        metadata.create_all()
Example #20
0
    def test_reflect_unicode_no_nvarchar(self):
        metadata = self.metadata
        Table('tnv', metadata, Column('data', sqltypes.Unicode(255)))
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table('tnv', m2, autoload=True)
        assert isinstance(t2.c.data.type, sqltypes.VARCHAR)

        if testing.against('oracle+cx_oracle'):
            assert isinstance(
                t2.c.data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleString)

        data = u('m’a réveillé.')
        t2.insert().execute(data=data)
        res = t2.select().execute().first()['data']
        eq_(res, data)
        assert isinstance(res, util.text_type)
Example #21
0
    def test_quoted_column_unicode(self):
        metadata = self.metadata
        table = Table("atable", metadata,
                      Column(u("méil"), Unicode(255), primary_key=True))
        metadata.create_all()

        table.insert().execute(
            {u('méil'): u('’é')},
        )
        result = testing.db.execute(
            table.select().where(table.c[u('méil')] == u('’é'))
        ).scalar()
        eq_(result, u('’é'))
Example #22
0
    def test_unicode_roundtrip(self):
        set_table = Table(
            "t",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("data", mysql.SET(u("réveillé"), u("drôle"), u("S’il"))),
        )

        set_table.create()
        with testing.db.begin() as conn:
            conn.execute(
                set_table.insert(), {"data": set([u("réveillé"), u("drôle")])}
            )

            row = conn.execute(set_table.select()).first()

            eq_(row, (1, set([u("réveillé"), u("drôle")])))
Example #23
0
    def test_col_targeting(self):
        t1.insert().execute({u('méil'): 1, ue('\u6e2c\u8a66'): 5})
        t2.insert().execute({u('a'): 1, u('b'): 1})
        t3.insert().execute({ue('\u6e2c\u8a66_id'): 1,
                             ue('unitable1_\u6e2c\u8a66'): 5,
                             u('Unitéble2_b'): 1,
                             ue('\u6e2c\u8a66_self'): 1})

        row = t1.select().execute().first()
        eq_(row[t1.c[u('méil')]], 1)
        eq_(row[t1.c[ue('\u6e2c\u8a66')]], 5)

        row = t2.select().execute().first()
        eq_(row[t2.c[u('a')]], 1)
        eq_(row[t2.c[u('b')]], 1)

        row = t3.select().execute().first()
        eq_(row[t3.c[ue('\u6e2c\u8a66_id')]], 1)
        eq_(row[t3.c[ue('unitable1_\u6e2c\u8a66')]], 5)
        eq_(row[t3.c[u('Unitéble2_b')]], 1)
        eq_(row[t3.c[ue('\u6e2c\u8a66_self')]], 1)
Example #24
0
    def test_charset_collate_table(self):
        t = Table('foo', self.metadata,
                  Column('id', Integer),
                  Column('data', UnicodeText),
                  mysql_default_charset='utf8',
                  mysql_collate='utf8_bin')
        t.create()
        m2 = MetaData(testing.db)
        t2 = Table('foo', m2, autoload=True)
        eq_(t2.kwargs['mysql_collate'], 'utf8_bin')
        eq_(t2.kwargs['mysql_default charset'], 'utf8')

        # test [ticket:2906]
        # in order to test the condition here, need to use
        # MySQLdb 1.2.3 and also need to pass either use_unicode=1
        # or charset=utf8 to the URL.
        t.insert().execute(id=1, data=u('some text'))
        assert isinstance(testing.db.scalar(select([t.c.data])),
                          util.text_type)
Example #25
0
    def test_reflect_nvarchar(self):
        metadata = self.metadata
        Table("tnv", metadata, Column("data", sqltypes.NVARCHAR(255)))
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("tnv", m2, autoload=True)
        assert isinstance(t2.c.data.type, sqltypes.NVARCHAR)

        if testing.against("oracle+cx_oracle"):
            assert isinstance(
                t2.c.data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleUnicodeStringNCHAR,
            )

        data = u("m’a réveillé.")
        t2.insert().execute(data=data)
        res = t2.select().execute().first()["data"]
        eq_(res, data)
        assert isinstance(res, util.text_type)
Example #26
0
    def test_reflect_nvarchar(self):
        metadata = self.metadata
        Table('tnv', metadata, Column('data', sqltypes.NVARCHAR(255)))
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table('tnv', m2, autoload=True)
        assert isinstance(t2.c.data.type, sqltypes.NVARCHAR)

        if testing.against('oracle+cx_oracle'):
            # nvarchar returns unicode natively.  cx_oracle
            # _OracleNVarChar type should be at play here.
            assert isinstance(
                t2.c.data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleNVarChar)

        data = u('m’a réveillé.')
        t2.insert().execute(data=data)
        res = t2.select().execute().first()['data']
        eq_(res, data)
        assert isinstance(res, util.text_type)
Example #27
0
    def test_charset_collate_table(self):
        t = Table(
            "foo",
            self.metadata,
            Column("id", Integer),
            Column("data", UnicodeText),
            mysql_default_charset="utf8",
            mysql_collate="utf8_bin",
        )
        t.create()
        m2 = MetaData(testing.db)
        t2 = Table("foo", m2, autoload=True)
        eq_(t2.kwargs["mysql_collate"], "utf8_bin")
        eq_(t2.kwargs["mysql_default charset"], "utf8")

        # test [ticket:2906]
        # in order to test the condition here, need to use
        # MySQLdb 1.2.3 and also need to pass either use_unicode=1
        # or charset=utf8 to the URL.
        t.insert().execute(id=1, data=u("some text"))
        assert isinstance(testing.db.scalar(select([t.c.data])), util.text_type)
Example #28
0
    def test_unicode_roundtrip(self):
        set_table = Table(
            't', self.metadata,
            Column('id', Integer, primary_key=True),
            Column('data', mysql.SET(
                u('réveillé'), u('drôle'), u('S’il'), convert_unicode=True)),
        )

        set_table.create()
        with testing.db.begin() as conn:
            conn.execute(
                set_table.insert(),
                {"data": set([u('réveillé'), u('drôle')])})

            row = conn.execute(
                set_table.select()
            ).first()

            eq_(
                row,
                (1, set([u('réveillé'), u('drôle')]))
            )
Example #29
0
class SetInputSizesTest(fixtures.TestBase):
    __only_on__ = "oracle+cx_oracle"
    __backend__ = True

    @testing.combinations(
        (SmallInteger, 25, int, False),
        (Integer, 25, int, False),
        (Numeric(10, 8), decimal.Decimal("25.34534"), None, False),
        (Float(15), 25.34534, None, False),
        (oracle.BINARY_DOUBLE, 25.34534, "NATIVE_FLOAT", False),
        (oracle.BINARY_FLOAT, 25.34534, "NATIVE_FLOAT", False),
        (oracle.DOUBLE_PRECISION, 25.34534, None, False),
        (Unicode(30), u("test"), "NCHAR", True),
        (UnicodeText(), u("test"), "NCLOB", True),
        (Unicode(30), u("test"), None, False),
        (UnicodeText(), u("test"), "CLOB", False),
        (String(30), "test", None, False),
        (CHAR(30), "test", "FIXED_CHAR", False),
        (NCHAR(30), u("test"), "FIXED_NCHAR", False),
        (oracle.LONG(), "test", None, False),
        argnames="datatype, value, sis_value_text, set_nchar_flag",
    )
    def test_setinputsizes(self, metadata, datatype, value, sis_value_text,
                           set_nchar_flag):
        if isinstance(sis_value_text, str):
            sis_value = getattr(testing.db.dialect.dbapi, sis_value_text)
        else:
            sis_value = sis_value_text

        class TestTypeDec(TypeDecorator):
            impl = NullType()

            def load_dialect_impl(self, dialect):
                if dialect.name == "oracle":
                    return dialect.type_descriptor(datatype)
                else:
                    return self.impl

        m = metadata
        # Oracle can have only one column of type LONG so we make three
        # tables rather than one table w/ three columns
        t1 = Table("t1", m, Column("foo", datatype))
        t2 = Table("t2", m,
                   Column("foo",
                          NullType().with_variant(datatype, "oracle")))
        t3 = Table("t3", m, Column("foo", TestTypeDec()))

        class CursorWrapper(object):
            # cx_oracle cursor can't be modified so we have to
            # invent a whole wrapping scheme

            def __init__(self, connection_fairy):
                self.cursor = connection_fairy.connection.cursor()
                self.mock = mock.Mock()
                connection_fairy.info["mock"] = self.mock

            def setinputsizes(self, *arg, **kw):
                self.mock.setinputsizes(*arg, **kw)
                self.cursor.setinputsizes(*arg, **kw)

            def __getattr__(self, key):
                return getattr(self.cursor, key)

        if set_nchar_flag:
            engine = testing_engine(options={"use_nchar_for_unicode": True})
        else:
            engine = testing.db

        with engine.connect() as conn:
            conn.begin()

            m.create_all(conn, checkfirst=False)

            connection_fairy = conn.connection
            for tab in [t1, t2, t3]:
                with mock.patch.object(
                        connection_fairy,
                        "cursor",
                        lambda: CursorWrapper(connection_fairy),
                ):
                    conn.execute(tab.insert(), {"foo": value})

                if sis_value:
                    eq_(
                        conn.info["mock"].mock_calls,
                        [mock.call.setinputsizes(foo=sis_value)],
                    )
                else:
                    eq_(
                        conn.info["mock"].mock_calls,
                        [mock.call.setinputsizes()],
                    )

    def test_event_no_native_float(self, metadata):
        def _remove_type(inputsizes, cursor, statement, parameters, context):
            for param, dbapitype in list(inputsizes.items()):
                if dbapitype is testing.db.dialect.dbapi.NATIVE_FLOAT:
                    del inputsizes[param]

        event.listen(testing.db, "do_setinputsizes", _remove_type)
        try:
            self.test_setinputsizes(metadata, oracle.BINARY_FLOAT, 25.34534,
                                    None, False)
        finally:
            event.remove(testing.db, "do_setinputsizes", _remove_type)
Example #30
0
    def test_unicode_enum(self):
        metadata = self.metadata
        t1 = Table(
            "table",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("value", Enum(u("réveillé"), u("drôle"), u("S’il"))),
            Column("value2", mysql.ENUM(u("réveillé"), u("drôle"), u("S’il"))),
        )
        metadata.create_all()
        t1.insert().execute(value=u("drôle"), value2=u("drôle"))
        t1.insert().execute(value=u("réveillé"), value2=u("réveillé"))
        t1.insert().execute(value=u("S’il"), value2=u("S’il"))
        eq_(
            t1.select().order_by(t1.c.id).execute().fetchall(),
            [
                (1, u("drôle"), u("drôle")),
                (2, u("réveillé"), u("réveillé")),
                (3, u("S’il"), u("S’il")),
            ],
        )

        # test reflection of the enum labels

        m2 = MetaData(testing.db)
        t2 = Table("table", m2, autoload=True)

        # TODO: what's wrong with the last element ?  is there
        #       latin-1 stuff forcing its way in ?

        eq_(t2.c.value.type.enums[0:2],
            [u("réveillé"), u("drôle")])  # u'S’il') # eh ?

        eq_(t2.c.value2.type.enums[0:2],
            [u("réveillé"), u("drôle")])  # u'S’il') # eh ?
    def define_tables(cls, metadata):
        global t1, t2, t3

        t1 = Table(
            u("unitable1"),
            metadata,
            Column(u("méil"), Integer, primary_key=True),
            Column(ue("\u6e2c\u8a66"), Integer),
            test_needs_fk=True,
        )
        t2 = Table(
            u("Unitéble2"),
            metadata,
            Column(u("méil"), Integer, primary_key=True, key="a"),
            Column(
                ue("\u6e2c\u8a66"),
                Integer,
                ForeignKey(u("unitable1.méil")),
                key="b",
            ),
            test_needs_fk=True,
        )

        # Few DBs support Unicode foreign keys
        if testing.against("sqlite"):
            t3 = Table(
                ue("\u6e2c\u8a66"),
                metadata,
                Column(
                    ue("\u6e2c\u8a66_id"),
                    Integer,
                    primary_key=True,
                    autoincrement=False,
                ),
                Column(
                    ue("unitable1_\u6e2c\u8a66"),
                    Integer,
                    ForeignKey(ue("unitable1.\u6e2c\u8a66")),
                ),
                Column(u("Unitéble2_b"), Integer,
                       ForeignKey(u("Unitéble2.b"))),
                Column(
                    ue("\u6e2c\u8a66_self"),
                    Integer,
                    ForeignKey(ue("\u6e2c\u8a66.\u6e2c\u8a66_id")),
                ),
                test_needs_fk=True,
            )
        else:
            t3 = Table(
                ue("\u6e2c\u8a66"),
                metadata,
                Column(
                    ue("\u6e2c\u8a66_id"),
                    Integer,
                    primary_key=True,
                    autoincrement=False,
                ),
                Column(ue("unitable1_\u6e2c\u8a66"), Integer),
                Column(u("Unitéble2_b"), Integer),
                Column(ue("\u6e2c\u8a66_self"), Integer),
                test_needs_fk=True,
            )
Example #32
0
 def test_nchar(self):
     self._test_setinputsizes(NCHAR(30), u("test"),
                              testing.db.dialect.dbapi.NCHAR)
Example #33
0
 def test_unicode(self):
     self._test_setinputsizes(
         Unicode(30), u("test"), testing.db.dialect.dbapi.NCHAR)
Example #34
0
 def test_unicode(self):
     self._test_setinputsizes(Unicode(30), u("test"),
                              testing.db.dialect.dbapi.NCHAR)
Example #35
0
    def test_unicode_enum(self):
        unicode_engine = utf8_engine()
        metadata = MetaData(unicode_engine)
        t1 = Table(
            'table', metadata, Column('id', Integer, primary_key=True),
            Column('value', Enum(u('réveillé'), u('drôle'), u('S’il'))),
            Column('value2', mysql.ENUM(u('réveillé'), u('drôle'), u('S’il'))))
        metadata.create_all()
        try:
            t1.insert().execute(value=u('drôle'), value2=u('drôle'))
            t1.insert().execute(value=u('réveillé'), value2=u('réveillé'))
            t1.insert().execute(value=u('S’il'), value2=u('S’il'))
            eq_(t1.select().order_by(t1.c.id).execute().fetchall(),
                [(1, u('drôle'), u('drôle')),
                 (2, u('réveillé'), u('réveillé')), (3, u('S’il'), u('S’il'))])

            # test reflection of the enum labels

            m2 = MetaData(testing.db)
            t2 = Table('table', m2, autoload=True)

            # TODO: what's wrong with the last element ?  is there
            # latin-1 stuff forcing its way in ?

            assert t2.c.value.type.enums[0:2] == \
                    (u('réveillé'), u('drôle'))  # u'S’il') # eh ?

            assert t2.c.value2.type.enums[0:2] == \
                    (u('réveillé'), u('drôle'))  # u'S’il') # eh ?
        finally:
            metadata.drop_all()
Example #36
0
 def test_string_text_literal_binds_explicit_unicode_right(self):
     self.assert_compile(
         column("x", String()) == util.u("foo"),
         "x = 'foo'",
         literal_binds=True,
     )
Example #37
0
 def test_unicode(self):
     self._test_setinputsizes(Unicode(30), u("test"), None)
Example #38
0
 def test_unicodetext(self):
     self._test_setinputsizes(UnicodeText(), u("test"),
                              testing.db.dialect.dbapi.CLOB)
Example #39
0
    def test_unicode_enum(self):
        metadata = self.metadata
        t1 = Table(
            'table', metadata,
            Column('id', Integer, primary_key=True),
            Column('value', Enum(u('réveillé'), u('drôle'), u('S’il'))),
            Column('value2', mysql.ENUM(u('réveillé'), u('drôle'), u('S’il')))
        )
        metadata.create_all()
        t1.insert().execute(value=u('drôle'), value2=u('drôle'))
        t1.insert().execute(value=u('réveillé'), value2=u('réveillé'))
        t1.insert().execute(value=u('S’il'), value2=u('S’il'))
        eq_(t1.select().order_by(t1.c.id).execute().fetchall(),
            [
                (1, u('drôle'), u('drôle')),
                (2, u('réveillé'), u('réveillé')),
                (3, u('S’il'), u('S’il'))
            ])

        # test reflection of the enum labels

        m2 = MetaData(testing.db)
        t2 = Table('table', m2, autoload=True)

        # TODO: what's wrong with the last element ?  is there
        # latin-1 stuff forcing its way in ?

        eq_(
            t2.c.value.type.enums[0:2],
            [u('réveillé'), u('drôle')]  # u'S’il') # eh ?
        )

        eq_(
            t2.c.value2.type.enums[0:2],
            [u('réveillé'), u('drôle')]  # u'S’il') # eh ?
        )
Example #40
0
 def test_unicode_default(self):
     default = u('foo')
     Column(Unicode(32), default=default)