Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLAlchemy (no ORM): update statement not committing
    text
    copied!<p>I have this (anonymized) function in my database module:</p> <pre><code>def fix_publishing_dates(row_id, last_time=None, next_time=None, next_index=1, user="python_script"): sql = """ UPDATE schema.table SET last_time = :last_time , next_time = :next_time , next_index = :next_index , col4 = SYSDATE , col5 = :user_id , is_active = 1 WHERE id = :row_id """ with closing(Session()) as s: with s.begin_nested(): user_id = get_userid_by_name(user) args = dict( last_time=last_time, next_time=next_time, next_index=next_index, row_id=row_id, user_id=user_id, ) s.execute(sql, args) s.flush() s.commit() </code></pre> <p>For some reason, this is not working. I query the above table for is_active=1, and I get zero rows. Am I doing something obviously wrong here?</p> <h3>Note</h3> <p>I don't want to use SQLAlchemy ORM and add lots of boilerplate Table classes* for this; I just like using Session() with text queries for the transaction support.</p> <p>*: nor slow down my startup time with introspection; the network pipe to this database is slow.</p> <h3>Edit 1</h3> <ul> <li>I'm using an Oracle 11 database through cx_oracle.</li> <li>In case it matters, one of the bound values is sometimes None/</li> <li><p>This code (anonymized differently) also isn't working:</p> <pre><code>def fix_publishing_dates(**kwargs): sql = insert_query_here user_id = get_userid_by_name(user) args = dict(kwargs) print "*" * 50 print "* About to update database with values: {}".format(args) print "*" * 50 result = engine.execute(sql, args) print "Row count is:", result.rowcount #import ipdb;ipdb.set_trace() #s.commit() </code></pre></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload