]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- changed name of TEXT to Text since its a "generic" type; TEXT name is
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Jan 2008 22:59:18 +0000 (22:59 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Jan 2008 22:59:18 +0000 (22:59 +0000)
deprecated until 0.5.  The "upgrading" behavior of String to Text
when no length is present is also deprecated until 0.5; will issue a
warning when used for CREATE TABLE statements (String with no length
for SQL expression purposes is still fine) [ticket:912]

14 files changed:
CHANGES
lib/sqlalchemy/databases/access.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/sql/compiler.py
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/types.py

diff --git a/CHANGES b/CHANGES
index f63c50a424b00659a1142aeb22cbddeef12ca840..fa9ea42d7598b46946ff1c6d1ccc0a7f74c52bd9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,12 @@ CHANGES
 
 0.4.2b
 ------
+- sql
+    - changed name of TEXT to Text since its a "generic" type; TEXT name is
+      deprecated until 0.5.  The "upgrading" behavior of String to Text 
+      when no length is present is also deprecated until 0.5; will issue a
+      warning when used for CREATE TABLE statements (String with no length
+      for SQL expression purposes is still fine) [ticket:912]
 
 - orm
     - Fixed cascades on a += assignment to a list-based relation.
index 354a8c33224e8ffd2f4ec4ca200fbd3c3b95bd9b..78e3a99970ece49f5c4b09be69459e0c8b14e6c7 100644 (file)
@@ -64,7 +64,7 @@ class AcDate(types.Date):
     def get_col_spec(self):
         return "DATETIME"
 
-class AcText(types.TEXT):
+class AcText(types.Text):
     def get_col_spec(self):
         return "MEMO"
 
@@ -172,7 +172,7 @@ class AccessDialect(default.DefaultDialect):
         types.String : AcString,
         types.Binary : AcBinary,
         types.Boolean : AcBoolean,
-        types.TEXT : AcText,
+        types.Text : AcText,
         types.CHAR: AcChar,
         types.TIMESTAMP: AcTimeStamp,
     }
index 9dca32a3369bbb3a16892048164d3318bdfd60d9..24740017944052ebe69c825a11190395171f29a1 100644 (file)
@@ -177,7 +177,7 @@ class FBTime(sqltypes.Time):
         return "TIME"
 
 
-class FBText(sqltypes.TEXT):
+class FBText(sqltypes.Text):
     """Handle ``BLOB SUB_TYPE 1`` datatype (aka *textual* blob)."""
 
     def get_col_spec(self):
@@ -223,7 +223,7 @@ colspecs = {
     sqltypes.String : FBString,
     sqltypes.Binary : FBBinary,
     sqltypes.Boolean : FBBoolean,
-    sqltypes.TEXT : FBText,
+    sqltypes.Text : FBText,
     sqltypes.CHAR: FBChar,
 }
 
index f04d53f0f3df414cd7af5209d10c079a4f881069..3ad490f44b29d4f7b66ca3d66545851a94558484 100644 (file)
@@ -150,7 +150,7 @@ colspecs = {
     sqltypes.String : InfoString,
     sqltypes.Binary : InfoBinary,
     sqltypes.Boolean : InfoBoolean,
-    sqltypes.TEXT : InfoText,
+    sqltypes.Text : InfoText,
     sqltypes.CHAR: InfoChar,
 }
 
index 3ca1bd61cc218d93c6574cd41fd7ca9fc4921748..b5d397d545601f22b4d02f2c837a16b45624ea61 100644 (file)
@@ -353,7 +353,7 @@ colspecs = {
     sqltypes.String: MaxString,
     sqltypes.Binary: MaxBlob,
     sqltypes.Boolean: MaxBoolean,
-    sqltypes.TEXT: MaxText,
+    sqltypes.Text: MaxText,
     sqltypes.CHAR: MaxChar,
     sqltypes.TIMESTAMP: MaxTimestamp,
     sqltypes.BLOB: MaxBlob,
index 8d43e7616f7b422e9537a13476ccf2bfe1e71737..69cf1bcc602d44a1b450eb68732e1250527351e6 100644 (file)
@@ -192,7 +192,7 @@ class MSDate_pymssql(MSDate):
                 return value
         return process
         
-class MSText(sqltypes.TEXT):
+class MSText(sqltypes.Text):
     def get_col_spec(self):
         if self.dialect.text_as_varchar:
             return "VARCHAR(max)"            
@@ -380,7 +380,7 @@ class MSSQLDialect(default.DefaultDialect):
         sqltypes.String : MSString,
         sqltypes.Binary : MSBinary,
         sqltypes.Boolean : MSBoolean,
-        sqltypes.TEXT : MSText,
+        sqltypes.Text : MSText,
         sqltypes.CHAR: MSChar,
         sqltypes.NCHAR: MSNChar,
         sqltypes.TIMESTAMP: MSTimeStamp,
index d89b6f5dbab56bbe830928d845702be257a81e5e..4f7f10a78a95486a8328d6929190811c90788919 100644 (file)
@@ -685,7 +685,7 @@ class MSYear(sqltypes.TypeEngine):
         else:
             return "YEAR(%s)" % self.length
 
-class MSText(_StringType, sqltypes.TEXT):
+class MSText(_StringType, sqltypes.Text):
     """MySQL TEXT type, for text up to 2^16 characters."""
 
     def __init__(self, length=None, **kwargs):
@@ -724,7 +724,7 @@ class MSText(_StringType, sqltypes.TEXT):
         """
 
         _StringType.__init__(self, **kwargs)
-        sqltypes.TEXT.__init__(self, length,
+        sqltypes.Text.__init__(self, length,
                                kwargs.get('convert_unicode', False), kwargs.get('assert_unicode', None))
 
     def get_col_spec(self):
@@ -1318,7 +1318,7 @@ colspecs = {
     sqltypes.String: MSString,
     sqltypes.Binary: MSBlob,
     sqltypes.Boolean: MSBoolean,
-    sqltypes.TEXT: MSText,
+    sqltypes.Text: MSText,
     sqltypes.CHAR: MSChar,
     sqltypes.NCHAR: MSNChar,
     sqltypes.TIMESTAMP: MSTimeStamp,
index 163b4f58b88ef862684fa4891861972a9dd6f836..79a276d62db3da70f8961a2b383331fe02017212 100644 (file)
@@ -86,7 +86,7 @@ class OracleString(sqltypes.String):
     def get_col_spec(self):
         return "VARCHAR(%(length)s)" % {'length' : self.length}
 
-class OracleText(sqltypes.TEXT):
+class OracleText(sqltypes.Text):
     def get_dbapi_type(self, dbapi):
         return dbapi.CLOB
 
@@ -169,7 +169,7 @@ colspecs = {
     sqltypes.String : OracleString,
     sqltypes.Binary : OracleBinary,
     sqltypes.Boolean : OracleBoolean,
-    sqltypes.TEXT : OracleText,
+    sqltypes.Text : OracleText,
     sqltypes.TIMESTAMP : OracleTimestamp,
     sqltypes.CHAR: OracleChar,
 }
index 01b1b10d32805d27af52e114bf08541bb3d3f6e6..eacd0c7e11c76aabef1bf9cc8212157601351087 100644 (file)
@@ -89,7 +89,7 @@ class PGInterval(sqltypes.TypeEngine):
     def get_col_spec(self):
         return "INTERVAL"
 
-class PGText(sqltypes.TEXT):
+class PGText(sqltypes.Text):
     def get_col_spec(self):
         return "TEXT"
 
@@ -166,7 +166,7 @@ colspecs = {
     sqltypes.String : PGString,
     sqltypes.Binary : PGBinary,
     sqltypes.Boolean : PGBoolean,
-    sqltypes.TEXT : PGText,
+    sqltypes.Text : PGText,
     sqltypes.CHAR: PGChar,
 }
 
index fa4466688e9a799c3a53d64754ae2c23d09b68ae..b357f48decdebed0613a030b5b9d1efe70c2ef72 100644 (file)
@@ -107,7 +107,7 @@ class SLTime(DateTimeMixin, sqltypes.Time):
             return tup and datetime.time(*tup[3:7])
         return process
         
-class SLText(sqltypes.TEXT):
+class SLText(sqltypes.Text):
     def get_col_spec(self):
         return "TEXT"
 
@@ -152,7 +152,7 @@ colspecs = {
     sqltypes.String : SLString,
     sqltypes.Binary : SLBinary,
     sqltypes.Boolean : SLBoolean,
-    sqltypes.TEXT : SLText,
+    sqltypes.Text : SLText,
     sqltypes.CHAR: SLChar,
 }
 
index 2209594ed7c3b498710bd912a54d225349241453..c170a9723ce7019561a39089d82f6f82e60b1db4 100644 (file)
@@ -295,7 +295,7 @@ class SybaseTime_pyodbc(sqltypes.Time):
             return datetime.datetime(1970, 1, 1, value.hour, value.minute, value.second, value.microsecond)
         return process
 
-class SybaseText(sqltypes.TEXT):
+class SybaseText(sqltypes.Text):
     def get_col_spec(self):
         return "TEXT"            
 
@@ -425,7 +425,7 @@ class SybaseSQLDialect(default.DefaultDialect):
         sqltypes.String : SybaseString,
         sqltypes.Binary : SybaseBinary,
         sqltypes.Boolean : SybaseBoolean,
-        sqltypes.TEXT : SybaseText,
+        sqltypes.Text : SybaseText,
         sqltypes.CHAR : SybaseChar,
         sqltypes.TIMESTAMP : SybaseTimeStamp,
         sqltypes.FLOAT : SybaseFloat,
index 35a12efe393071af82dd72c531046baf283ba923..70343a7b4ddf22da49e8ee1922d55bd72be50ab6 100644 (file)
@@ -286,7 +286,7 @@ class DefaultCompiler(engine.Compiled):
         return index.name
 
     def visit_typeclause(self, typeclause, **kwargs):
-        return typeclause.type.dialect_impl(self.dialect).get_col_spec()
+        return typeclause.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
 
     def visit_textclause(self, textclause, **kwargs):
         if textclause.typemap is not None:
index 8ad537e74becb7fe0da82ea66cdc18325da04fcf..b3b04b678ce0dfac1cc84f6c8d706fba7816662e 100644 (file)
@@ -1729,27 +1729,12 @@ class _BindParamClause(ClauseElement, _CompareMixin):
         self.shortname = shortname
 
         if type_ is None:
-            self.type = self.type_map.get(type(value), sqltypes.NullType)()
+            self.type = sqltypes.type_map.get(type(value), sqltypes.NullType)()
         elif isinstance(type_, type):
             self.type = type_()
         else:
             self.type = type_
 
-    # TODO: move to types module, obviously
-    # using VARCHAR/NCHAR so that we dont get the genericized "String"
-    # type which usually resolves to TEXT/CLOB
-    type_map = {
-        str : sqltypes.VARCHAR,
-        unicode : sqltypes.NCHAR,
-        int : sqltypes.Integer,
-        float : sqltypes.Numeric,
-        datetime.date : sqltypes.Date,
-        datetime.datetime : sqltypes.DateTime,
-        datetime.time : sqltypes.Time,
-        datetime.timedelta : sqltypes.Interval,
-        type(None):sqltypes.NullType
-    }
-
     def _clone(self):
         c = ClauseElement._clone(self)
         if self.unique:
index 5ab9ad45095c37c5f6a868fcd128f0a8a9a5a70c..22a89ccc2cf0c9ebae0aef462242b1907493217e 100644 (file)
@@ -12,12 +12,13 @@ For more information see the SQLAlchemy documentation on types.
 
 """
 __all__ = [ 'TypeEngine', 'TypeDecorator', 'AbstractType',
-            'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'TEXT', 'FLOAT',
+            'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'TEXT', 'Text', 'FLOAT',
             'NUMERIC', 'DECIMAL', 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB',
             'BOOLEAN', 'SMALLINT', 'DATE', 'TIME',
             'String', 'Integer', 'SmallInteger','Smallinteger',
             'Numeric', 'Float', 'DateTime', 'Date', 'Time', 'Binary',
             'Boolean', 'Unicode', 'PickleType', 'Interval',
+            'type_map'
             ]
 
 import inspect
@@ -25,7 +26,7 @@ import datetime as dt
 import warnings
 
 from sqlalchemy import exceptions
-from sqlalchemy.util import pickle, Decimal as _python_Decimal
+from sqlalchemy.util import pickle, Decimal as _python_Decimal, warn_deprecated
 NoneType = type(None)
 
 class _UserTypeAdapter(type):
@@ -155,7 +156,7 @@ class AbstractType(object):
                       for k in inspect.getargspec(self.__init__)[0][1:]]))
 
 class TypeEngine(AbstractType):
-    def dialect_impl(self, dialect):
+    def dialect_impl(self, dialect, **kwargs):
         try:
             return self._impl_dict[dialect]
         except AttributeError:
@@ -196,7 +197,7 @@ class TypeDecorator(AbstractType):
             raise exceptions.AssertionError("TypeDecorator implementations require a class-level variable 'impl' which refers to the class of type being decorated")
         self.impl = self.__class__.impl(*args, **kwargs)
 
-    def dialect_impl(self, dialect):
+    def dialect_impl(self, dialect, **kwargs):
         try:
             return self._impl_dict[dialect]
         except AttributeError:
@@ -340,6 +341,15 @@ class Concatenable(object):
             return op
 
 class String(Concatenable, TypeEngine):
+    """A sized string type.
+    
+    Usually corresponds to VARCHAR.  Can also take Python unicode objects
+    and encode to the database's encoding in bind params (and the reverse for 
+    result sets.)
+    
+    a String with no length will adapt itself automatically to a Text 
+    object at the dialect level (this behavior is deprecated in 0.4).
+    """
     def __init__(self, length=None, convert_unicode=False, assert_unicode=None):
         self.length = length
         self.convert_unicode = convert_unicode
@@ -380,13 +390,19 @@ class String(Concatenable, TypeEngine):
         else:
             return None
 
+    def dialect_impl(self, dialect, **kwargs):
+        _for_ddl = kwargs.pop('_for_ddl', False)
+        if self.length is None:
+            warn_deprecated("Using String type with no length for CREATE TABLE is deprecated; use the Text type explicitly")
+        return TypeEngine.dialect_impl(self, dialect, **kwargs)
+        
     def get_search_list(self):
         l = super(String, self).get_search_list()
         # if we are String or Unicode with no length,
-        # return TEXT as the highest-priority type
+        # return Text as the highest-priority type
         # to be adapted by the dialect
         if self.length is None and l[0] in (String, Unicode):
-            return (TEXT,) + l
+            return (Text,) + l
         else:
             return l
 
@@ -394,6 +410,8 @@ class String(Concatenable, TypeEngine):
         return dbapi.STRING
 
 class Unicode(String):
+    """A synonym for String(length, convert_unicode=True, assert_unicode='warn')."""
+    
     def __init__(self, length=None, **kwargs):
         kwargs['convert_unicode'] = True
         kwargs['assert_unicode'] = 'warn'
@@ -413,6 +431,8 @@ class SmallInteger(Integer):
 Smallinteger = SmallInteger
 
 class Numeric(TypeEngine):
+    """Numeric datatype, usually resolves to DECIMAL or NUMERIC."""
+    
     def __init__(self, precision=10, length=2, asdecimal=True):
         self.precision = precision
         self.length = length
@@ -634,7 +654,8 @@ class Interval(TypeDecorator):
             return process
 
 class FLOAT(Float): pass
-class TEXT(String): pass
+class Text(String): pass
+TEXT = Text
 class NUMERIC(Numeric): pass
 class DECIMAL(Numeric): pass
 class INT(Integer): pass
@@ -644,7 +665,7 @@ class TIMESTAMP(DateTime): pass
 class DATETIME(DateTime): pass
 class DATE(Date): pass
 class TIME(Time): pass
-class CLOB(TEXT): pass
+class CLOB(Text): pass
 class VARCHAR(String): pass
 class CHAR(String): pass
 class NCHAR(Unicode): pass
@@ -652,3 +673,18 @@ class BLOB(Binary): pass
 class BOOLEAN(Boolean): pass
 
 NULLTYPE = NullType()
+
+# using VARCHAR/NCHAR so that we dont get the genericized "String"
+# type which usually resolves to TEXT/CLOB
+type_map = {
+    str : VARCHAR,
+    unicode : NCHAR,
+    int : Integer,
+    float : Numeric,
+    dt.date : Date,
+    dt.datetime : DateTime,
+    dt.time : Time,
+    dt.timedelta : Interval,
+    type(None): NullType
+}
+