def execute(self, query, args=None): "wrapper around the base class execute method" try: return DictCursor.execute(self, query, args) except MySQLdb.OperationalError: logger.exception("One OperationalError exception in MySQL call") try: return DictCursor.execute(self, query, args) except MySQLdb.OperationalError: logger.exception("Two OperationalError exceptions in MySQL call, giving up") raise
def execute(query, *args): logger.writeln('execute', query, '%', args) connection = connections.get_con() cursor = DictCursor(connection) cursor.execute(query, args) results = tuple(_results_gen(cursor)) cursor.close() connections.release_con(connection) if len(results) == 1: return results[0] else: return results
def callproc(name, *args): logger.writeln('callproc', name, '%', args) connection = connections.get_con() cursor = DictCursor(connection) cursor.callproc(name, args) results = tuple(_results_gen(cursor)) cursor.close() connections.release_con(connection) if len(results) == 1: return results[0] else: return results
def run_dict_get_query(connection, query): cursor = DictCursor(connection) try: cursor.execute(query) for row in cursor: yield row except Error as e: print("An Error occurred") traceback.print_exc()
def execute(self, query, args=None): query = query.replace('?', '%s').strip() for pattern, sub in QCursor.replace: query = re.sub(pattern, sub, query) if False: cherrypy.engine.log('Query: "%s" %s' % (query, args)) return DictCursor.execute(self, query, args)
TEMPLATE = """ :date: {blog_date} :tags: {tags} :category: blog :slug: {slug} :author: Ken Cochrane :title: {title} {content} """ db = connect(host="127.0.0.1", user="******", passwd="", db="blog") dict_curr = DictCursor(db) dict_curr.execute("select * from blog_entries") results = dict_curr.fetchall() for result in results: slug = result.get("slug", None) title = result.get("title", None) orig_tags = result.get("tags", "") blog_date = result.get("pub_date") content = result.get("body") format = result.get("format", "REST") if format == "REST": ext = "rst" else: ext = "html"
def close(self): DictCursor.close(self)
def __del__(self): DictCursor.__del__(self)
import twik.db as db import config_db_con from MySQLdb.cursors import DictCursor con = db.connections.get_con() cur = DictCursor(con) cur.callproc('user_data_byemail', ('*****@*****.**',)) r = cur.fetchall() print r cur.close() db.connections.release_con(con)