]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The 'length' argument to all Numeric types has been renamed
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Aug 2008 19:52:54 +0000 (19:52 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Aug 2008 19:52:54 +0000 (19:52 +0000)
to 'scale'.  'length' is deprecated and is still accepted
with a warning. [ticket:827]
- The 'length' argument to MSInteger, MSBigInteger, MSTinyInteger,
MSSmallInteger and MSYear has been renamed to 'display_width'.
[ticket:827]
- mysql._Numeric now consumes 'unsigned' and 'zerofill' from
the given kw, so that the same kw can be passed along to Numeric
and allow the 'length' deprecation logic to still take effect
- added testlib.engines.all_dialects() to return a dialect for
every db module
- informix added to sqlalchemy.databases.__all__.  Since other
"experimental" dbs like access and sybase are there, informix
should be as well.

17 files changed:
CHANGES
lib/sqlalchemy/databases/__init__.py
lib/sqlalchemy/databases/firebird.py
lib/sqlalchemy/databases/informix.py
lib/sqlalchemy/databases/maxdb.py
lib/sqlalchemy/databases/mssql.py
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/oracle.py
lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/databases/sqlite.py
lib/sqlalchemy/databases/sybase.py
lib/sqlalchemy/types.py
lib/sqlalchemy/util.py
test/dialect/mysql.py
test/sql/functions.py
test/sql/testtypes.py
test/testlib/engines.py

diff --git a/CHANGES b/CHANGES
index e5746ea3e72705dc44802c69ca9b71b3b690a72a..8e7c50ecfaad35b55ce1a8aa0340c8bf9790708c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -77,12 +77,20 @@ CHANGES
       removed from util.sort_tables(); use the Python
       'reversed' function to reverse the results.
       [ticket:1033]
+
+    - The 'length' argument to all Numeric types has been renamed
+      to 'scale'.  'length' is deprecated and is still accepted
+      with a warning.
       
 - sql
     - Temporarily rolled back the "ORDER BY" enhancement from
       [ticket:1068].  This feature is on hold pending further
       development.
 
+- mysql
+    - The 'length' argument to MSInteger, MSBigInteger, MSTinyInteger,
+      MSSmallInteger and MSYear has been renamed to 'display_width'.
+
 0.5beta3
 ========
 
index 9837cd136b66a339a2f8dc1120a248e38947888a..ec7ac69029f0aaca22f39135f16eddb2d2463dd6 100644 (file)
@@ -8,6 +8,7 @@
 __all__ = (
     'access',
     'firebird',
+    'informix',
     'maxdb',
     'mssql',
     'mysql',
index b2fcea095571b52260bde2e0fedaac13ffab66ae..ccd4db3c77cb4e7203c33fcd7ee12a61ab5a30fc 100644 (file)
@@ -109,14 +109,14 @@ _initialized_kb = False
 
 
 class FBNumeric(sqltypes.Numeric):
-    """Handle ``NUMERIC(precision,length)`` datatype."""
+    """Handle ``NUMERIC(precision,scale)`` datatype."""
 
     def get_col_spec(self):
         if self.precision is None:
             return "NUMERIC"
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % { 'precision': self.precision,
-                                                            'length' : self.length }
+            return "NUMERIC(%(precision)s, %(scale)s)" % { 'precision': self.precision,
+                                                            'scale' : self.scale }
 
     def bind_processor(self, dialect):
         return None
index e5f400770972dff277b8746cb0767b22edd6c671..423226c1880e59be576802d44d6cb012b8e069cf 100644 (file)
@@ -45,7 +45,7 @@ class InfoNumeric(sqltypes.Numeric):
         if not self.precision:
             return 'NUMERIC'
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+            return "NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale}
 
 class InfoInteger(sqltypes.Integer):
     def get_col_spec(self):
index c9ea2b57923a7f54b4b708003911a80b2222c668..34629b298aa4336773210a30620ae27b155f8302 100644 (file)
@@ -169,17 +169,17 @@ class MaxSmallInteger(MaxInteger):
 class MaxNumeric(sqltypes.Numeric):
     """The FIXED (also NUMERIC, DECIMAL) data type."""
 
-    def __init__(self, precision=None, length=None, **kw):
+    def __init__(self, precision=None, scale=None, **kw):
         kw.setdefault('asdecimal', True)
-        super(MaxNumeric, self).__init__(length=length, precision=precision,
+        super(MaxNumeric, self).__init__(scale=scale, precision=precision,
                                          **kw)
 
     def bind_processor(self, dialect):
         return None
 
     def get_col_spec(self):
-        if self.length and self.precision:
-            return 'FIXED(%s, %s)' % (self.precision, self.length)
+        if self.scale and self.precision:
+            return 'FIXED(%s, %s)' % (self.precision, self.scale)
         elif self.precision:
             return 'FIXED(%s)' % self.precision
         else:
index cfb34dd78e7d67f2e4a2c88f1c9d675dcf7398d3..a2535754d8ba746b2d4513e5fbe342ff2556c83c 100644 (file)
@@ -76,7 +76,7 @@ class MSNumeric(sqltypes.Numeric):
         if self.precision is None:
             return "NUMERIC"
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+            return "NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale}
 
 class MSFloat(sqltypes.Float):
     def get_col_spec(self):
index 4a4cfbd9013a05c401523fb900c57131cf0ec738..46e6924637680ee45fe0104fc39142f835c0d4a1 100644 (file)
@@ -231,9 +231,9 @@ SET_RE = re.compile(
 class _NumericType(object):
     """Base for MySQL numeric types."""
 
-    def __init__(self, unsigned=False, zerofill=False, **kw):
-        self.unsigned = unsigned
-        self.zerofill = zerofill
+    def __init__(self, kw):
+        self.unsigned = kw.pop('unsigned', False)
+        self.zerofill = kw.pop('zerofill', False)
 
     def _extend(self, spec):
         "Extend a numeric-type declaration with MySQL specific extensions."
@@ -304,14 +304,14 @@ class _StringType(object):
 class MSNumeric(sqltypes.Numeric, _NumericType):
     """MySQL NUMERIC type."""
 
-    def __init__(self, precision=10, length=2, asdecimal=True, **kw):
+    def __init__(self, precision=10, scale=2, asdecimal=True, **kw):
         """Construct a NUMERIC.
 
         precision
-          Total digits in this number.  If length and precision are both
+          Total digits in this number.  If scale and precision are both
           None, values are stored to limits allowed by the server.
 
-        length
+        scale
           The number of digits after the decimal point.
 
         unsigned
@@ -323,14 +323,14 @@ class MSNumeric(sqltypes.Numeric, _NumericType):
           underlying database API, which continue to be numeric.
         """
 
-        _NumericType.__init__(self, **kw)
-        sqltypes.Numeric.__init__(self, precision, length, asdecimal=asdecimal)
+        _NumericType.__init__(self, kw)
+        sqltypes.Numeric.__init__(self, precision, scale, asdecimal=asdecimal, **kw)
 
     def get_col_spec(self):
         if self.precision is None:
             return self._extend("NUMERIC")
         else:
-            return self._extend("NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length})
+            return self._extend("NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale})
 
     def bind_processor(self, dialect):
         return None
@@ -350,14 +350,14 @@ class MSNumeric(sqltypes.Numeric, _NumericType):
 class MSDecimal(MSNumeric):
     """MySQL DECIMAL type."""
 
-    def __init__(self, precision=10, length=2, asdecimal=True, **kw):
+    def __init__(self, precision=10, scale=2, asdecimal=True, **kw):
         """Construct a DECIMAL.
 
         precision
-          Total digits in this number.  If length and precision are both None,
+          Total digits in this number.  If scale and precision are both None,
           values are stored to limits allowed by the server.
 
-        length
+        scale
           The number of digits after the decimal point.
 
         unsigned
@@ -369,28 +369,28 @@ class MSDecimal(MSNumeric):
           underlying database API, which continue to be numeric.
         """
 
-        super(MSDecimal, self).__init__(precision, length, asdecimal=asdecimal, **kw)
+        super(MSDecimal, self).__init__(precision, scale, asdecimal=asdecimal, **kw)
 
     def get_col_spec(self):
         if self.precision is None:
             return self._extend("DECIMAL")
-        elif self.length is None:
+        elif self.scale is None:
             return self._extend("DECIMAL(%(precision)s)" % {'precision': self.precision})
         else:
-            return self._extend("DECIMAL(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length})
+            return self._extend("DECIMAL(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale})
 
 
 class MSDouble(sqltypes.Float, _NumericType):
     """MySQL DOUBLE type."""
 
-    def __init__(self, precision=None, length=None, asdecimal=True, **kw):
+    def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
         """Construct a DOUBLE.
 
         precision
-          Total digits in this number.  If length and precision are both None,
+          Total digits in this number.  If scale and precision are both None,
           values are stored to limits allowed by the server.
 
-        length
+        scale
           The number of digits after the decimal point.
 
         unsigned
@@ -402,22 +402,22 @@ class MSDouble(sqltypes.Float, _NumericType):
           underlying database API, which continue to be numeric.
         """
 
-        if ((precision is None and length is not None) or
-            (precision is not None and length is None)):
+        if ((precision is None and scale is not None) or
+            (precision is not None and scale is None)):
             raise exc.ArgumentError(
-                "You must specify both precision and length or omit "
+                "You must specify both precision and scale or omit "
                 "both altogether.")
 
-        _NumericType.__init__(self, **kw)
-        sqltypes.Float.__init__(self, asdecimal=asdecimal)
-        self.length = length
+        _NumericType.__init__(self, kw)
+        sqltypes.Float.__init__(self, asdecimal=asdecimal, **kw)
+        self.scale = scale
         self.precision = precision
 
     def get_col_spec(self):
-        if self.precision is not None and self.length is not None:
-            return self._extend("DOUBLE(%(precision)s, %(length)s)" %
+        if self.precision is not None and self.scale is not None:
+            return self._extend("DOUBLE(%(precision)s, %(scale)s)" %
                                 {'precision': self.precision,
-                                 'length' : self.length})
+                                 'scale' : self.scale})
         else:
             return self._extend('DOUBLE')
 
@@ -425,14 +425,14 @@ class MSDouble(sqltypes.Float, _NumericType):
 class MSReal(MSDouble):
     """MySQL REAL type."""
 
-    def __init__(self, precision=None, length=None, asdecimal=True, **kw):
+    def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
         """Construct a REAL.
 
         precision
-          Total digits in this number.  If length and precision are both None,
+          Total digits in this number.  If scale and precision are both None,
           values are stored to limits allowed by the server.
 
-        length
+        scale
           The number of digits after the decimal point.
 
         unsigned
@@ -443,13 +443,13 @@ class MSReal(MSDouble):
           zeros. Note that this does not effect the values returned by the
           underlying database API, which continue to be numeric.
         """
-        MSDouble.__init__(self, precision, length, asdecimal, **kw)
+        MSDouble.__init__(self, precision, scale, asdecimal, **kw)
 
     def get_col_spec(self):
-        if self.precision is not None and self.length is not None:
-            return self._extend("REAL(%(precision)s, %(length)s)" %
+        if self.precision is not None and self.scale is not None:
+            return self._extend("REAL(%(precision)s, %(scale)s)" %
                                 {'precision': self.precision,
-                                 'length' : self.length})
+                                 'scale' : self.scale})
         else:
             return self._extend('REAL')
 
@@ -457,14 +457,14 @@ class MSReal(MSDouble):
 class MSFloat(sqltypes.Float, _NumericType):
     """MySQL FLOAT type."""
 
-    def __init__(self, precision=None, length=None, asdecimal=False, **kw):
+    def __init__(self, precision=None, scale=None, asdecimal=False, **kw):
         """Construct a FLOAT.
 
         precision
-          Total digits in this number.  If length and precision are both None,
+          Total digits in this number.  If scale and precision are both None,
           values are stored to limits allowed by the server.
 
-        length
+        scale
           The number of digits after the decimal point.
 
         unsigned
@@ -476,14 +476,14 @@ class MSFloat(sqltypes.Float, _NumericType):
           underlying database API, which continue to be numeric.
         """
 
-        _NumericType.__init__(self, **kw)
-        sqltypes.Float.__init__(self, asdecimal=asdecimal)
-        self.length = length
+        _NumericType.__init__(self, kw)
+        sqltypes.Float.__init__(self, asdecimal=asdecimal, **kw)
+        self.scale = scale
         self.precision = precision
 
     def get_col_spec(self):
-        if self.length is not None and self.precision is not None:
-            return self._extend("FLOAT(%s, %s)" % (self.precision, self.length))
+        if self.scale is not None and self.precision is not None:
+            return self._extend("FLOAT(%s, %s)" % (self.precision, self.scale))
         elif self.precision is not None:
             return self._extend("FLOAT(%s)" % (self.precision,))
         else:
@@ -496,10 +496,10 @@ class MSFloat(sqltypes.Float, _NumericType):
 class MSInteger(sqltypes.Integer, _NumericType):
     """MySQL INTEGER type."""
 
-    def __init__(self, length=None, **kw):
+    def __init__(self, display_width=None, **kw):
         """Construct an INTEGER.
 
-        length
+        display_width
           Optional, maximum display width for this number.
 
         unsigned
@@ -511,13 +511,17 @@ class MSInteger(sqltypes.Integer, _NumericType):
           underlying database API, which continue to be numeric.
         """
 
-        self.length = length
-        _NumericType.__init__(self, **kw)
-        sqltypes.Integer.__init__(self)
+        if 'length' in kw:
+            util.warn_deprecated("'length' is deprecated for MSInteger and subclasses.  Use 'display_width'.")
+            self.display_width = kw.pop('length')
+        else:
+            self.display_width = display_width
+        _NumericType.__init__(self, kw)
+        sqltypes.Integer.__init__(self, **kw)
 
     def get_col_spec(self):
-        if self.length is not None:
-            return self._extend("INTEGER(%(length)s)" % {'length': self.length})
+        if self.display_width is not None:
+            return self._extend("INTEGER(%(display_width)s)" % {'display_width': self.display_width})
         else:
             return self._extend("INTEGER")
 
@@ -525,10 +529,10 @@ class MSInteger(sqltypes.Integer, _NumericType):
 class MSBigInteger(MSInteger):
     """MySQL BIGINTEGER type."""
 
-    def __init__(self, length=None, **kw):
+    def __init__(self, display_width=None, **kw):
         """Construct a BIGINTEGER.
 
-        length
+        display_width
           Optional, maximum display width for this number.
 
         unsigned
@@ -540,11 +544,11 @@ class MSBigInteger(MSInteger):
           underlying database API, which continue to be numeric.
         """
 
-        super(MSBigInteger, self).__init__(length, **kw)
+        super(MSBigInteger, self).__init__(display_width, **kw)
 
     def get_col_spec(self):
-        if self.length is not None:
-            return self._extend("BIGINT(%(length)s)" % {'length': self.length})
+        if self.display_width is not None:
+            return self._extend("BIGINT(%(display_width)s)" % {'display_width': self.display_width})
         else:
             return self._extend("BIGINT")
 
@@ -552,14 +556,14 @@ class MSBigInteger(MSInteger):
 class MSTinyInteger(MSInteger):
     """MySQL TINYINT type."""
 
-    def __init__(self, length=None, **kw):
+    def __init__(self, display_width=None, **kw):
         """Construct a TINYINT.
 
         Note: following the usual MySQL conventions, TINYINT(1) columns
         reflected during Table(..., autoload=True) are treated as
         Boolean columns.
 
-        length
+        display_width
           Optional, maximum display width for this number.
 
         unsigned
@@ -571,11 +575,11 @@ class MSTinyInteger(MSInteger):
           underlying database API, which continue to be numeric.
         """
 
-        super(MSTinyInteger, self).__init__(length, **kw)
+        super(MSTinyInteger, self).__init__(display_width, **kw)
 
     def get_col_spec(self):
-        if self.length is not None:
-            return self._extend("TINYINT(%s)" % self.length)
+        if self.display_width is not None:
+            return self._extend("TINYINT(%s)" % self.display_width)
         else:
             return self._extend("TINYINT")
 
@@ -583,10 +587,10 @@ class MSTinyInteger(MSInteger):
 class MSSmallInteger(sqltypes.Smallinteger, MSInteger):
     """MySQL SMALLINTEGER type."""
 
-    def __init__(self, length=None, **kw):
+    def __init__(self, display_width=None, **kw):
         """Construct a SMALLINTEGER.
 
-        length
+        display_width
           Optional, maximum display width for this number.
 
         unsigned
@@ -598,13 +602,13 @@ class MSSmallInteger(sqltypes.Smallinteger, MSInteger):
           underlying database API, which continue to be numeric.
         """
 
-        self.length = length
-        _NumericType.__init__(self, **kw)
-        sqltypes.SmallInteger.__init__(self, length)
+        self.display_width = display_width
+        _NumericType.__init__(self, kw)
+        sqltypes.SmallInteger.__init__(self, **kw)
 
     def get_col_spec(self):
-        if self.length is not None:
-            return self._extend("SMALLINT(%(length)s)" % {'length': self.length})
+        if self.display_width is not None:
+            return self._extend("SMALLINT(%(display_width)s)" % {'display_width': self.display_width})
         else:
             return self._extend("SMALLINT")
 
@@ -690,14 +694,14 @@ class MSTimeStamp(sqltypes.TIMESTAMP):
 class MSYear(sqltypes.TypeEngine):
     """MySQL YEAR type, for single byte storage of years 1901-2155."""
 
-    def __init__(self, length=None):
-        self.length = length
+    def __init__(self, display_width=None):
+        self.display_width = display_width
 
     def get_col_spec(self):
-        if self.length is None:
+        if self.display_width is None:
             return "YEAR"
         else:
-            return "YEAR(%s)" % self.length
+            return "YEAR(%s)" % self.display_width
 
 class MSText(_StringType, sqltypes.Text):
     """MySQL TEXT type, for text up to 2^16 characters."""
index f2e5ba2f64ab1eb86773d2ac5b8e48329f14a96f..7b12e5af1b4fdfbbd67f671ac62e27e78fefcaa1 100644 (file)
@@ -19,7 +19,7 @@ class OracleNumeric(sqltypes.Numeric):
         if self.precision is None:
             return "NUMERIC"
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+            return "NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale}
 
 class OracleInteger(sqltypes.Integer):
     def get_col_spec(self):
index 744a573c90b275bf49182c284c62a21652ceaecb..aeed41078b506f3a781118e0c9dece83e8f53554 100644 (file)
@@ -45,7 +45,7 @@ class PGNumeric(sqltypes.Numeric):
         if not self.precision:
             return "NUMERIC"
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+            return "NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale}
 
     def bind_processor(self, dialect):
         return None
index b491ce07b43f04e5ae6b4f6099e75c0f9d6e2329..3840cb64cc0695069aaec535da2b44d3ad268a6f 100644 (file)
@@ -30,7 +30,7 @@ class SLNumeric(sqltypes.Numeric):
         if self.precision is None:
             return "NUMERIC"
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+            return "NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale}
 
 class SLFloat(sqltypes.Float):
     def bind_processor(self, dialect):
index aea77f8bfe647bed85561afa7e1e16b1810a41e3..5c64ec1aecee7371e4b8cf68c945786253627672 100644 (file)
@@ -168,18 +168,18 @@ class SybaseTypeError(sqltypes.TypeEngine):
 
 class SybaseNumeric(sqltypes.Numeric):
     def get_col_spec(self):
-        if self.length is None:
+        if self.scale is None:
             if self.precision is None:
                 return "NUMERIC"
             else:
                 return "NUMERIC(%(precision)s)" % {'precision' : self.precision}
         else:
-            return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+            return "NUMERIC(%(precision)s, %(scale)s)" % {'precision': self.precision, 'scale' : self.scale}
 
 class SybaseFloat(sqltypes.FLOAT, SybaseNumeric):
-    def __init__(self, precision = 10, asdecimal = False, length = 2, **kwargs):
+    def __init__(self, precision = 10, asdecimal = False, scale = 2, **kwargs):
         super(sqltypes.FLOAT, self).__init__(precision, asdecimal, **kwargs)
-        self.length = length
+        self.scale = scale
 
     def get_col_spec(self):
         # if asdecimal is True, handle same way as SybaseNumeric
index 3b08cf6f38e842916d84e570046cd8da50f28b2a..21762c66314bf8b3eed4c703174d4f917f05f9c8 100644 (file)
@@ -450,13 +450,16 @@ Smallinteger = SmallInteger
 class Numeric(TypeEngine):
     """Numeric datatype, usually resolves to DECIMAL or NUMERIC."""
 
-    def __init__(self, precision=10, length=2, asdecimal=True):
+    def __init__(self, precision=10, scale=2, asdecimal=True, length=None):
+        if length:
+            util.warn_deprecated("'length' is deprecated for Numeric.  Use 'scale'.")
+            scale = length
         self.precision = precision
-        self.length = length
+        self.scale = scale
         self.asdecimal = asdecimal
 
     def adapt(self, impltype):
-        return impltype(precision=self.precision, length=self.length, asdecimal=self.asdecimal)
+        return impltype(precision=self.precision, scale=self.scale, asdecimal=self.asdecimal)
 
     def get_dbapi_type(self, dbapi):
         return dbapi.NUMBER
index 443ab8878fc03fc7846a52f94176e54237032780..24ac0a97e317e30e73e214afd6cc82bca3dffbee 100644 (file)
@@ -380,6 +380,7 @@ def getargspec_init(method):
         else:
             return (['self'], 'args', 'kwargs', None)
 
+    
 def unbound_method_to_callable(func_or_cls):
     """Adjust the incoming callable such that a 'self' argument is not required."""
 
index 415f5a653f715ac7a4d29059849518cc5ee9a0ae..2c944fd3a108a92e386221e7907419303e07f45b 100644 (file)
@@ -659,7 +659,7 @@ class TypesTest(TestBase, AssertsExecutionResults):
                  ( mysql.MSNChar(2), mysql.MSChar(2), ), # N is CREATE only
                  ( mysql.MSNVarChar(22), mysql.MSString(22), ),
                  ( SmallInteger(), mysql.MSSmallInteger(), ),
-                 ( SmallInteger(4), mysql.MSSmallInteger(4), ),
+                 ( SmallInteger(), mysql.MSSmallInteger(4), ),
                  ( mysql.MSSmallInteger(), ),
                  ( mysql.MSSmallInteger(4), mysql.MSSmallInteger(4), ),
                  ( Binary(3), mysql.MSBlob(3), ),
index 681d6a5575e8dc01fbee6e84e2f30ad4982bb5b4..27e87ecebc22708b8cabb62c02933719b949e85d 100644 (file)
@@ -5,22 +5,16 @@ from sqlalchemy.sql import table, column
 from sqlalchemy import databases, sql, util
 from sqlalchemy.sql.compiler import BIND_TEMPLATES
 from sqlalchemy.engine import default
+from testlib.engines import all_dialects
 from sqlalchemy import types as sqltypes
 from testlib import *
 from sqlalchemy.sql.functions import GenericFunction
 from testlib.testing import eq_
 
 from sqlalchemy.databases import *
-# every dialect in databases.__all__ is expected to pass these tests.
-dialects = [getattr(databases, mod).dialect()
-            for mod in databases.__all__
-            # fixme!
-            if mod not in ('access',)]
-
-# if the configured dialect is out-of-tree or not yet in __all__, include it
-# too.
-if testing.db.name not in databases.__all__:
-    dialects.append(testing.db.dialect)
+
+# FIXME!
+dialects = [d for d in all_dialects() if d.name not in ('access', 'informix')]
 
 
 class CompileTest(TestBase, AssertsCompiledSQL):
index eaeac326ba4c69c28392406c6ba937fff40f94d2..345fbceac98cc33a71da3df11982c53ba39a08ea 100644 (file)
@@ -4,6 +4,7 @@ import datetime, os, pickleable, re
 from sqlalchemy import *
 from sqlalchemy import exc, types, util
 from sqlalchemy.sql import operators
+from testlib.testing import eq_
 import sqlalchemy.engine.url as url
 from sqlalchemy.databases import mssql, oracle, mysql, postgres, firebird
 from testlib import *
@@ -728,7 +729,34 @@ class NumericTest(TestBase, AssertsExecutionResults):
             assert isinstance(row['ncasdec'], decimal.Decimal)
             assert isinstance(row['fcasdec'], decimal.Decimal)
 
-
+    def test_length_deprecation(self):
+        self.assertRaises(exc.SADeprecationWarning, Numeric, length=8)
+        
+        @testing.uses_deprecated(".*is deprecated for Numeric")
+        def go():
+            n = Numeric(length=12)
+            assert n.scale == 12
+        go()
+        
+        n = Numeric(scale=12)
+        for dialect in engines.all_dialects():
+            n2 = dialect.type_descriptor(n)
+            eq_(n2.scale, 12, dialect.name)
+            
+            # test colspec generates successfully using 'scale'
+            assert n2.get_col_spec()
+            
+            # test constructor of the dialect-specific type
+            n3 = n2.__class__(scale=5)
+            eq_(n3.scale, 5, dialect.name)
+            
+            @testing.uses_deprecated(".*is deprecated for Numeric")
+            def go():
+                n3 = n2.__class__(length=6)
+                eq_(n3.scale, 6, dialect.name)
+            go()
+                
+            
 class IntervalTest(TestBase, AssertsExecutionResults):
     def setUpAll(self):
         global interval_table, metadata
index 3df98d4fc4ec524fdb86f4e1c63ac523808670bd..a6e9fb8b72d1e6c98857ea6e3bb024bc49e23b23 100644 (file)
@@ -66,6 +66,12 @@ def close_open_connections(fn):
             testing_reaper.close_all()
     return _function_named(decorated, fn.__name__)
 
+def all_dialects():
+    import sqlalchemy.databases as d
+    for name in d.__all__:
+        mod = getattr(__import__('sqlalchemy.databases.%s' % name).databases, name)
+        yield mod.dialect()
+        
 class ReconnectFixture(object):
     def __init__(self, dbapi):
         self.dbapi = dbapi