예제 #1
0
    def test_set_parse(self):
        with testing.expect_deprecated('Manually quoting SET value literals'):
            set_table = Table(
                'mysql_set', self.metadata, Column('e1', mysql.SET("'a'")),
                Column('e2', mysql.SET("''", retrieve_as_bitwise=True)),
                Column('e3', mysql.SET('a')),
                Column('e4', mysql.SET('', retrieve_as_bitwise=True)),
                Column('e5', mysql.SET("'a'", "''", retrieve_as_bitwise=True)),
                Column('e6', mysql.SET("''", "'a'", retrieve_as_bitwise=True)),
                Column(
                    'e7',
                    mysql.SET("''",
                              "'''a'''",
                              "'b''b'",
                              "''''",
                              retrieve_as_bitwise=True)))

        for col in set_table.c:
            self.assert_(repr(col))

        set_table.create()

        # don't want any warnings on reflection
        reflected = Table('mysql_set', MetaData(testing.db), autoload=True)
        for t in set_table, reflected:
            eq_(t.c.e1.type.values, ("a", ))
            eq_(t.c.e2.type.values, ("", ))
            eq_(t.c.e3.type.values, ("a", ))
            eq_(t.c.e4.type.values, ("", ))
            eq_(t.c.e5.type.values, ("a", ""))
            eq_(t.c.e6.type.values, ("", "a"))
            eq_(t.c.e7.type.values, ("", "'a'", "b'b", "'"))
예제 #2
0
    def test_set_parse(self):
        set_table = Table(
            "mysql_set",
            self.metadata,
            Column("e1", mysql.SET("a")),
            Column("e2", mysql.SET("", retrieve_as_bitwise=True)),
            Column("e3", mysql.SET("a")),
            Column("e4", mysql.SET("", retrieve_as_bitwise=True)),
            Column("e5", mysql.SET("a", "", retrieve_as_bitwise=True)),
            Column("e6", mysql.SET("", "a", retrieve_as_bitwise=True)),
            Column(
                "e7",
                mysql.SET("", "'a'", "b'b", "'", retrieve_as_bitwise=True,),
            ),
        )

        for col in set_table.c:
            self.assert_(repr(col))

        set_table.create()

        # don't want any warnings on reflection
        reflected = Table("mysql_set", MetaData(testing.db), autoload=True)
        for t in set_table, reflected:
            eq_(t.c.e1.type.values, ("a",))
            eq_(t.c.e2.type.values, ("",))
            eq_(t.c.e3.type.values, ("a",))
            eq_(t.c.e4.type.values, ("",))
            eq_(t.c.e5.type.values, ("a", ""))
            eq_(t.c.e6.type.values, ("", "a"))
            eq_(t.c.e7.type.values, ("", "'a'", "b'b", "'"))
예제 #3
0
    def test_set_roundtrip_plus_reflection(self):
        set_table = Table(
            "mysql_set",
            self.metadata,
            Column("s1", mysql.SET("dq", "sq")),
            Column("s2", mysql.SET("a")),
            Column("s3", mysql.SET("5", "7", "9")),
        )

        eq_(colspec(set_table.c.s1), "s1 SET('dq','sq')")
        eq_(colspec(set_table.c.s2), "s2 SET('a')")
        eq_(colspec(set_table.c.s3), "s3 SET('5','7','9')")
        set_table.create()
        reflected = Table("mysql_set", MetaData(testing.db), autoload=True)
        for table in set_table, reflected:

            def roundtrip(store, expected=None):
                expected = expected or store
                table.insert(store).execute()
                row = table.select().execute().first()
                eq_(row, tuple(expected))
                table.delete().execute()

            roundtrip([None, None, None], [None] * 3)
            roundtrip(["", "", ""], [set([])] * 3)
            roundtrip([set(["dq"]), set(["a"]), set(["5"])])
            roundtrip(["dq", "a", "5"], [set(["dq"]), set(["a"]), set(["5"])])
            roundtrip([1, 1, 1], [set(["dq"]), set(["a"]), set(["5"])])
            roundtrip([set(["dq", "sq"]), None, set(["9", "5", "7"])])
        set_table.insert().execute(
            {"s3": set(["5"])},
            {"s3": set(["5", "7"])},
            {"s3": set(["5", "7", "9"])},
            {"s3": set(["7", "9"])},
        )

        rows = (
            select(
                [set_table.c.s3], set_table.c.s3.in_([set(["5"]), ["5", "7"]])
            )
            .execute()
            .fetchall()
        )
        found = set([frozenset(row[0]) for row in rows])
        eq_(found, set([frozenset(["5"]), frozenset(["5", "7"])]))
예제 #4
0
    def test_set_roundtrip_plus_reflection(self):
        set_table = Table('mysql_set', self.metadata,
                        Column('s1',
                          mysql.SET("dq", "sq")),
                            Column('s2', mysql.SET("a")),
                            Column('s3', mysql.SET("5", "7", "9")))

        eq_(colspec(set_table.c.s1), "s1 SET('dq','sq')")
        eq_(colspec(set_table.c.s2), "s2 SET('a')")
        eq_(colspec(set_table.c.s3), "s3 SET('5','7','9')")
        set_table.create()
        reflected = Table('mysql_set', MetaData(testing.db),
                          autoload=True)
        for table in set_table, reflected:

            def roundtrip(store, expected=None):
                expected = expected or store
                table.insert(store).execute()
                row = table.select().execute().first()
                self.assert_(list(row) == expected)
                table.delete().execute()

            roundtrip([None, None, None], [None] * 3)
            roundtrip(['', '', ''], [set([''])] * 3)
            roundtrip([set(['dq']), set(['a']), set(['5'])])
            roundtrip(['dq', 'a', '5'], [set(['dq']), set(['a']),
                      set(['5'])])
            roundtrip([1, 1, 1], [set(['dq']), set(['a']), set(['5'
                      ])])
            roundtrip([set(['dq', 'sq']), None, set(['9', '5', '7'
                      ])])
        set_table.insert().execute({'s3': set(['5'])},
                {'s3': set(['5', '7'])}, {'s3': set(['5', '7', '9'])},
                {'s3': set(['7', '9'])})

        # NOTE: the string sent to MySQL here is sensitive to ordering.
        # for some reason the set ordering is always "5, 7" when we test on
        # MySQLdb but in Py3K this is not guaranteed.   So basically our
        # SET type doesn't do ordering correctly (not sure how it can,
        # as we don't know how the SET was configured in the first place.)
        rows = select([set_table.c.s3],
                    set_table.c.s3.in_([set(['5']), ['5', '7']])
                        ).execute().fetchall()
        found = set([frozenset(row[0]) for row in rows])
        eq_(found, set([frozenset(['5']), frozenset(['5', '7'])]))
예제 #5
0
    def test_set_roundtrip_plus_reflection(self):
        set_table = Table(
            'mysql_set', self.metadata,
            Column('s1', mysql.SET("dq", "sq")),
            Column('s2', mysql.SET("a")),
            Column('s3', mysql.SET("5", "7", "9")))

        eq_(colspec(set_table.c.s1), "s1 SET('dq','sq')")
        eq_(colspec(set_table.c.s2), "s2 SET('a')")
        eq_(colspec(set_table.c.s3), "s3 SET('5','7','9')")
        set_table.create()
        reflected = Table('mysql_set', MetaData(testing.db),
                          autoload=True)
        for table in set_table, reflected:

            def roundtrip(store, expected=None):
                expected = expected or store
                table.insert(store).execute()
                row = table.select().execute().first()
                eq_(row, tuple(expected))
                table.delete().execute()

            roundtrip([None, None, None], [None] * 3)
            roundtrip(['', '', ''], [set([])] * 3)
            roundtrip([set(['dq']), set(['a']), set(['5'])])
            roundtrip(['dq', 'a', '5'], [set(['dq']), set(['a']),
                      set(['5'])])
            roundtrip([1, 1, 1], [set(['dq']), set(['a']), set(['5'])])
            roundtrip([set(['dq', 'sq']), None, set(['9', '5', '7'])])
        set_table.insert().execute(
            {'s3': set(['5'])},
            {'s3': set(['5', '7'])},
            {'s3': set(['5', '7', '9'])},
            {'s3': set(['7', '9'])})

        rows = select(
            [set_table.c.s3],
            set_table.c.s3.in_([set(['5']), ['5', '7']])
        ).execute().fetchall()
        found = set([frozenset(row[0]) for row in rows])
        eq_(found, set([frozenset(['5']), frozenset(['5', '7'])]))
예제 #6
0
    def test_unicode_roundtrip(self, metadata, connection):
        set_table = Table(
            "t",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("data", mysql.SET("réveillé", "drôle", "S’il")),
        )

        set_table.create(connection)
        connection.execute(set_table.insert(),
                           {"data": set(["réveillé", "drôle"])})

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

        eq_(row, (1, set(["réveillé", "drôle"])))
예제 #7
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")])))
예제 #8
0
 def test_empty_set_no_empty_string(self):
     t = Table(
         "t",
         self.metadata,
         Column("id", Integer),
         Column("data", mysql.SET("a", "b")),
     )
     t.create()
     with testing.db.begin() as conn:
         conn.execute(
             t.insert(),
             {"id": 1, "data": set()},
             {"id": 2, "data": set([""])},
             {"id": 3, "data": set(["a", ""])},
             {"id": 4, "data": set(["b"])},
         )
         eq_(
             conn.execute(t.select().order_by(t.c.id)).fetchall(),
             [(1, set()), (2, set()), (3, set(["a"])), (4, set(["b"]))],
         )
예제 #9
0
 def test_empty_set_no_empty_string(self, metadata, connection):
     t = Table(
         "t",
         metadata,
         Column("id", Integer),
         Column("data", mysql.SET("a", "b")),
     )
     t.create(connection)
     connection.execute(
         t.insert(),
         [
             {"id": 1, "data": set()},
             {"id": 2, "data": set([""])},
             {"id": 3, "data": set(["a", ""])},
             {"id": 4, "data": set(["b"])},
         ],
     )
     eq_(
         connection.execute(t.select().order_by(t.c.id)).fetchall(),
         [(1, set()), (2, set()), (3, set(["a"])), (4, set(["b"]))],
     )
예제 #10
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')])))
예제 #11
0
 def test_empty_set_empty_string(self):
     t = Table(
         't', self.metadata,
         Column('id', Integer),
         Column('data', mysql.SET("a", "b", '', retrieve_as_bitwise=True))
     )
     t.create()
     with testing.db.begin() as conn:
         conn.execute(
             t.insert(),
             {'id': 1, 'data': set()},
             {'id': 2, 'data': set([''])},
             {'id': 3, 'data': set(['a', ''])},
             {'id': 4, 'data': set(['b'])},
         )
         eq_(
             conn.execute(t.select().order_by(t.c.id)).fetchall(),
             [
                 (1, set()),
                 (2, set([''])),
                 (3, set(['a', ''])),
                 (4, set(['b'])),
             ]
         )
예제 #12
0
 def test_set_repr(self, value, kw, expected):
     eq_(repr(mysql.SET(*value, **kw)), expected)