def test_connection(db, c): try: c.execute("select 1") except _mysql_exceptions.OperationalError as e: # connection went away, retry db = dsn.getConnection() c = db.cursor() return db, c
database) sys.exit(1) if database == 'service': filespec = "//depot/b-serviceschema/db/schema/common/sql/golden/service.sql" else: filespec = "//depot/b-serviceschema/db/schema/common/sql/golden/trio.sql" p4 = P4.P4() conn = None cursor = None try: schemadiff.log_in_to_p4(p4) conn = dsn.getConnection() cursor = conn.cursor() diff_branches(p4, cursor, filespec, oldbranch, newbranch, database, dmlfile, validate) except P4.P4Exception as p4e: logging.error(p4e) for e in p4.warnings:
#!/usr/bin/python import MySQLdb import quiz_sql import dsn # docs at http://mysql-python.sourceforge.net/MySQLdb.html q = quiz_sql.next_item_query % {'quizkey':'definitions'} db = dsn.getConnection() def get_article(db): article_cursor = db.cursor() article_query = """ select wa.value from word w, word_attribute wa, attribute a where w.id = wa.word_id and wa.attribute_id = a.id and attrkey = 'article' and word_id = %s """ % d['word_id'] article_cursor.execute(article_query) article = None for r1 in article_cursor.fetchall(): article = r1[0] break