summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2007-08-09 19:03:42 +0000
committerJason Kirtland <jek@discorporate.us>2007-08-09 19:03:42 +0000
commitbdd780dd88950106df09f81e539067f3bd98a06c (patch)
treeb8a0b3bfbd1754dbf08ad965ceeb69308cf051a4
parent7c9d8d81aee73444f0ec17c4a24c616c133bd573 (diff)
downloadsqlalchemy-bdd780dd88950106df09f81e539067f3bd98a06c.tar.gz
restore clipping value for YEAR DDL
-rw-r--r--lib/sqlalchemy/databases/mysql.py9
-rw-r--r--test/dialect/mysql.py9
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 139328039..766748c62 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -551,9 +551,14 @@ class MSTimeStamp(sqltypes.TIMESTAMP):
class MSYear(sqltypes.TypeEngine):
"""MySQL YEAR type, for single byte storage of years 1901-2155"""
- def get_col_spec(self):
- return "YEAR"
+ def __init__(self, length=None):
+ self.length = length
+ def get_col_spec(self):
+ 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"""
diff --git a/test/dialect/mysql.py b/test/dialect/mysql.py
index fcf1de449..ef0562884 100644
--- a/test/dialect/mysql.py
+++ b/test/dialect/mysql.py
@@ -422,8 +422,8 @@ class TypesTest(AssertMixin):
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()
@@ -433,8 +433,11 @@ class TypesTest(AssertMixin):
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()