From: Mike Bayer Date: Wed, 2 Jul 2008 18:26:58 +0000 (+0000) Subject: - add SLFloat type, which matches the SQLite REAL X-Git-Tag: rel_0_4_7~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5dc261c352550dfaa99d900bf625e0efdcb469a0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add SLFloat type, which matches the SQLite REAL type affinity. Previously, only SLNumeric was provided which fulfills NUMERIC affinity, but that's not the same as REAL. --- diff --git a/CHANGES b/CHANGES index d985593991..82f8aff413 100644 --- a/CHANGES +++ b/CHANGES @@ -98,6 +98,10 @@ CHANGES [ticket:1090] + - add SLFloat type, which matches the SQLite REAL + type affinity. Previously, only SLNumeric was provided + which fulfills NUMERIC affinity, but that's not the + same as REAL. 0.4.6 ===== diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 040e23a4bd..b4af462211 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -32,6 +32,19 @@ class SLNumeric(sqltypes.Numeric): else: return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length} +class SLFloat(sqltypes.Float): + def bind_processor(self, dialect): + type_ = self.asdecimal and str or float + def process(value): + if value is not None: + return type_(value) + else: + return value + return process + + def get_col_spec(self): + return "FLOAT" + class SLInteger(sqltypes.Integer): def get_col_spec(self): return "INTEGER" @@ -153,7 +166,7 @@ colspecs = { sqltypes.CHAR: SLChar, sqltypes.Date: SLDate, sqltypes.DateTime: SLDateTime, - sqltypes.Float: SLNumeric, + sqltypes.Float: SLFloat, sqltypes.Integer: SLInteger, sqltypes.NCHAR: SLChar, sqltypes.Numeric: SLNumeric, diff --git a/test/sql/testtypes.py b/test/sql/testtypes.py index 09a3702ee7..b71017bd61 100644 --- a/test/sql/testtypes.py +++ b/test/sql/testtypes.py @@ -278,9 +278,12 @@ class ColumnsTest(TestBase, AssertsExecutionResults): } db = testing.db - if testing.against('sqlite', 'oracle'): + if testing.against('oracle'): expectedResults['float_column'] = 'float_column NUMERIC(25, 2)' + if testing.against('sqlite'): + expectedResults['float_column'] = 'float_column FLOAT' + if testing.against('maxdb'): expectedResults['numeric_column'] = ( expectedResults['numeric_column'].replace('NUMERIC', 'FIXED'))