Advertisement
JIST2018

Error Psycopg2-update

Dec 28th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1.     def edit_records(self, nombre, new_nombre, salario, new_salario):
  2.         id=0
  3.         nombre=new_nombre
  4.         salario=new_salario
  5.  
  6.         con = None
  7.         try:
  8.             con = psycopg2.connect("host=localhost dbname=videotk_3 user=postgres password=111")
  9.             cur = con.cursor()
  10.           cur.execute("UPDATE empleado SET empleado_id =(SELECT id FROM empleado WHERE nombre=%s AND salario=%s AND id=%s", [nombre, salario,id])
  11.  
  12.             con.commit()
  13.         except psycopg2.DatabaseError as e:
  14.             if con:
  15.                 con.rollback()
  16.  
  17.             print('Error %s' % e)
  18.             sys.exit(1)
  19.  
  20.         finally:
  21.             if con:
  22.                 con.close()
  23.  
  24.         print(cur.rowcount)
  25.  
  26. if __name__ == '__main__':
  27.     window = root()
  28.     application = Empleado(window)
  29.     window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement