summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r--lib/sqlalchemy/databases/__init__.py1
-rw-r--r--lib/sqlalchemy/databases/firebird.py6
-rw-r--r--lib/sqlalchemy/databases/informix.py2
-rw-r--r--lib/sqlalchemy/databases/maxdb.py8
-rw-r--r--lib/sqlalchemy/databases/mssql.py2
-rw-r--r--lib/sqlalchemy/databases/mysql.py144
-rw-r--r--lib/sqlalchemy/databases/oracle.py2
-rw-r--r--lib/sqlalchemy/databases/postgres.py2
-rw-r--r--lib/sqlalchemy/databases/sqlite.py2
-rw-r--r--lib/sqlalchemy/databases/sybase.py8
10 files changed, 91 insertions, 86 deletions
diff --git a/lib/sqlalchemy/databases/__init__.py b/lib/sqlalchemy/databases/__init__.py
index 9837cd136..ec7ac6902 100644
--- a/lib/sqlalchemy/databases/__init__.py
+++ b/lib/sqlalchemy/databases/__init__.py
@@ -8,6 +8,7 @@
__all__ = (
'access',
'firebird',
+ 'informix',
'maxdb',
'mssql',
'mysql',
diff --git a/lib/sqlalchemy/databases/firebird.py b/lib/sqlalchemy/databases/firebird.py
index b2fcea095..ccd4db3c7 100644
--- a/lib/sqlalchemy/databases/firebird.py
+++ b/lib/sqlalchemy/databases/firebird.py
@@ -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
diff --git a/lib/sqlalchemy/databases/informix.py b/lib/sqlalchemy/databases/informix.py
index e5f400770..423226c18 100644
--- a/lib/sqlalchemy/databases/informix.py
+++ b/lib/sqlalchemy/databases/informix.py
@@ -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):
diff --git a/lib/sqlalchemy/databases/maxdb.py b/lib/sqlalchemy/databases/maxdb.py
index c9ea2b579..34629b298 100644
--- a/lib/sqlalchemy/databases/maxdb.py
+++ b/lib/sqlalchemy/databases/maxdb.py
@@ -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:
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index cfb34dd78..a2535754d 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -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):
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 4a4cfbd90..46e692463 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -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."""
diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py
index f2e5ba2f6..7b12e5af1 100644
--- a/lib/sqlalchemy/databases/oracle.py
+++ b/lib/sqlalchemy/databases/oracle.py
@@ -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):
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 744a573c9..aeed41078 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -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
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py
index b491ce07b..3840cb64c 100644
--- a/lib/sqlalchemy/databases/sqlite.py
+++ b/lib/sqlalchemy/databases/sqlite.py
@@ -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):
diff --git a/lib/sqlalchemy/databases/sybase.py b/lib/sqlalchemy/databases/sybase.py
index aea77f8bf..5c64ec1ae 100644
--- a/lib/sqlalchemy/databases/sybase.py
+++ b/lib/sqlalchemy/databases/sybase.py
@@ -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