From: Jason Kirtland Date: Thu, 6 Sep 2007 18:46:53 +0000 (+0000) Subject: mysql SETs and ENUMs now unescape embedded quotes before storage in .enums and .value... X-Git-Tag: rel_0_4beta6~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a072e50c9d28eac08882ecb5bf274f423f0a4508;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git mysql SETs and ENUMs now unescape embedded quotes before storage in .enums and .values. An ancient bug. --- diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 5078764813..8bbe8b6830 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -81,7 +81,7 @@ multi-column key for some storage engines:: Column('gid', Integer, primary_key=True, autoincrement=False), Column('id', Integer, primary_key=True)) -MySQL SQL modes are supported. Modes that enable ``ANSI_QUOTE`` (such as +MySQL SQL modes are supported. Modes that enable ``ANSI_QUOTES`` (such as ``ANSI``) require an engine option to modify SQLAlchemy's quoting style. When using an ANSI-quoting mode, supply ``use_ansiquotes=True`` when creating your ``Engine``:: @@ -310,7 +310,6 @@ class MSNumeric(sqltypes.Numeric, _NumericType): return process else: return None - class MSDecimal(MSNumeric): @@ -1064,7 +1063,10 @@ class MSEnum(MSString): enums The range of valid values for this ENUM. Values will be used - exactly as they appear when generating schemas + exactly as they appear when generating schemas. Strings must + be quoted, as in the example above. Single-quotes are suggested + for ANSI compatability and are required for portability to servers + with ANSI_QUOTES enabled. strict Defaults to False: ensure that a given value is in this ENUM's @@ -1101,7 +1103,8 @@ class MSEnum(MSString): strip_enums = [] for a in enums: if a[0:1] == '"' or a[0:1] == "'": - a = a[1:-1] + # strip enclosing quotes and unquote interior + a = a[1:-1].replace(a[0] * 2, a[0]) strip_enums.append(a) self.enums = strip_enums @@ -1139,7 +1142,10 @@ class MSSet(MSString): values The range of valid values for this SET. Values will be used - exactly as they appear when generating schemas. + exactly as they appear when generating schemas. Strings must + be quoted, as in the example above. Single-quotes are suggested + for ANSI compatability and are required for portability to servers + with ANSI_QUOTES enabled. charset Optional, a column-level character set for this string @@ -1169,7 +1175,8 @@ class MSSet(MSString): strip_values = [] for a in values: if a[0:1] == '"' or a[0:1] == "'": - a = a[1:-1] + # strip enclosing quotes and unquote interior + a = a[1:-1].replace(a[0] * 2, a[0]) strip_values.append(a) self.values = strip_values diff --git a/test/dialect/mysql.py b/test/dialect/mysql.py index 8a5bac6e6f..2ea7abf03f 100644 --- a/test/dialect/mysql.py +++ b/test/dialect/mysql.py @@ -567,17 +567,17 @@ class TypesTest(AssertMixin): Column('e2', mysql.MSEnum("''")), Column('e3', mysql.MSEnum("'a'", "''")), Column('e4', mysql.MSEnum("''", "'a'")), - Column('e5', mysql.MSEnum("''", "'''a'''", "'b''b'"))) + Column('e5', mysql.MSEnum("''", "'''a'''", "'b''b'", "''''"))) try: enum_table.create() reflected = Table('mysql_enum', MetaData(testbase.db), autoload=True) for t in enum_table, reflected: - assert t.c.e1.type.enums == ['a'] - assert t.c.e2.type.enums == [''] - assert t.c.e3.type.enums == ['a', ''] - assert t.c.e4.type.enums == ['', 'a'] - assert t.c.e5.type.enums == ['', "''a''", "b''b"] + assert t.c.e1.type.enums == ["a"] + assert t.c.e2.type.enums == [""] + assert t.c.e3.type.enums == ["a", ""] + assert t.c.e4.type.enums == ["", "a"] + assert t.c.e5.type.enums == ["", "'a'", "b'b", "'"] finally: enum_table.drop()