]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
mysql SETs and ENUMs now unescape embedded quotes before storage in .enums and .value...
authorJason Kirtland <jek@discorporate.us>
Thu, 6 Sep 2007 18:46:53 +0000 (18:46 +0000)
committerJason Kirtland <jek@discorporate.us>
Thu, 6 Sep 2007 18:46:53 +0000 (18:46 +0000)
lib/sqlalchemy/databases/mysql.py
test/dialect/mysql.py

index 50787648132da218d480711df5305dde0ddf7371..8bbe8b6830f6aaae419734c0ae31cd2978bb6af0 100644 (file)
@@ -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
index 8a5bac6e6ff18cfe3a023d451e09c7fb738917ce..2ea7abf03f53247a154beaff29492f73cc28a7a8 100644 (file)
@@ -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()