SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import psycopg2
  2.  
  3. # Connecting to database.
  4. try:
  5.     connect = psycopg2.connect(database='fn1132_2017', user='student', host='195.19.32.74', password='bmstu')
  6.     cursor = connect.cursor()
  7. except:
  8.     print("Unable connect to database.")
  9.     exit(100)
  10.  
  11. program_run = True
  12. query = ""
  13.  
  14. while program_run:
  15.     print("Please enter your command or EXIT to leave program:")
  16.  
  17.     query = input()
  18.     if query == "EXIT":
  19.         program_run = False
  20.     else:
  21.         try:
  22.             cursor.execute(query)
  23.             connect.commit()
  24.         except:
  25.             print("Bad query.")
  26.         finally:
  27.             if "select" in query.lower():
  28.                 try:
  29.                     for row in cursor:
  30.                         print(row)
  31.                 except:
  32.                     print("No data to print.")
  33.  
  34. connect.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top