python - Flask sqlalchemy update limit -


i try execute update query limit in flask, using flask-sqlalchemy (not sqlalchemy!).

db.session.query(itemobject).filter_by(owner_type=0,item_id=item_id.decode('hex')).update({'owner_type': '1'}) 

when try ".limit(1)" or "update({'owner_type': '1'}, mysql_limit=1)" geting error

attributeerror: 'long' object has no attribute 'limit' 

or

typeerror: update() got unexpected keyword argument 'mysql_limit' 

how can make query without using execute()?

for first error, sounds you're trying call limit() after calling update().

db.session.query(itemobject).filter_by(owner_type=0,item_id=item_id.decode('hex')).update({'owner_type': '1'}) 

this line returns long because update() returns number of rows matched (not modified!). can't chain limit after update.

you also can't call limit on query update, wouldn't work anyways. that's mysql thing.

take @ previous answer - https://stackoverflow.com/a/25943713/175320 - shows how same end result in portable manner using subqueries.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -