Created
October 22, 2018 13:33
-
-
Save RaulMedeiros/7bed1b1eb690d4c2d76d225959387c3f to your computer and use it in GitHub Desktop.
database_python_sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
teste