]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed reflection of the empty string for mysql enums.
authorJason Kirtland <jek@discorporate.us>
Wed, 5 Sep 2007 19:39:07 +0000 (19:39 +0000)
committerJason Kirtland <jek@discorporate.us>
Wed, 5 Sep 2007 19:39:07 +0000 (19:39 +0000)
CHANGES
lib/sqlalchemy/databases/mysql.py
test/dialect/mysql.py

diff --git a/CHANGES b/CHANGES
index 9596524d5a2ed18d110bf468d028b56d7737ffb9..9fa7ad5988ab41d04918fcea55dc2c2ec37af710 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,8 +4,8 @@ CHANGES
 0.4.0beta6
 ----------
 
-- mapper compilation has been reorganized such that most compilation
-  occurs upon mapper construction.  this allows us to have fewer
+- Mapper compilation has been reorganized such that most compilation
+  occurs upon mapper construction.  This allows us to have fewer
   calls to mapper.compile() and also to allow class-based properties
   to force a compilation (i.e. User.addresses == 7 will compile all
   mappers; this is [ticket:758]).  The only caveat here is that 
@@ -13,13 +13,14 @@ CHANGES
   so mappers within inheritance relationships need to be constructed in
   inheritance order (which should be the normal case anyway).
 
-- removed "parameters" argument from clauseelement.compile(), replaced with
-  "column_keys".  the parameters sent to execute() only interact with the 
-  insert/update statement compilation process in terms of the column names 
-  present but not the values for those columns.
-  produces more consistent execute/executemany behavior, simplifies things a 
-  bit internally.
+- Removed "parameters" argument from clauseelement.compile(), replaced with
+  "column_keys".  The parameters sent to execute() only interact with the
+  insert/update statement compilation process in terms of the column names
+  present but not the values for those columns.  Produces more consistent
+  execute/executemany behavior, simplifies things a bit internally.
   
+- Fixed reflection of the empty string for mysql enums.
+
 0.4.0beta5
 ----------
 
index 6d5c545783b857a4ae3edfe82916ab35dc4a627d..50787648132da218d480711df5305dde0ddf7371 100644 (file)
@@ -1106,7 +1106,7 @@ class MSEnum(MSString):
             
         self.enums = strip_enums
         self.strict = kw.pop('strict', False)
-        length = max([len(v) for v in strip_enums])
+        length = max([len(v) for v in strip_enums] + [0])
         super(MSEnum, self).__init__(length, **kw)
 
     def bind_processor(self, dialect):
@@ -2175,7 +2175,7 @@ class MySQLSchemaReflector(object):
             r'(?:\((\d+)\))?(?=\,|$))+' % quotes)
 
         # 'foo' or 'foo','bar' or 'fo,o','ba''a''r'
-        self._re_csv_str = _re_compile(r'\x27(?:\x27\x27|[^\x27])+\x27')
+        self._re_csv_str = _re_compile(r'\x27(?:\x27\x27|[^\x27])*\x27')
 
         # 123 or 123,456
         self._re_csv_int = _re_compile(r'\d+')
@@ -2192,7 +2192,7 @@ class MySQLSchemaReflector(object):
             r'%(iq)s(?P<name>(?:%(esc_fq)s|[^%(fq)s])+)%(fq)s +'
             r'(?P<coltype>\w+)'
             r'(?:\((?P<arg>(?:\d+|\d+,\d+|'
-              r'(?:\x27(?:\x27\x27|[^\x27])+\x27,?)+))\))?'
+              r'(?:\x27(?:\x27\x27|[^\x27])*\x27,?)+))\))?'
             r'(?: +(?P<unsigned>UNSIGNED))?'
             r'(?: +(?P<zerofill>ZEROFILL))?'
             r'(?: +CHARACTER SET +(?P<charset>\w+))?'
index 1cf6b437c0098bbfaf1108032134a26ab6b8b67d..8a5bac6e6ff18cfe3a023d451e09c7fb738917ce 100644 (file)
@@ -557,6 +557,30 @@ class TypesTest(AssertMixin):
         self.assert_eq(res, expected)
         enum_table.drop()
 
+    @testing.supported('mysql')
+    def test_enum_parse(self):
+        """More exercises for the ENUM type."""
+        
+        db = testbase.db
+        enum_table = Table('mysql_enum', MetaData(testbase.db),
+            Column('e1', mysql.MSEnum("'a'")),
+            Column('e2', mysql.MSEnum("''")),
+            Column('e3', mysql.MSEnum("'a'", "''")),
+            Column('e4', mysql.MSEnum("''", "'a'")),
+            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"]
+        finally:
+            enum_table.drop()
+
     @testing.supported('mysql')
     @testing.exclude('mysql', '<', (5, 0, 0))
     def test_type_reflection(self):
@@ -583,6 +607,7 @@ class TypesTest(AssertMixin):
                  ( mysql.MSBlob(1234), mysql.MSBlob()),
                  ( mysql.MSMediumBlob(),),
                  ( mysql.MSLongBlob(),),
+                 ( mysql.MSEnum("''","'fleem'"), ),
                  ]
 
         columns = [Column('c%i' % (i + 1), t[0]) for i, t in enumerate(specs)]