]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- REAL has been added to the core types. Supported
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 5 Apr 2011 16:40:55 +0000 (12:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 5 Apr 2011 16:40:55 +0000 (12:40 -0400)
by Postgresql, SQL Server, MySQL, SQLite.  Note
that the SQL Server and MySQL versions, which
add extra arguments, are also still available
from those dialects.  [ticket:2081]

13 files changed:
CHANGES
doc/build/core/types.rst
lib/sqlalchemy/__init__.py
lib/sqlalchemy/dialects/drizzle/base.py
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/sqlite/__init__.py
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/types.py
test/dialect/test_postgresql.py
test/sql/test_types.py

diff --git a/CHANGES b/CHANGES
index dc7dba7ada9bf72a3cd692a38e37a53eb3c3ce9b..c92ddcf08a2480c21185574ebba2ad31cdc05838 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -57,6 +57,13 @@ CHANGES
     these elements are only applied when the Table
     is newly created.   [ticket:2109]
 
+- types
+  - REAL has been added to the core types.  Supported
+    by Postgresql, SQL Server, MySQL, SQLite.  Note
+    that the SQL Server and MySQL versions, which 
+    add extra arguments, are also still available
+    from those dialects.  [ticket:2081]
+
 -event
   - Added @event.listens_for() decorator, given
     target + event name, applies the decorated 
index 74a04a8c09148cf6da39b62edab53920dd75a6e5..04b9b37b54322b52640be83e08f8864718f0294e 100644 (file)
@@ -163,6 +163,9 @@ on all databases.
 .. autoclass:: NUMERIC
   :show-inheritance:
 
+.. autoclass:: REAL
+  :show-inheritance:
+
 .. autoclass:: SMALLINT
   :show-inheritance:
 
index 0cab28da1efbd09c81ecb7da13c1665e7d9a4304..a20554dc0da93fbba3a3796e3dc908cffa9fe00f 100644 (file)
@@ -75,6 +75,7 @@ from sqlalchemy.types import (
     NUMERIC,
     Numeric,
     PickleType,
+    REAL,
     SMALLINT,
     SmallInteger,
     String,
index bec0562a95cd59b56d5e4b0e1bce84304daf2052..ca2678e58c091df617a1514c57f33b8b8593736d 100644 (file)
@@ -218,7 +218,7 @@ class DOUBLE(_FloatType):
         super(DOUBLE, self).__init__(precision=precision, scale=scale,
                                      asdecimal=asdecimal, **kw)
 
-class REAL(_FloatType):
+class REAL(_FloatType, sqltypes.REAL):
     """Drizzle REAL type."""
 
     __visit_name__ = 'REAL'
index 16d9217853ad29fbceff20b280e422ed06ae8a85..7ff017d834fdd3d46eee0262b5a5d60201cce597 100644 (file)
@@ -217,13 +217,12 @@ RESERVED_WORDS = set(
     ])
 
 
-class REAL(sqltypes.Float):
-    """A type for ``real`` numbers."""
-
+class REAL(sqltypes.REAL):
     __visit_name__ = 'REAL'
 
     def __init__(self, **kw):
-        kw.setdefault('precision', 24)
+        # REAL is a synonym for FLOAT(24) on SQL server
+        kw['precision'] = 24
         super(REAL, self).__init__(**kw)
 
 class TINYINT(sqltypes.Integer):
@@ -548,9 +547,6 @@ class MSTypeCompiler(compiler.GenericTypeCompiler):
         else:
             return "FLOAT(%(precision)s)" % {'precision': precision}
 
-    def visit_REAL(self, type_):
-        return "REAL"
-
     def visit_TINYINT(self, type_):
         return "TINYINT"
 
index 21e0312f5a468e3f5207cbf53464153209fea2bd..33dc8a73e4890e0833159c2829d7afc64e1f091e 100644 (file)
@@ -354,7 +354,7 @@ class DOUBLE(_FloatType):
         super(DOUBLE, self).__init__(precision=precision, scale=scale,
                                      asdecimal=asdecimal, **kw)
 
-class REAL(_FloatType):
+class REAL(_FloatType, sqltypes.REAL):
     """MySQL REAL type."""
 
     __visit_name__ = 'REAL'
index cc2f461f98517fadf0eabb4b38a783be81379fe0..7fdd74628fda8733335d8bb6e28c972b354476a3 100644 (file)
@@ -99,7 +99,7 @@ except ImportError:
 
 from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \
         CHAR, TEXT, FLOAT, NUMERIC, \
-        DATE, BOOLEAN
+        DATE, BOOLEAN, REAL
 
 RESERVED_WORDS = set(
     ["all", "analyse", "analyze", "and", "any", "array", "as", "asc",
@@ -123,9 +123,6 @@ _DECIMAL_TYPES = (1231, 1700)
 _FLOAT_TYPES = (700, 701, 1021, 1022)
 _INT_TYPES = (20, 21, 23, 26, 1005, 1007, 1016)
 
-class REAL(sqltypes.Float):
-    __visit_name__ = "REAL"
-
 class BYTEA(sqltypes.LargeBinary):
     __visit_name__ = 'BYTEA'
 
@@ -669,9 +666,6 @@ class PGTypeCompiler(compiler.GenericTypeCompiler):
     def visit_BYTEA(self, type_):
         return "BYTEA"
 
-    def visit_REAL(self, type_):
-        return "REAL"
-
     def visit_ARRAY(self, type_):
         return self.process(type_.item_type) + '[]'
 
index 9d39bd8251e06d85eade89bf0d549b53c52c7bfa..d939d51cd819b7b1a1700e4635a85fbe70a5f02b 100644 (file)
@@ -11,10 +11,10 @@ base.dialect = pysqlite.dialect
 
 
 from sqlalchemy.dialects.sqlite.base import \
-    BLOB, BOOLEAN, CHAR, DATE, DATETIME, DECIMAL, FLOAT, INTEGER,\
+    BLOB, BOOLEAN, CHAR, DATE, DATETIME, DECIMAL, FLOAT, INTEGER, REAL,\
     NUMERIC, SMALLINT, TEXT, TIME, TIMESTAMP, VARCHAR, dialect
 
 __all__ = (
     'BLOB', 'BOOLEAN', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'FLOAT', 'INTEGER',
-    'NUMERIC', 'SMALLINT', 'TEXT', 'TIME', 'TIMESTAMP', 'VARCHAR', 'dialect'
+    'NUMERIC', 'SMALLINT', 'TEXT', 'TIME', 'TIMESTAMP', 'VARCHAR', 'dialect', 'REAL'
 )
\ No newline at end of file
index 36357597cc0e6fd78db4943d94cdbba880b6265b..43d8d708ba9dfdc1e73b2bca6dbe0d93ba1c4dd1 100644 (file)
@@ -63,8 +63,7 @@ from sqlalchemy.sql import compiler
 from sqlalchemy import processors
 
 from sqlalchemy.types import BLOB, BOOLEAN, CHAR, DATE, DATETIME, DECIMAL,\
-                            FLOAT, INTEGER, NUMERIC, SMALLINT, TEXT, TIME,\
-                            TIMESTAMP, VARCHAR
+    FLOAT, REAL, INTEGER, NUMERIC, SMALLINT, TEXT, TIME, TIMESTAMP, VARCHAR
 
 class _DateTimeMixin(object):
     _reg = None
@@ -272,7 +271,7 @@ ischema_names = {
     'INT': sqltypes.INTEGER,
     'INTEGER': sqltypes.INTEGER,
     'NUMERIC': sqltypes.NUMERIC,
-    'REAL': sqltypes.Numeric,
+    'REAL': sqltypes.REAL,
     'SMALLINT': sqltypes.SMALLINT,
     'TEXT': sqltypes.TEXT,
     'TIME': sqltypes.TIME,
index 76303c10c6bb888ef22ba7e4ba20d853d2aa479f..7c409e0e637ba2db8fe7e2ffe2e9b6bd683d6f62 100644 (file)
@@ -1479,6 +1479,9 @@ class GenericTypeCompiler(engine.TypeCompiler):
     def visit_FLOAT(self, type_):
         return "FLOAT"
 
+    def visit_REAL(self, type_):
+        return "REAL"
+
     def visit_NUMERIC(self, type_):
         if type_.precision is None:
             return "NUMERIC"
@@ -1565,6 +1568,9 @@ class GenericTypeCompiler(engine.TypeCompiler):
     def visit_integer(self, type_): 
         return self.visit_INTEGER(type_)
 
+    def visit_real(self, type_):
+        return self.visit_REAL(type_)
+
     def visit_float(self, type_):
         return self.visit_FLOAT(type_)
 
index b52f7644c171bbeb624687d9bc368538f78f03ee..e8d0b6f22f7f84154370385104dbc29fb63f4ddc 100644 (file)
@@ -13,8 +13,8 @@ For more information see the SQLAlchemy documentation on types.
 """
 __all__ = [ 'TypeEngine', 'TypeDecorator', 'AbstractType', 'UserDefinedType',
             'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'NVARCHAR','TEXT', 'Text',
-            'FLOAT', 'NUMERIC', 'DECIMAL', 'TIMESTAMP', 'DATETIME', 'CLOB',
-            'BLOB', 'BOOLEAN', 'SMALLINT', 'INTEGER', 'DATE', 'TIME',
+            'FLOAT', 'NUMERIC', 'REAL', 'DECIMAL', 'TIMESTAMP', 'DATETIME', 
+            'CLOB', 'BLOB', 'BOOLEAN', 'SMALLINT', 'INTEGER', 'DATE', 'TIME',
             'String', 'Integer', 'SmallInteger', 'BigInteger', 'Numeric',
             'Float', 'DateTime', 'Date', 'Time', 'LargeBinary', 'Binary',
             'Boolean', 'Unicode', 'MutableType', 'Concatenable',
@@ -1995,6 +1995,11 @@ class Interval(_DateAffinity, TypeDecorator):
         return self.impl._coerce_compared_value(op, value)
 
 
+class REAL(Float):
+    """The SQL REAL type."""
+
+    __visit_name__ = 'REAL'
+
 class FLOAT(Float):
     """The SQL FLOAT type."""
 
index bbf4765604bf5e6d413792121763db0ea4319e8c..1f8a87bc099ee66a946c66897ce285120d7f808c 100644 (file)
@@ -287,7 +287,7 @@ class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults):
         metadata = self.metadata
         t1 = Table('t', metadata, 
             Column('x', postgresql.ARRAY(Float)),
-            Column('y', postgresql.ARRAY(postgresql.REAL)),
+            Column('y', postgresql.ARRAY(REAL)),
             Column('z', postgresql.ARRAY(postgresql.DOUBLE_PRECISION)),
             Column('q', postgresql.ARRAY(Numeric))
         )
index d154aada7c551d08d897ea535e3df75f1db1083b..7865a5296d75f3b36876b56b1a39bdfcd9887bee 100644 (file)
@@ -55,6 +55,7 @@ class AdaptTest(fixtures.TestBase):
 
         for dialect in self._all_dialects():
             for type_, expected in (
+                (REAL, "REAL"),
                 (FLOAT, "FLOAT"),
                 (NUMERIC, "NUMERIC"),
                 (DECIMAL, "DECIMAL"),
@@ -120,7 +121,13 @@ class AdaptTest(fixtures.TestBase):
                 for k in t1.__dict__:
                     if k == 'impl':
                         continue
-                    eq_(getattr(t2, k), t1.__dict__[k])
+                    # assert each value was copied, or that
+                    # the adapted type has a more specific
+                    # value than the original (i.e. SQL Server
+                    # applies precision=24 for REAL)
+                    assert \
+                        getattr(t2, k) == t1.__dict__[k] or \
+                        t1.__dict__[k] is None
 
     def test_plain_init_deprecation_warning(self):
         for typ in (Integer, Date, SmallInteger):