SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 74 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.         except:
  24.             print("Bad query.")
  25.         finally:
  26.             if "select" in query.lower():
  27.                 for row in cursor:
  28.                     print(row)
  29.  
  30. 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