From: Jason Kirtland Date: Wed, 10 Feb 2010 18:32:56 +0000 (+0000) Subject: Fix mysql reflection of TINYINT(1) UNSIGNED columns. X-Git-Tag: rel_0_6beta2~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bef9e234de84a1601df4d324feb5c422818a6d3d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix mysql reflection of TINYINT(1) UNSIGNED columns. --- diff --git a/CHANGES b/CHANGES index a9f22f242a..855293635a 100644 --- a/CHANGES +++ b/CHANGES @@ -56,7 +56,10 @@ CHANGES - Fixed reflection bug whereby when COLLATE was present, nullable flag and server defaults would not be reflected. [ticket:1655] - + + - Fixed reflection of TINYINT(1) "boolean" columns defined with + integer flags like UNSIGNED. + - mssql - Re-established initial support for pymssql. diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 77b13c1a73..eb348f1a16 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1084,7 +1084,7 @@ ischema_names = { 'binary': BINARY, 'bit': BIT, 'blob': BLOB, - 'boolean':BOOLEAN, + 'boolean': BOOLEAN, 'char': CHAR, 'date': DATE, 'datetime': DATETIME, @@ -2154,7 +2154,6 @@ class MySQLTableDefinitionParser(object): Any column-bearing line from SHOW CREATE TABLE """ - charset = state.charset spec = None m = self._re_column.match(line) if m: @@ -2178,6 +2177,8 @@ class MySQLTableDefinitionParser(object): if type_ == 'tinyint' and args == '1': type_ = 'boolean' args = None + spec['unsigned'] = None + spec['zerofill'] = None try: col_type = self.dialect.ischema_names[type_] diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index 0e9aca8181..85156ac3bf 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -359,12 +359,14 @@ class TypesTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL): Column('b1', BOOLEAN), Column('b2', Boolean), Column('b3', mysql.MSTinyInteger(1)), - Column('b4', mysql.MSTinyInteger)) + Column('b4', mysql.MSTinyInteger(1, unsigned=True)), + Column('b5', mysql.MSTinyInteger)) eq_(colspec(bool_table.c.b1), 'b1 BOOL') eq_(colspec(bool_table.c.b2), 'b2 BOOL') eq_(colspec(bool_table.c.b3), 'b3 TINYINT(1)') - eq_(colspec(bool_table.c.b4), 'b4 TINYINT') + eq_(colspec(bool_table.c.b4), 'b4 TINYINT(1) UNSIGNED') + eq_(colspec(bool_table.c.b5), 'b5 TINYINT') for col in bool_table.c: self.assert_(repr(col)) @@ -389,22 +391,23 @@ class TypesTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL): table.delete().execute().close() - roundtrip([None, None, None, None]) - roundtrip([True, True, 1, 1]) - roundtrip([False, False, 0, 0]) - roundtrip([True, True, True, True], [True, True, 1, 1]) - roundtrip([False, False, 0, 0], [False, False, 0, 0]) + roundtrip([None, None, None, None, None]) + roundtrip([True, True, 1, 1, 1]) + roundtrip([False, False, 0, 0, 0]) + roundtrip([True, True, True, True, True], [True, True, 1, 1, 1]) + roundtrip([False, False, 0, 0, 0], [False, False, 0, 0, 0]) meta2 = MetaData(testing.db) # replace with reflected table = Table('mysql_bool', meta2, autoload=True) eq_(colspec(table.c.b3), 'b3 BOOL') + eq_(colspec(table.c.b4), 'b4 BOOL') - roundtrip([None, None, None, None]) - roundtrip([True, True, 1, 1], [True, True, True, 1]) - roundtrip([False, False, 0, 0], [False, False, False, 0]) - roundtrip([True, True, True, True], [True, True, True, 1]) - roundtrip([False, False, 0, 0], [False, False, False, 0]) + roundtrip([None, None, None, None, None]) + roundtrip([True, True, 1, 1, 1], [True, True, True, True, 1]) + roundtrip([False, False, 0, 0, 0], [False, False, False, False, 0]) + roundtrip([True, True, True, True, True], [True, True, True, True, 1]) + roundtrip([False, False, 0, 0, 0], [False, False, False, False, 0]) finally: meta.drop_all()