summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-08-24 21:20:05 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-08-24 21:20:05 +0000
commitae573e047a696c3c80d11e56466c9f55b72e0461 (patch)
tree7da54e41f789fc5dea306894d94eca6acd851d37
parent4c29ed71d0f6ff656da4a04437097c290122f75c (diff)
downloadsqlalchemy-ae573e047a696c3c80d11e56466c9f55b72e0461.tar.gz
- Added MSMediumInteger type [ticket:1146].
-rw-r--r--CHANGES2
-rw-r--r--lib/sqlalchemy/databases/mysql.py31
-rw-r--r--test/dialect/mysql.py15
3 files changed, 46 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index f3cc31dd2..9dc7e8004 100644
--- a/CHANGES
+++ b/CHANGES
@@ -93,6 +93,8 @@ CHANGES
- mysql
- The 'length' argument to MSInteger, MSBigInteger, MSTinyInteger,
MSSmallInteger and MSYear has been renamed to 'display_width'.
+
+ - Added MSMediumInteger type [ticket:1146].
0.5beta3
========
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index ed8712748..729e1ad45 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -166,7 +166,7 @@ from sqlalchemy import types as sqltypes
__all__ = (
- 'MSBigInteger', 'MSBinary', 'MSBit', 'MSBlob', 'MSBoolean',
+ 'MSBigInteger', 'MSMediumInteger', 'MSBinary', 'MSBit', 'MSBlob', 'MSBoolean',
'MSChar', 'MSDate', 'MSDateTime', 'MSDecimal', 'MSDouble',
'MSEnum', 'MSFloat', 'MSInteger', 'MSLongBlob', 'MSLongText',
'MSMediumBlob', 'MSMediumText', 'MSNChar', 'MSNVarChar',
@@ -552,6 +552,33 @@ class MSBigInteger(MSInteger):
else:
return self._extend("BIGINT")
+class MSMediumInteger(MSInteger):
+ """MySQL MEDIUMINTEGER type."""
+
+ def __init__(self, display_width=None, **kw):
+ """Construct a MEDIUMINTEGER
+
+ display_width
+ Optional, maximum display width for this number.
+
+ unsigned
+ Optional.
+
+ zerofill
+ Optional. If true, values will be stored as strings left-padded with
+ zeros. Note that this does not effect the values returned by the
+ underlying database API, which continue to be numeric.
+ """
+
+ super(MSMediumInteger, self).__init__(display_width, **kw)
+
+ def get_col_spec(self):
+ if self.display_width is not None:
+ return self._extend("MEDIUMINT(%(display_width)s)" % {'display_width': self.display_width})
+ else:
+ return self._extend("MEDIUMINT")
+
+
class MSTinyInteger(MSInteger):
"""MySQL TINYINT type."""
@@ -1404,7 +1431,7 @@ ischema_names = {
'longblob': MSLongBlob,
'longtext': MSLongText,
'mediumblob': MSMediumBlob,
- 'mediumint': MSInteger,
+ 'mediumint': MSMediumInteger,
'mediumtext': MSMediumText,
'nchar': MSNChar,
'nvarchar': MSNVarChar,
diff --git a/test/dialect/mysql.py b/test/dialect/mysql.py
index 2c944fd3a..5a03ffa98 100644
--- a/test/dialect/mysql.py
+++ b/test/dialect/mysql.py
@@ -24,6 +24,7 @@ class TypesTest(TestBase, AssertsExecutionResults):
Column('num3', mysql.MSBigInteger()),
Column('num4', mysql.MSDouble),
Column('num5', mysql.MSDouble()),
+ Column('num6', mysql.MSMediumInteger),
Column('enum1', mysql.MSEnum("'black'", "'white'")),
Column('enum2', mysql.MSEnum("dog", "cat")),
)
@@ -40,6 +41,7 @@ class TypesTest(TestBase, AssertsExecutionResults):
assert isinstance(t2.c.num3.type, mysql.MSBigInteger)
assert isinstance(t2.c.num4.type, mysql.MSDouble)
assert isinstance(t2.c.num5.type, mysql.MSDouble)
+ assert isinstance(t2.c.num6.type, mysql.MSMediumInteger)
assert isinstance(t2.c.enum1.type, mysql.MSEnum)
assert isinstance(t2.c.enum2.type, mysql.MSEnum)
t2.drop()
@@ -136,6 +138,17 @@ class TypesTest(TestBase, AssertsExecutionResults):
(mysql.MSBigInteger, [4], {'zerofill':True, 'unsigned':True},
'BIGINT(4) UNSIGNED ZEROFILL'),
+ (mysql.MSMediumInteger, [], {},
+ 'MEDIUMINT'),
+ (mysql.MSMediumInteger, [4], {},
+ 'MEDIUMINT(4)'),
+ (mysql.MSMediumInteger, [4], {'unsigned':True},
+ 'MEDIUMINT(4) UNSIGNED'),
+ (mysql.MSMediumInteger, [4], {'zerofill':True},
+ 'MEDIUMINT(4) ZEROFILL'),
+ (mysql.MSMediumInteger, [4], {'zerofill':True, 'unsigned':True},
+ 'MEDIUMINT(4) UNSIGNED ZEROFILL'),
+
(mysql.MSTinyInteger, [], {},
'TINYINT'),
(mysql.MSTinyInteger, [1], {},
@@ -662,6 +675,8 @@ class TypesTest(TestBase, AssertsExecutionResults):
( SmallInteger(), mysql.MSSmallInteger(4), ),
( mysql.MSSmallInteger(), ),
( mysql.MSSmallInteger(4), mysql.MSSmallInteger(4), ),
+ ( mysql.MSMediumInteger(), mysql.MSMediumInteger(), ),
+ ( mysql.MSMediumInteger(8), mysql.MSMediumInteger(8), ),
( Binary(3), mysql.MSBlob(3), ),
( Binary(), mysql.MSBlob() ),
( mysql.MSBinary(3), mysql.MSBinary(3), ),