From: Mike Bayer Date: Fri, 2 Jul 2010 17:55:24 +0000 (-0400) Subject: - add typing/operator converts to Float/Numeric to get Oracle tests going again, X-Git-Tag: rel_0_6_2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8548ca8cc596228f6d72107ac50efa1cf6f4347a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add typing/operator converts to Float/Numeric to get Oracle tests going again, as we have an unusually high level of dependence on SQLA typing now - force oracle seqs to return integers --- diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 52bf815712..3318cfe49b 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -578,9 +578,9 @@ class OracleIdentifierPreparer(compiler.IdentifierPreparer): class OracleExecutionContext(default.DefaultExecutionContext): def fire_sequence(self, seq): - return self._execute_scalar("SELECT " + + return int(self._execute_scalar("SELECT " + self.dialect.identifier_preparer.format_sequence(seq) + - ".nextval FROM DUAL") + ".nextval FROM DUAL")) class OracleDialect(default.DefaultDialect): name = 'oracle' diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 01ac1a6855..629615ab4e 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -90,7 +90,7 @@ class _OracleNumeric(sqltypes.Numeric): if dialect.supports_native_decimal: if self.asdecimal and self.scale is None: processors.to_decimal_processor_factory(Decimal) - elif not self.asdecimal: + elif not self.asdecimal and self.precision is None and self.scale is None: return processors.to_float else: return None @@ -99,7 +99,7 @@ class _OracleNumeric(sqltypes.Numeric): # floats return super(_OracleNumeric, self).\ result_processor(dialect, coltype) - + class _OracleDate(sqltypes.Date): def bind_processor(self, dialect): return None @@ -469,7 +469,6 @@ class OracleDialect_cx_oracle(OracleDialect): # convert all NUMBER with precision + positive scale to Decimal, # or zero precision and 0 or neg scale, indicates "don't know", # this effectively allows "native decimal" mode. - if defaultType == cx_Oracle.NUMBER \ and ( (precision and scale > 0) or \ diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index d8a176f1fd..91eb352751 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -1022,11 +1022,25 @@ class Numeric(_DateAffinity, TypeEngine): def _expression_adaptations(self): return { operators.mul:{ - Interval:Interval + Interval:Interval, + Numeric:Numeric, + }, + # Py2K + operators.div:{ + Numeric:Numeric, + }, + # end Py2K + operators.truediv:{ + Numeric:Numeric, + }, + operators.add:{ + Numeric:Numeric, }, + operators.sub:{ + Numeric:Numeric, + } } - class Float(Numeric): """A type for ``float`` numbers. @@ -1060,6 +1074,29 @@ class Float(Numeric): else: return None + @util.memoized_property + def _expression_adaptations(self): + return { + operators.mul:{ + Interval:Interval, + Numeric:Float, + }, + # Py2K + operators.div:{ + Numeric:Float, + }, + # end Py2K + operators.truediv:{ + Numeric:Float, + }, + operators.add:{ + Numeric:Float, + }, + operators.sub:{ + Numeric:Float, + } + } + class DateTime(_DateAffinity, TypeEngine): """A type for ``datetime.datetime()`` objects. diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 27459bb3f4..5f2ef1a067 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -1057,7 +1057,8 @@ class SequenceTest(TestBase, AssertsCompiledSQL): seq = Sequence("My_Seq", schema="Some_Schema") assert dialect.identifier_preparer.format_sequence(seq) == '"Some_Schema"."My_Seq"' - + + class ExecuteTest(TestBase): __only_on__ = 'oracle' @@ -1067,7 +1068,17 @@ class ExecuteTest(TestBase): testing.db.execute("/*+ this is a comment */ SELECT 1 FROM DUAL").fetchall(), [(1,)] ) - + + def test_sequences_are_integers(self): + seq = Sequence('foo_seq') + seq.create(testing.db) + try: + val = testing.db.execute(seq) + eq_(val, 1) + assert type(val) is int + finally: + seq.drop(testing.db) + @testing.provide_metadata def test_limit_offset_for_update(self): # oracle can't actually do the ROWNUM thing with FOR UPDATE diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py index 4c30b3bd99..de397f47b1 100644 --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -1710,8 +1710,11 @@ class SubqueryTest(_base.MappedTest): }) session = create_session() - session.add(User(name='joe', tags=[Tag(score1=5.0, score2=3.0), Tag(score1=55.0, score2=1.0)])) - session.add(User(name='bar', tags=[Tag(score1=5.0, score2=4.0), Tag(score1=50.0, score2=1.0), Tag(score1=15.0, score2=2.0)])) + session.add(User(name='joe', tags=[Tag(score1=5.0, score2=3.0), + Tag(score1=55.0, score2=1.0)])) + session.add(User(name='bar', tags=[Tag(score1=5.0, score2=4.0), + Tag(score1=50.0, score2=1.0), + Tag(score1=15.0, score2=2.0)])) session.flush() session.expunge_all()