python - Update with prepared statement executing improperly -


so i'm working in python 3.5.2 venv sqlalchemy , mysql. i'm trying update status of order (row) in table. requires changing value of 1 column in row. following shows function i'm working with:

def update_order_status(self, order):     newstatus = self.orderwindow.status.currentindex()     orderid = order.orderid      stmt = update(order)\         .where(order.orderid == orderid).values(status=newstatus)      session.execute(stmt)        session.commit() 

newstatus integer value taken current choice set in dropdown menu presented user. upon session.commit()the following errors

   .....    file "c:\python35\python35-32\lib\site-packages\mysqldb\connections.py", line 292, in query     _mysql.connection.query(self, query) sqlalchemy.exc.operationalerror: (_mysql_exceptions.operationalerror) (1366, "incorrect integer value: 'patient' column 'bill' @ row 1") [sql: 'update `order` set bill=%s, ship=%s, status=%s, flavor=%s `order`.orderid = %s'] [parameters: ('patient', 'pickup', 'received', 7, 100000)]  ...... process finished exit code 1 

the parameters executed not @ shown in prepared statement. should updating row orderid matching 1 provided parameter function , status dropdown.

i've updated packages , tried other methods of updating including setattr(order, "status", newstatus)

i'm unsure of diagnose error.

edit: forgot mention earlier function works flawlessly in python console after copy-pasting database declarations script first.

seems i've answered own question. remembered querying order table earlier in program , changing attributes integers user-friendly strings. when update being called, using changed order object had values contradicting table column types.

i didn't know update function attempts update entire object rather columns provided in .values() field. result i've had revamp handling of orders , instead i'm putting them dictionaries , referencing table again update original order.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -