def test_string_types(self): specs = [ (String(1), mysql.MSString(1)), (String(3), mysql.MSString(3)), (Text(), mysql.MSText()), (Unicode(1), mysql.MSString(1)), (Unicode(3), mysql.MSString(3)), (UnicodeText(), mysql.MSText()), (mysql.MSChar(1), mysql.MSChar(1)), (mysql.MSChar(3), mysql.MSChar(3)), (NCHAR(2), mysql.MSChar(2)), (mysql.MSNChar(2), mysql.MSChar(2)), (mysql.MSNVarChar(22), mysql.MSString(22)), ] self._run_test(specs, ["length"])
def test_type_reflection(self): # (ask_for, roundtripped_as_if_different) specs = [(String(1), mysql.MSString(1), ), (String(3), mysql.MSString(3), ), (Text(), mysql.MSText(), ), (Unicode(1), mysql.MSString(1), ), (Unicode(3), mysql.MSString(3), ), (UnicodeText(), mysql.MSText(), ), (mysql.MSChar(1), ), (mysql.MSChar(3), ), (NCHAR(2), mysql.MSChar(2), ), (mysql.MSNChar(2), mysql.MSChar(2), ), # N is CREATE only (mysql.MSNVarChar(22), mysql.MSString(22), ), (SmallInteger(), mysql.MSSmallInteger(), ), (SmallInteger(), mysql.MSSmallInteger(4), ), (mysql.MSSmallInteger(), ), (mysql.MSSmallInteger(4), mysql.MSSmallInteger(4), ), (mysql.MSMediumInteger(), mysql.MSMediumInteger(), ), (mysql.MSMediumInteger(8), mysql.MSMediumInteger(8), ), (LargeBinary(3), mysql.TINYBLOB(), ), (LargeBinary(), mysql.BLOB() ), (mysql.MSBinary(3), mysql.MSBinary(3), ), (mysql.MSVarBinary(3),), (mysql.MSTinyBlob(),), (mysql.MSBlob(),), (mysql.MSBlob(1234), mysql.MSBlob()), (mysql.MSMediumBlob(),), (mysql.MSLongBlob(),), (mysql.ENUM("''","'fleem'"), ), ] columns = [Column('c%i' % (i + 1), t[0]) for i, t in enumerate(specs)] db = testing.db m = MetaData(db) t_table = Table('mysql_types', m, *columns) try: m.create_all() m2 = MetaData(db) rt = Table('mysql_types', m2, autoload=True) try: db.execute('CREATE OR REPLACE VIEW mysql_types_v ' 'AS SELECT * from mysql_types') rv = Table('mysql_types_v', m2, autoload=True) expected = [len(c) > 1 and c[1] or c[0] for c in specs] # Early 5.0 releases seem to report more "general" for columns # in a view, e.g. char -> varchar, tinyblob -> mediumblob # # Not sure exactly which point version has the fix. if db.dialect.server_version_info < (5, 0, 11): tables = rt, else: tables = rt, rv for table in tables: for i, reflected in enumerate(table.c): assert isinstance(reflected.type, type(expected[i])), \ 'element %d: %r not instance of %r' % (i, reflected.type, type(expected[i])) finally: db.execute('DROP VIEW mysql_types_v') finally: m.drop_all()