]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- types.Binary is renamed to types.LargeBinary, it only
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Jan 2010 19:44:06 +0000 (19:44 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Jan 2010 19:44:06 +0000 (19:44 +0000)
produces BLOB, BYTEA, or a similar "long binary" type.
New base BINARY and VARBINARY
types have been added to access these MySQL/MS-SQL specific
types in an agnostic way [ticket:1664].

21 files changed:
CHANGES
doc/build/reference/sqlalchemy/types.rst
lib/sqlalchemy/__init__.py
lib/sqlalchemy/dialects/access/base.py
lib/sqlalchemy/dialects/informix/base.py
lib/sqlalchemy/dialects/maxdb/base.py
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/dialects/oracle/cx_oracle.py
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/dialects/sybase/base.py
lib/sqlalchemy/dialects/type_migration_guidelines.txt
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/types.py
test/dialect/test_mysql.py
test/engine/test_reflection.py
test/orm/inheritance/test_productspec.py
test/orm/test_unitofwork.py
test/sql/test_types.py

diff --git a/CHANGES b/CHANGES
index 28feff96783fb2dd9c844ac54de8502dc7e30c2d..326d64b1b7738a72b67c86720de0cb6a35914b44 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -788,6 +788,12 @@ CHANGES
       FLOAT, DECIMAL don't generate any length or scale unless
       specified.
     
+    - types.Binary is renamed to types.LargeBinary, it only
+      produces BLOB, BYTEA, or a similar "long binary" type.   
+      New base BINARY and VARBINARY
+      types have been added to access these MySQL/MS-SQL specific
+      types in an agnostic way [ticket:1664].
+      
     - String/Text/Unicode types now skip the unicode() check
       on each result column value if the dialect has 
       detected the DBAPI as returning Python unicode objects
index a22cf2ef708485eabc125e9abd69bb14a71a867b..0b26a83c265b0823b735fb8ea281122193ca8722 100644 (file)
@@ -38,9 +38,6 @@ database column type available on the target database when issuing a
 type is emitted in ``CREATE TABLE``, such as ``VARCHAR`` see `SQL
 Standard Types`_ and the other sections of this chapter.
 
-.. autoclass:: Binary
-   :show-inheritance:
-
 .. autoclass:: Boolean
   :show-inheritance:
 
@@ -64,6 +61,9 @@ Standard Types`_ and the other sections of this chapter.
 .. autoclass:: Interval
  :show-inheritance:
 
+.. autoclass:: LargeBinary
+ :show-inheritance:
+
 .. autoclass:: Numeric
   :show-inheritance:
   :members:
@@ -101,6 +101,9 @@ The SQL standard types always create database column types of the same
 name when ``CREATE TABLE`` is issued.  Some types may not be supported
 on all databases.
 
+.. autoclass:: BINARY
+  :show-inheritance:
+
 .. autoclass:: BLOB
   :show-inheritance:
 
@@ -149,6 +152,9 @@ on all databases.
 .. autoclass:: TIMESTAMP
   :show-inheritance:
 
+.. autoclass:: VARBINARY
+  :show-inheritance:
+
 .. autoclass:: VARCHAR
   :show-inheritance:
 
index 0fae8099763418ac7c78af03dc2b831cc701750a..8aa293a6cc29ca1aaa3682cfd956ecf763797c9b 100644 (file)
@@ -67,6 +67,7 @@ from sqlalchemy.types import (
     INTEGER,
     Integer,
     Interval,
+    LargeBinary,
     NCHAR,
     NVARCHAR,
     NUMERIC,
index d665dbda19f7f428828e2f5542edfe58dd0f4da0..a46ad247a4e7089d65e994685096021b070d93fd 100644 (file)
@@ -95,7 +95,7 @@ class AcChar(types.CHAR):
     def get_col_spec(self):
         return "TEXT" + (self.length and ("(%d)" % self.length) or "")
 
-class AcBinary(types.Binary):
+class AcBinary(types.LargeBinary):
     def get_col_spec(self):
         return "BINARY"
 
@@ -170,7 +170,7 @@ class AccessDialect(default.DefaultDialect):
         types.DateTime : AcDateTime,
         types.Date : AcDate,
         types.String : AcString,
-        types.Binary : AcBinary,
+        types.LargeBinary : AcBinary,
         types.Boolean : AcBoolean,
         types.Text : AcText,
         types.CHAR: AcChar,
index c11917c0f354cb5ca66cafc51352c9a6f580af3f..2802d493a6d80a0404e5d5e9d872a6d027239225 100644 (file)
@@ -65,7 +65,7 @@ ischema_names = {
     7   : sqltypes.DATE,         # DATE
     8   : sqltypes.Numeric,      # MONEY
     10  : sqltypes.DATETIME,     # DATETIME
-    11  : sqltypes.Binary,       # BYTE
+    11  : sqltypes.LargeBinary,       # BYTE
     12  : sqltypes.TEXT,         # TEXT
     13  : sqltypes.VARCHAR,       # VARCHAR
     15  : sqltypes.NCHAR,       # NCHAR
@@ -85,7 +85,7 @@ class InfoTypeCompiler(compiler.GenericTypeCompiler):
     def visit_TIME(self, type_):
         return "DATETIME HOUR TO SECOND"
 
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return "BYTE"
 
     def visit_boolean(self, type_):
index 891547ac3192bddc388eb71cf54016aa4017fa0a..2e0b9518b0035bb49b1469e328a022a22e90a11d 100644 (file)
@@ -263,7 +263,7 @@ class MaxTime(sqltypes.Time):
         return process
 
 
-class MaxBlob(sqltypes.Binary):
+class MaxBlob(sqltypes.LargeBinary):
     def bind_processor(self, dialect):
         def process(value):
             if value is None:
@@ -306,7 +306,7 @@ class MaxDBTypeCompiler(compiler.GenericTypeCompiler):
     def visit_string(self, type_):
         return self._string_spec("VARCHAR", type_)
 
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return "LONG BYTE"
     
     def visit_numeric(self, type_):
@@ -327,7 +327,7 @@ colspecs = {
     sqltypes.Time: MaxTime,
     sqltypes.String: MaxString,
     sqltypes.Unicode:MaxUnicode,
-    sqltypes.Binary: MaxBlob,
+    sqltypes.LargeBinary: MaxBlob,
     sqltypes.Text: MaxText,
     sqltypes.CHAR: MaxChar,
     sqltypes.TIMESTAMP: MaxTimestamp,
index 8f52c4b1259dd498b00ea61d1b8d21074d67baae..4e58d64b362d40d5b192b23cef20f059d257fbc2 100644 (file)
@@ -235,7 +235,8 @@ from sqlalchemy.engine import default, base, reflection
 from sqlalchemy import types as sqltypes
 from decimal import Decimal as _python_Decimal
 from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, DECIMAL, NUMERIC, \
-                                FLOAT, TIMESTAMP, DATETIME, DATE
+                                FLOAT, TIMESTAMP, DATETIME, DATE, BINARY,\
+                                VARBINARY, BLOB
             
 
 from sqlalchemy.dialects.mssql import information_schema as ischema
@@ -592,13 +593,7 @@ class NCHAR(_StringType, sqltypes.NCHAR):
         _StringType.__init__(self, collation)
         sqltypes.NCHAR.__init__(self, *args, **kw)
 
-class BINARY(sqltypes.Binary):
-    __visit_name__ = 'BINARY'
-
-class VARBINARY(sqltypes.Binary):
-    __visit_name__ = 'VARBINARY'
-        
-class IMAGE(sqltypes.Binary):
+class IMAGE(sqltypes.LargeBinary):
     __visit_name__ = 'IMAGE'
 
 class BIT(sqltypes.TypeEngine):
@@ -772,27 +767,12 @@ class MSTypeCompiler(compiler.GenericTypeCompiler):
         else:
             return self.visit_TIME(type_)
             
-    def visit_binary(self, type_):
-        if type_.length:
-            return self.visit_BINARY(type_)
-        else:
-            return self.visit_IMAGE(type_)
-
-    def visit_BINARY(self, type_):
-        if type_.length:
-            return "BINARY(%s)" % type_.length
-        else:
-            return "BINARY"
+    def visit_large_binary(self, type_):
+        return self.visit_IMAGE(type_)
 
     def visit_IMAGE(self, type_):
         return "IMAGE"
 
-    def visit_VARBINARY(self, type_):
-        if type_.length:
-            return "VARBINARY(%s)" % type_.length
-        else:
-            return "VARBINARY"
-
     def visit_boolean(self, type_):
         return self.visit_BIT(type_)
 
@@ -1290,7 +1270,7 @@ class MSDialect(default.DefaultDialect):
             coltype = self.ischema_names.get(type, None)
 
             kwargs = {}
-            if coltype in (MSString, MSChar, MSNVarchar, MSNChar, MSText, MSNText, MSBinary, MSVarBinary, sqltypes.Binary):
+            if coltype in (MSString, MSChar, MSNVarchar, MSNChar, MSText, MSNText, MSBinary, MSVarBinary, sqltypes.LargeBinary):
                 kwargs['length'] = charlen
                 if collation:
                     kwargs['collation'] = collation
index e3235783c61d5261e5fdb35e160643f77adcaead..1a85babe4a2215d5a90c2ae5f9e62a200ee95403 100644 (file)
@@ -197,7 +197,8 @@ from sqlalchemy.engine import reflection
 from sqlalchemy.engine import base as engine_base, default
 from sqlalchemy import types as sqltypes
 
-from sqlalchemy.types import DATE, DATETIME, BOOLEAN, TIME
+from sqlalchemy.types import DATE, DATETIME, BOOLEAN, TIME, \
+                                BLOB, BINARY, VARBINARY
 
 RESERVED_WORDS = set(
     ['accessible', 'add', 'all', 'alter', 'analyze','and', 'as', 'asc',
@@ -305,11 +306,6 @@ class _StringType(sqltypes.String):
                            ', '.join(['%s=%r' % (k, params[k]) for k in params]))
 
 
-class _BinaryType(sqltypes.Binary):
-    """Base for MySQL binary types."""
-
-    pass
-
 class NUMERIC(_NumericType, sqltypes.NUMERIC):
     """MySQL NUMERIC type."""
     
@@ -826,62 +822,18 @@ class NCHAR(_StringType, sqltypes.NCHAR):
 
 
 
-class VARBINARY(_BinaryType):
-    """MySQL VARBINARY type, for variable length binary data."""
-
-    __visit_name__ = 'VARBINARY'
-
-    def __init__(self, length=None, **kw):
-        """Construct a VARBINARY.  Arguments are:
-
-        :param length: Maximum data length, in characters.
-
-        """
-        super(VARBINARY, self).__init__(length=length, **kw)
-
-class BINARY(_BinaryType):
-    """MySQL BINARY type, for fixed length binary data"""
-
-    __visit_name__ = 'BINARY'
-
-    def __init__(self, length=None, **kw):
-        """Construct a BINARY.
-
-        This is a fixed length type, and short values will be right-padded
-        with a server-version-specific pad value.
-
-        :param length: Maximum data length, in bytes. 
-
-        """
-        super(BINARY, self).__init__(length=length, **kw)
 
-class BLOB(_BinaryType, sqltypes.BLOB):
-    """MySQL BLOB type, for binary data up to 2^16 bytes"""
-
-    __visit_name__ = 'BLOB'
-
-    def __init__(self, length=None, **kw):
-        """Construct a BLOB.  Arguments are:
-
-        :param length: Optional, if provided the server may optimize storage
-          by substituting the smallest TEXT type sufficient to store
-          ``length`` characters.
-
-        """
-        super(BLOB, self).__init__(length=length, **kw)
-
-
-class TINYBLOB(_BinaryType):
+class TINYBLOB(sqltypes._Binary):
     """MySQL TINYBLOB type, for binary data up to 2^8 bytes."""
     
     __visit_name__ = 'TINYBLOB'
 
-class MEDIUMBLOB(_BinaryType):
+class MEDIUMBLOB(sqltypes._Binary):
     """MySQL MEDIUMBLOB type, for binary data up to 2^24 bytes."""
 
     __visit_name__ = 'MEDIUMBLOB'
 
-class LONGBLOB(_BinaryType):
+class LONGBLOB(sqltypes._Binary):
     """MySQL LONGBLOB type, for binary data up to 2^32 bytes."""
 
     __visit_name__ = 'LONGBLOB'
@@ -1122,7 +1074,6 @@ MSInteger = INTEGER
 colspecs = {
     sqltypes.Numeric: NUMERIC,
     sqltypes.Float: FLOAT,
-    sqltypes.Binary: _BinaryType,
     sqltypes.Time: _MSTime,
     sqltypes.Enum: ENUM,
 }
@@ -1217,7 +1168,7 @@ class MySQLCompiler(compiler.SQLCompiler):
                 return 'CHAR(%s)' % type_.length
             else:
                 return 'CHAR'
-        elif isinstance(type_, sqltypes.Binary):
+        elif isinstance(type_, sqltypes._Binary):
             return 'BINARY'
         elif isinstance(type_, NUMERIC):
             return self.dialect.type_compiler.process(type_).replace('NUMERIC', 'DECIMAL')
@@ -1425,7 +1376,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
                          if c is not None])
     
     def _mysql_type(self, type_):
-        return isinstance(type_, (_StringType, _NumericType, _BinaryType))
+        return isinstance(type_, (_StringType, _NumericType))
     
     def visit_NUMERIC(self, type_):
         if type_.precision is None:
@@ -1564,12 +1515,9 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
             return self._extend_string(type_, {'national':True}, "CHAR")
     
     def visit_VARBINARY(self, type_):
-        if type_.length:
-            return "VARBINARY(%d)" % type_.length
-        else:
-            return self.visit_BLOB(type_)
+        return "VARBINARY(%d)" % type_.length
     
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return self.visit_BLOB(type_)
     
     def visit_enum(self, type_):
@@ -1578,12 +1526,6 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
         else:
             return self.visit_ENUM(type_)
     
-    def visit_BINARY(self, type_):
-        if type_.length:
-            return "BINARY(%d)" % type_.length
-        else:
-            return "BINARY"
-    
     def visit_BLOB(self, type_):
         if type_.length:
             return "BLOB(%d)" % type_.length
index 882505a405037c528b7f2e5d3ce912d823b1349c..92679696109ec39844987bc6e1f7d47f00d7da4b 100644 (file)
@@ -122,7 +122,7 @@ from sqlalchemy.types import VARCHAR, NVARCHAR, CHAR, DATE, DATETIME, \
                 
 RESERVED_WORDS = set('''SHARE RAW DROP BETWEEN FROM DESC OPTION PRIOR LONG THEN DEFAULT ALTER IS INTO MINUS INTEGER NUMBER GRANT IDENTIFIED ALL TO ORDER ON FLOAT DATE HAVING CLUSTER NOWAIT RESOURCE ANY TABLE INDEX FOR UPDATE WHERE CHECK SMALLINT WITH DELETE BY ASC REVOKE LIKE SIZE RENAME NOCOMPRESS NULL GROUP VALUES AS IN VIEW EXCLUSIVE COMPRESS SYNONYM SELECT INSERT EXISTS NOT TRIGGER ELSE CREATE INTERSECT PCTFREE DISTINCT USER CONNECT SET MODE OF UNIQUE VARCHAR2 VARCHAR LOCK OR CHAR DECIMAL UNION PUBLIC AND START UID COMMENT'''.split()) 
 
-class RAW(sqltypes.Binary):
+class RAW(sqltypes.LargeBinary):
     pass
 OracleRaw = RAW
 
@@ -157,7 +157,7 @@ class DOUBLE_PRECISION(sqltypes.Numeric):
                 
         super(DOUBLE_PRECISION, self).__init__(precision=precision, scale=scale, asdecimal=asdecimal)
 
-class BFILE(sqltypes.Binary):
+class BFILE(sqltypes.LargeBinary):
     __visit_name__ = 'BFILE'
 
 class LONG(sqltypes.Text):
@@ -282,7 +282,7 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler):
     def visit_unicode_text(self, type_):
         return self.visit_NCLOB(type_)
 
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return self.visit_BLOB(type_)
 
     def visit_big_integer(self, type_):
index 6b1d7e5b99df7c6dced38cf6f22085d7494dc580..d0058e454394ca1a7d42e0025ac6b13ac7bb6096 100644 (file)
@@ -160,7 +160,7 @@ class _OracleInteger(sqltypes.Integer):
             return val
         return to_int
         
-class _OracleBinary(_LOBMixin, sqltypes.Binary):
+class _OracleBinary(_LOBMixin, sqltypes.LargeBinary):
     def get_dbapi_type(self, dbapi):
         return dbapi.BLOB
 
@@ -176,7 +176,7 @@ class _OracleRaw(oracle.RAW):
 
 colspecs = {
     sqltypes.Date : _OracleDate,
-    sqltypes.Binary : _OracleBinary,
+    sqltypes.LargeBinary : _OracleBinary,
     sqltypes.Boolean : oracle._OracleBoolean,
     sqltypes.Interval : _OracleInterval,
     oracle.INTERVAL : _OracleInterval,
index bc5459f3a3c00bbf97f45703a40149b1315b4973..cfbef69e89e3f1d1e695492926342e24e62733a8 100644 (file)
@@ -83,7 +83,7 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \
 class REAL(sqltypes.Float):
     __visit_name__ = "REAL"
 
-class BYTEA(sqltypes.Binary):
+class BYTEA(sqltypes.LargeBinary):
     __visit_name__ = 'BYTEA'
 
 class DOUBLE_PRECISION(sqltypes.Float):
@@ -476,7 +476,7 @@ class PGTypeCompiler(compiler.GenericTypeCompiler):
     def visit_UUID(self, type_):
         return "UUID"
 
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return self.visit_BYTEA(type_)
         
     def visit_BYTEA(self, type_):
index 85f1157e0719576331208cf2613422c9f7bc4ff2..93e62ec245c0da9f0e9a242fbb4b53d6e6c1d53b 100644 (file)
@@ -300,7 +300,7 @@ class SQLiteDDLCompiler(compiler.DDLCompiler):
         return text
 
 class SQLiteTypeCompiler(compiler.GenericTypeCompiler):
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return self.visit_BLOB(type_)
 
 class SQLiteIdentifierPreparer(compiler.IdentifierPreparer):
index 63e1d01aa67795bdabd2ae66e433bc6fbb6f6e3a..cdbf6138daee332aeb7ca6303bb7e4e5255e87bd 100644 (file)
@@ -99,7 +99,7 @@ RESERVED_WORDS = set([
     ])
 
 
-class SybaseImage(sqltypes.Binary):
+class SybaseImage(sqltypes.LargeBinary):
     __visit_name__ = 'IMAGE'
 
 class SybaseBit(sqltypes.TypeEngine):
@@ -135,7 +135,7 @@ class SybaseBoolean(sqltypes.Boolean):
         return process
 
 class SybaseTypeCompiler(compiler.GenericTypeCompiler):
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return self.visit_IMAGE(type_)
     
     def visit_boolean(self, type_):
@@ -157,7 +157,7 @@ class SybaseTypeCompiler(compiler.GenericTypeCompiler):
         return "UNIQUEIDENTIFIER"
         
 colspecs = {
-    sqltypes.Binary : SybaseImage,
+    sqltypes.LargeBinary : SybaseImage,
     sqltypes.Boolean : SybaseBoolean,
 }
 
@@ -176,9 +176,9 @@ ischema_names = {
     'numeric' : sqltypes.NUMERIC,
     'float' : sqltypes.FLOAT,
     'double' : sqltypes.Numeric,
-    'binary' : sqltypes.Binary,
-    'long binary' : sqltypes.Binary,
-    'varbinary' : sqltypes.Binary,
+    'binary' : sqltypes.LargeBinary,
+    'long binary' : sqltypes.LargeBinary,
+    'varbinary' : sqltypes.LargeBinary,
     'bit': SybaseBit,
     'image' : SybaseImage,
     'timestamp': sqltypes.TIMESTAMP,
index 8ed1a17975409ab77c87a0e3b6ea56adae89480e..c26b65e08dc4e372e804f3e16073695f72289766 100644 (file)
@@ -139,7 +139,7 @@ a subclass of compiler.GenericTypeCompiler.
     arguments and flags to those types.  
     
     d. the visit_lowercase methods are overridden to provide an interpretation of a generic 
-    type.  E.g.  visit_binary() might be overridden to say "return self.visit_BIT(type_)".
+    type.  E.g.  visit_large_binary() might be overridden to say "return self.visit_BIT(type_)".
     
     e. visit_lowercase methods should *never* render strings directly - it should always
     be via calling a visit_UPPERCASE() method.
index 2d099e9d5416e2f55ccf9ed383a81acb27903295..e635e20e18afd5db80583834bb792129a948ed04 100644 (file)
@@ -1217,6 +1217,12 @@ class GenericTypeCompiler(engine.TypeCompiler):
 
     def visit_BLOB(self, type_):
         return "BLOB"
+
+    def visit_BINARY(self, type_):
+        return "BINARY" + (type_.length and "(%d)" % type_.length or "")
+
+    def visit_VARBINARY(self, type_):
+        return "VARBINARY" + (type_.length and "(%d)" % type_.length or "")
     
     def visit_BOOLEAN(self, type_):
         return "BOOLEAN"
@@ -1224,7 +1230,7 @@ class GenericTypeCompiler(engine.TypeCompiler):
     def visit_TEXT(self, type_):
         return "TEXT"
     
-    def visit_binary(self, type_):
+    def visit_large_binary(self, type_):
         return self.visit_BLOB(type_)
         
     def visit_boolean(self, type_): 
index 5ed631a86791b521a30ad8ed34e9f3c378cbbc45..b4e9ba0cd0cc070d25ffdad3fd224ae4de068c15 100644 (file)
@@ -16,7 +16,7 @@ __all__ = [ 'TypeEngine', 'TypeDecorator', 'AbstractType', 'UserDefinedType',
             'FLOAT', 'NUMERIC', 'DECIMAL', 'TIMESTAMP', 'DATETIME', 'CLOB',
             'BLOB', 'BOOLEAN', 'SMALLINT', 'INTEGER', 'DATE', 'TIME',
             'String', 'Integer', 'SmallInteger', 'BigInteger', 'Numeric',
-            'Float', 'DateTime', 'Date', 'Time', 'Binary', 'Boolean',
+            'Float', 'DateTime', 'Date', 'Time', 'LargeBinary', 'Binary', 'Boolean',
             'Unicode', 'MutableType', 'Concatenable', 'UnicodeText',
             'PickleType', 'Interval', 'type_map', 'Enum' ]
 
@@ -845,29 +845,10 @@ class Time(TypeEngine):
     def get_dbapi_type(self, dbapi):
         return dbapi.DATETIME
 
-
-class Binary(TypeEngine):
-    """A type for binary byte data.
-
-    The Binary type generates BLOB or BYTEA when tables are created,
-    and also converts incoming values using the ``Binary`` callable
-    provided by each DB-API.
-
-    """
-
-    __visit_name__ = 'binary'
+class _Binary(TypeEngine):
+    """Define base behavior for binary types."""
 
     def __init__(self, length=None):
-        """
-        Construct a Binary type.
-
-        :param length: optional, a length for the column for use in
-          DDL statements.  May be safely omitted if no ``CREATE
-          TABLE`` will be issued.  Certain databases may require a
-          *length* for use in DDL, and will raise an exception when
-          the ``CREATE TABLE`` DDL is issued.
-
-        """
         self.length = length
 
     # Python 3 - sqlite3 doesn't need the `Binary` conversion
@@ -908,6 +889,40 @@ class Binary(TypeEngine):
 
     def get_dbapi_type(self, dbapi):
         return dbapi.BINARY
+    
+class LargeBinary(_Binary):
+    """A type for large binary byte data.
+
+    The Binary type generates BLOB or BYTEA when tables are created,
+    and also converts incoming values using the ``Binary`` callable
+    provided by each DB-API.
+
+    """
+
+    __visit_name__ = 'large_binary'
+
+    def __init__(self, length=None):
+        """
+        Construct a LargeBinary type.
+
+        :param length: optional, a length for the column for use in
+          DDL statements, for those BLOB types that accept a length
+          (i.e. MySQL).  It does *not* produce a small BINARY/VARBINARY
+          type - use the BINARY/VARBINARY types specifically for those.
+          May be safely omitted if no ``CREATE
+          TABLE`` will be issued.  Certain databases may require a
+          *length* for use in DDL, and will raise an exception when
+          the ``CREATE TABLE`` DDL is issued.
+
+        """
+        _Binary.__init__(self, length=length)
+
+class Binary(LargeBinary):
+    """Deprecated.  Renamed to LargeBinary."""
+    
+    def __init__(self, *arg, **kw):
+        util.warn_deprecated("The Binary type has been renamed to LargeBinary.")
+        LargeBinary.__init__(self, *arg, **kw)
 
 class SchemaType(object):
     """Mark a type as possibly requiring schema-level DDL for usage.
@@ -1100,7 +1115,7 @@ class PickleType(MutableType, TypeDecorator):
 
     """
 
-    impl = Binary
+    impl = LargeBinary
 
     def __init__(self, protocol=pickle.HIGHEST_PROTOCOL, pickler=None, mutable=True, comparator=None):
         """
@@ -1398,11 +1413,21 @@ class NCHAR(Unicode):
     __visit_name__ = 'NCHAR'
 
 
-class BLOB(Binary):
+class BLOB(LargeBinary):
     """The SQL BLOB type."""
 
     __visit_name__ = 'BLOB'
 
+class BINARY(_Binary):
+    """The SQL BINARY type."""
+
+    __visit_name__ = 'BINARY'
+
+class VARBINARY(_Binary):
+    """The SQL VARBINARY type."""
+
+    __visit_name__ = 'VARBINARY'
+
 
 class BOOLEAN(Boolean):
     """The SQL BOOLEAN type."""
index 4a419772533ba7dcd6da4c0bfeb8a2fd4a8a32b3..09213cf95671ce7259e1b62592e35d378f2dcefa 100644 (file)
@@ -817,11 +817,10 @@ class ReflectionTest(TestBase, AssertsExecutionResults):
                  ( mysql.MSSmallInteger(4), mysql.MSSmallInteger(4), ),
                  ( mysql.MSMediumInteger(), mysql.MSMediumInteger(), ),
                  ( mysql.MSMediumInteger(8), mysql.MSMediumInteger(8), ),
-                 ( Binary(3), mysql.TINYBLOB(), ),
-                 ( Binary(), mysql.BLOB() ),
+                 ( LargeBinary(3), mysql.TINYBLOB(), ),
+                 ( LargeBinary(), mysql.BLOB() ),
                  ( mysql.MSBinary(3), mysql.MSBinary(3), ),
                  ( mysql.MSVarBinary(3),),
-                 ( mysql.MSVarBinary(), mysql.MSBlob()),
                  ( mysql.MSTinyBlob(),),
                  ( mysql.MSBlob(),),
                  ( mysql.MSBlob(1234), mysql.MSBlob()),
@@ -1081,7 +1080,7 @@ class SQLTest(TestBase, AssertsCompiledSQL):
             (m.MSNChar, "CAST(t.col AS CHAR)"),
             (m.MSNVarChar, "CAST(t.col AS CHAR)"),
 
-            (Binary, "CAST(t.col AS BINARY)"),
+            (LargeBinary, "CAST(t.col AS BINARY)"),
             (BLOB, "CAST(t.col AS BINARY)"),
             (m.MSBlob, "CAST(t.col AS BINARY)"),
             (m.MSBlob(32), "CAST(t.col AS BINARY)"),
index bc2c896ab26cff578c88c864b4d5caba9b883db9..95f985db3d587b49fb536b64a8c30692418a3f89 100644 (file)
@@ -32,9 +32,9 @@ class ReflectionTest(TestBase, ComparesTables):
                    sa.ForeignKey('engine_users.user_id')),
             Column('test6', sa.Date, nullable=False),
             Column('test7', sa.Text),
-            Column('test8', sa.Binary),
+            Column('test8', sa.LargeBinary),
             Column('test_passivedefault2', sa.Integer, server_default='5'),
-            Column('test9', sa.Binary(100)),
+            Column('test9', sa.LargeBinary(100)),
             Column('test10', sa.Numeric(10, 2)),
             test_needs_fk=True,
         )
@@ -951,9 +951,9 @@ def createTables(meta, schema=None):
         parent_user_id,
         Column('test6', sa.Date, nullable=False),
         Column('test7', sa.Text),
-        Column('test8', sa.Binary),
+        Column('test8', sa.LargeBinary),
         Column('test_passivedefault2', sa.Integer, server_default='5'),
-        Column('test9', sa.Binary(100)),
+        Column('test9', sa.LargeBinary(100)),
         Column('test10', sa.Numeric(10, 2)),
         schema=schema,
         test_needs_fk=True,
@@ -1083,7 +1083,7 @@ class ComponentReflectionTest(TestBase):
                             ).intersection(ctype_def.__mro__)
                             .intersection([sql_types.Integer, sql_types.Numeric, 
                                             sql_types.DateTime, sql_types.Date, sql_types.Time, 
-                                            sql_types.String, sql_types.Binary])
+                                            sql_types.String, sql_types._Binary])
                             ) > 0
                     ,("%s(%s), %s(%s)" % (col.name, col.type, cols[i]['name'],
                                           ctype)))
index 4c593e2a38f69e51bce3bbbbbe1a256a847233df..deb7564a8fee8ef1f9cb1fc43e1c01713fc9c8f2 100644 (file)
@@ -37,7 +37,7 @@ class InheritTest(_base.MappedTest):
             Column('last_updated', DateTime, default=lambda:datetime.now(),
                 onupdate=lambda:datetime.now()),
             Column('name', String(128)),
-            Column('data', Binary),
+            Column('data', LargeBinary),
             Column('size', Integer, default=0),
             )
 
index 85a0eae82137e901e2ee03736b576aa855086e6a..265ce3fc0bfa6cd2deff5948e1d30184e4c475f3 100644 (file)
@@ -337,7 +337,7 @@ class BinaryHistTest(_base.MappedTest, testing.AssertsExecutionResults):
     def define_tables(cls, metadata):
         Table('t1', metadata,
             Column('id', sa.Integer, primary_key=True, test_needs_autoincrement=True),
-            Column('data', sa.Binary),
+            Column('data', sa.LargeBinary),
         )
 
     @classmethod
index b31015d85ba561a021df690d6d36d32bcdd825f8..4b7cba73c28b2c431624ace02b57a2c29b845cb5 100644 (file)
@@ -63,9 +63,9 @@ class TypeAffinityTest(TestBase):
             (Integer(), Integer(), True),
             (Text(), String(), True),
             (Text(), Unicode(), True),
-            (Binary(), Integer(), False),
-            (Binary(), PickleType(), True),
-            (PickleType(), Binary(), True),
+            (LargeBinary(), Integer(), False),
+            (LargeBinary(), PickleType(), True),
+            (PickleType(), LargeBinary(), True),
             (PickleType(), PickleType(), True),
         ]:
             eq_(t1._compare_type_affinity(t2), comp, "%s %s" % (t1, t2))
@@ -466,8 +466,8 @@ class BinaryTest(TestBase, AssertsExecutionResults):
 
         binary_table = Table('binary_table', MetaData(testing.db),
             Column('primary_id', Integer, Sequence('binary_id_seq', optional=True), primary_key=True),
-            Column('data', Binary),
-            Column('data_slice', Binary(100)),
+            Column('data', LargeBinary),
+            Column('data_slice', LargeBinary(100)),
             Column('misc', String(30)),
             # construct PickleType with non-native pickle module, since cPickle uses relative module
             # loading and confuses this test's parent package 'sql' with the 'sqlalchemy.sql' package relative
@@ -516,7 +516,7 @@ class BinaryTest(TestBase, AssertsExecutionResults):
             binary_table.select(order_by=binary_table.c.primary_id),
             text(
                 "select * from binary_table order by binary_table.primary_id", 
-                typemap={'pickled':PickleType, 'mypickle':MyPickleType, 'data':Binary, 'data_slice':Binary}, 
+                typemap={'pickled':PickleType, 'mypickle':MyPickleType, 'data':LargeBinary, 'data_slice':LargeBinary}, 
                 bind=testing.db)
         ):
             l = stmt.execute().fetchall()