]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added MSMediumInteger type [ticket:1146].
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Aug 2008 21:20:15 +0000 (21:20 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Aug 2008 21:20:15 +0000 (21:20 +0000)
CHANGES
lib/sqlalchemy/databases/mysql.py
test/dialect/mysql.py

diff --git a/CHANGES b/CHANGES
index acba941d80317d6ec392d276d4a1f3742caecb5b..4daadf7db91b173df8b078bc443c308d405403a9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@ CHANGES
     - Fixed bug regarding inherit_condition passed
       with "A=B" versus "B=A" leading to errors
       [ticket:1039]
+
+- mysql
+    - Added MSMediumInteger type [ticket:1146].
       
 0.4.7p1
 =====
index 3e718655ad0b227b9521bcadd2e6b870f9fdfb60..9697bcae9ebe26f575ffa960d3cae6e88d2274eb 100644 (file)
@@ -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',
@@ -548,6 +548,33 @@ class MSBigInteger(MSInteger):
         else:
             return self._extend("BIGINT")
 
+class MSMediumInteger(MSInteger):
+    """MySQL MEDIUMINTEGER type."""
+
+    def __init__(self, length=None, **kw):
+        """Construct a MEDIUMINTEGER
+
+        length
+          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__(length, **kw)
+
+    def get_col_spec(self):
+        if self.length is not None:
+            return self._extend("MEDIUMINT(%(length)s)" % {'length': self.length})
+        else:
+            return self._extend("MEDIUMINT")
+
+
 
 class MSTinyInteger(MSInteger):
     """MySQL TINYINT type."""
@@ -1363,7 +1390,7 @@ ischema_names = {
     'longblob': MSLongBlob,
     'longtext': MSLongText,
     'mediumblob': MSMediumBlob,
-    'mediumint': MSInteger,
+    'mediumint': MSMediumInteger,
     'mediumtext': MSMediumText,
     'nchar': MSNChar,
     'nvarchar': MSNVarChar,
index 6cdc284c9c47ca6468ae729d9c96337eb84fd026..86ccd0da28887c70b5a1b76047b3130e6628f7f3 100644 (file)
@@ -23,6 +23,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'")),
             )
         try:
@@ -38,6 +39,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)
             t2.drop()
             t2.create()
@@ -133,6 +135,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], {},
@@ -645,6 +658,8 @@ class TypesTest(TestBase, AssertsExecutionResults):
                  ( SmallInteger(4), 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), ),