jason kirtland avatar jason kirtland committed bee200e

restore clipping value for YEAR DDL

Comments (0)

Files changed (2)

lib/sqlalchemy/databases/mysql.py

 class MSYear(sqltypes.TypeEngine):
     """MySQL YEAR type, for single byte storage of years 1901-2155"""
 
+    def __init__(self, length=None):
+        self.length = length
+
     def get_col_spec(self):
-        return "YEAR"
-
+        if self.length is None:
+            return "YEAR"
+        else:
+            return "YEAR(%s)" % self.length
 
 class MSText(_StringType, sqltypes.TEXT):
     """MySQL TEXT type, for text up to 2^16 characters""" 

test/dialect/mysql.py

                            Column('y1', mysql.MSYear),
                            Column('y2', mysql.MSYear),
                            Column('y3', mysql.MSYear),
-                           Column('y4', mysql.MSYear),
-                           Column('y5', mysql.MSYear))
+                           Column('y4', mysql.MSYear(2)),
+                           Column('y5', mysql.MSYear(4)))
 
         try:
             year_table.create()
             for table in year_table, reflected:
                 table.insert(['1950', '50', None, 50, 1950]).execute()
                 row = list(table.select().execute())[0]
-                self.assert_eq(list(row), [1950, 2050, None, 2050, 1950])
+                self.assert_eq(list(row), [1950, 2050, None, 50, 1950])
                 table.delete().execute()
+                self.assert_(colspec(table.c.y1).startswith('y1 YEAR'))
+                self.assert_eq(colspec(table.c.y4), 'y4 YEAR(2)')
+                self.assert_eq(colspec(table.c.y5), 'y5 YEAR(4)')
         finally:
             meta.drop_all()
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.