Mike Bayer avatar Mike Bayer committed 22e6e5f

- Added MSMediumInteger type [ticket:1146].

Comments (0)

Files changed (3)

     - 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
 =====

lib/sqlalchemy/databases/mysql.py

 
 
 __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',
         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."""
     'longblob': MSLongBlob,
     'longtext': MSLongText,
     'mediumblob': MSMediumBlob,
-    'mediumint': MSInteger,
+    'mediumint': MSMediumInteger,
     'mediumtext': MSMediumText,
     'nchar': MSNChar,
     'nvarchar': MSNVarChar,

test/dialect/mysql.py

             Column('num3', mysql.MSBigInteger()),
             Column('num4', mysql.MSDouble),
             Column('num5', mysql.MSDouble()),
+            Column('num6', mysql.MSMediumInteger),
             Column('enum1', mysql.MSEnum("'black'", "'white'")),
             )
         try:
             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()
             (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], {},
                  ( 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), ),
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.