[Sqlalchemy-commits] sqlalchemy: - more oracle tweaks for returning; the method here ...
Brought to you by:
zzzeek
From: <co...@sq...> - 2012-08-25 19:42:02
|
details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/eb07b51cb7f0 changeset: 8597:eb07b51cb7f0 user: Mike Bayer <mi...@zz...> date: Sat Aug 25 19:41:14 2012 +0000 description: - more oracle tweaks for returning; the method here is still kind of brittle and might have issues with pks, multiple function calls Subject: sqlalchemy: - merge details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/82c3f7c5ceb1 changeset: 8598:82c3f7c5ceb1 user: Mike Bayer <mi...@zz...> date: Sat Aug 25 19:41:43 2012 +0000 description: - merge diffstat: lib/sqlalchemy/dialects/oracle/cx_oracle.py | 11 ++++++----- lib/sqlalchemy/sql/compiler.py | 4 +++- test/dialect/test_oracle.py | 25 ++++++++++++++++++++++--- test/sql/test_returning.py | 4 ++-- 4 files changed, 33 insertions(+), 11 deletions(-) diffs (99 lines): diff -r 7f624dea540e -r 82c3f7c5ceb1 lib/sqlalchemy/dialects/oracle/cx_oracle.py --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sat Aug 25 13:30:58 2012 -0400 +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sat Aug 25 19:41:43 2012 +0000 @@ -350,11 +350,12 @@ if not hasattr(self, 'out_parameters'): self.out_parameters = {} if dbtype is None: - raise exc.InvalidRequestError("Cannot create out parameter for parameter " - "%r - it's type %r is not supported by" - " cx_oracle" % - (name, bindparam.type) - ) + raise exc.InvalidRequestError( + "Cannot create out parameter for parameter " + "%r - it's type %r is not supported by" + " cx_oracle" % + (bindparam.name, bindparam.type) + ) name = self.compiled.bind_names[bindparam] self.out_parameters[name] = self.cursor.var(dbtype) self.parameters[0][quoted_bind_names.get(name, name)] = \ diff -r 7f624dea540e -r 82c3f7c5ceb1 lib/sqlalchemy/sql/compiler.py --- a/lib/sqlalchemy/sql/compiler.py Sat Aug 25 13:30:58 2012 -0400 +++ b/lib/sqlalchemy/sql/compiler.py Sat Aug 25 19:41:43 2012 +0000 @@ -958,7 +958,9 @@ else: add_to_result_map = None - if isinstance(column, sql.Label): + if not within_columns_clause: + result_expr = col_expr + elif isinstance(column, sql.Label): if col_expr is not column: result_expr = _CompileLabel( col_expr, diff -r 7f624dea540e -r 82c3f7c5ceb1 test/dialect/test_oracle.py --- a/test/dialect/test_oracle.py Sat Aug 25 13:30:58 2012 -0400 +++ b/test/dialect/test_oracle.py Sat Aug 25 19:41:43 2012 +0000 @@ -453,6 +453,23 @@ "t1.c2, t1.c3 INTO :ret_0, :ret_1" ) + def test_returning_insert_functional(self): + t1 = table('t1', column('c1'), column('c2', String()), column('c3', String())) + fn = func.lower(t1.c.c2, type_=String()) + stmt = t1.insert().values(c1=1).returning(fn, t1.c.c3) + compiled = stmt.compile(dialect=oracle.dialect()) + eq_( + compiled.result_map, + {'c3': ('c3', (t1.c.c3, 'c3', 'c3'), t1.c.c3.type), + 'lower': ('lower', (), fn.type)} + + ) + self.assert_compile( + stmt, + "INSERT INTO t1 (c1) VALUES (:c1) RETURNING " + "lower(t1.c2), t1.c3 INTO :ret_0, :ret_1" + ) + def test_returning_insert_labeled(self): t1 = table('t1', column('c1'), column('c2'), column('c3')) self.assert_compile( @@ -1312,13 +1329,15 @@ meta.drop_all() def test_fetch(self): - result = binary_table.select().execute().fetchall() + result = binary_table.select().order_by(binary_table.c.id).\ + execute().fetchall() eq_(result, [(i, stream) for i in range(1, 11)]) @testing.fails_on('+zxjdbc', 'FIXME: zxjdbc should support this') def test_fetch_single_arraysize(self): - eng = testing_engine(options={'arraysize':1}) - result = eng.execute(binary_table.select()).fetchall() + eng = testing_engine(options={'arraysize': 1}) + result = eng.execute(binary_table.select(). + order_by(binary_table.c.id)).fetchall() eq_(result, [(i, stream) for i in range(1, 11)]) class UnsupportedIndexReflectTest(fixtures.TestBase): diff -r 7f624dea540e -r 82c3f7c5ceb1 test/sql/test_returning.py --- a/test/sql/test_returning.py Sat Aug 25 13:30:58 2012 -0400 +++ b/test/sql/test_returning.py Sat Aug 25 19:41:43 2012 +0000 @@ -71,12 +71,12 @@ result = table.insert().values(goofy="someOTHERgoofy").\ returning(func.lower(table.c.goofy, type_=GoofyType)).execute() row = result.first() - assert row[0] == "foosomeothergoofyBAR" + eq_(row[0], "foosomeothergoofyBAR") result = table.insert().values(persons=12).\ returning(table.c.persons + 18).execute() row = result.first() - assert row[0] == 30 + eq_(row[0], 30) @testing.exclude('firebird', '<', (2, 1), '2.1+ feature') @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature') |