Skip to content

Instantly share code, notes, and snippets.

@RaulMedeiros
Created October 22, 2018 13:33
Show Gist options
  • Save RaulMedeiros/7bed1b1eb690d4c2d76d225959387c3f to your computer and use it in GitHub Desktop.
Save RaulMedeiros/7bed1b1eb690d4c2d76d225959387c3f to your computer and use it in GitHub Desktop.
database_python_sample
import psycopg2
def update_DB(host='localhost',dbname='lapisco',user='postgres',
password='senha',projetc_id='35',field='status',
value='5',table='projeto'):
con = None
try:
con = psycopg2.connect("host='"+host+"' dbname='"+dbname+"' user='"+user+"' password='"+password+"'")
cur = con.cursor()
cur.execute("UPDATE "+table+" SET "+field+"="+value+" WHERE id="+projetc_id)
con.commit()
except psycopg2.DatabaseError, e:
if con:
con.rollback()
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()
return True
@RaulMedeiros
Copy link
Author

teste

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment