zamotivator

Untitled

May 30th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. def execqs(conn, query_sequence, description):
  2. try:
  3. print(conn)
  4. print(conn.cursor)
  5. c = conn.сursor()
  6. print (c)
  7. logger.info("begin %s", description)
  8. for query in query_sequence:
  9. logger.debug("%s => executing %s" % (description, query))
  10. cursor.execqs(query)
  11. if logger.isEnabledFor(logging.DEBUG):
  12. for line_number, record in enumerate(cursor):
  13. logger.debug("\t%s\t%s", line_number, record)
  14. logger.info("commit %s" % description)
  15. conn.commit()
  16. cursor.close()
  17. except BaseException as e:
  18. logger.error(e)
  19. logger.info("rollback %s" % description)
  20. conn.rollback()
  21. raise
  22.  
  23. def drop_database(conn):
  24. print(conn)
  25. execqs(conn, ["drop database if exists amtt"], "drop database")
  26.  
  27. import psycopg2
  28. conn = psycopg2.connect(database="postgres")
  29. drop_database(conn)
Advertisement
Add Comment
Please, Sign In to add comment