database - python flask cursors.execute() of INSERT and DELETE doesn't work -
i'm new python development , trying update database following function, sadly doesn't work:
def db_update_favourite(user_id, id_layer,favourite): connection = g.db cursor = connection.cursor() cursor.execute(schema) chiave="favourite_layers"; if(favourite): query = ("""insert users_properties (id_user,chiave,index,val_bigint) values(%s,%s,(select max(index)+1 users_properties),%s) """) else: query = ("""delete users_properties id_user=%s , chiave=%s , val_bigint=%s """) print query %(user_id,chiave,id_layer) try: res= cursor.execute(query, (user_id,chiave,id_layer)) except exception e: print e print res print cursor.rowcount return cursor.rowcount>=1
if go , check database see function didn't change database @ all.
if instead, try 2 queries manually psql work expected.
as can see tried debug res none, exception not triggered , rowcount 1.
there other methods perform similar queries , work, can be? other ideas on how further debug it, otherwise?
p.s i'm using pg8000 because server not mine , code existing use library.
use connection.commit()
or g.db.commit()
before close connection.
Comments
Post a Comment