コード例 #1
0
def query(_db, _sql, _args,pool_info = None):
    conn = get_pool_connection(_db,pool_info)
    cursor = conn.cursor(dictionary=True)
    result = ()
    try:
        cursor.execute(_sql, _args)
        result = cursor.fetchall()
    except:
        pass
        rootLogger.error("query exception sql is %s ,_args is %s,stacks is %s", _sql, _args, get_caller_info_total())
        rootLogger.exception("message")
    finally:
        cursor.close()
        conn.close()
    return result
コード例 #2
0
def check_record_exsit(_db, _sql, _args):
    result = 0
    conn = get_pool_connection(_db)
    cursor = conn.cursor(buffered=True)
    #conn.autocommit(True) #replace False -> True
    try:
        cursor.execute(_sql, _args)         #conn.commit()
        result = cursor.rowcount
    except:
        pass
        rootLogger.error("message")
        conn.rollback()
    finally:
        print("the record is has rows = {}".format(cursor.rowcount))
        cursor.close()
        conn.close()
    return result
コード例 #3
0
def insertOrUpdate(_db, _sql, _args):
    result = 0
    conn = get_pool_connection(_db)
    cursor = conn.cursor(buffered=True)
    try:
        cursor.execute(_sql, _args)
        conn.commit()
        result = cursor.rowcount
    except:
        pass
        rootLogger.error("exception sql is %s ,_args is %s", _sql, _args)
        rootLogger.exception("message")
        conn.rollback()
    finally:
        print("affected rows = {}".format(cursor.rowcount))
        cursor.close()
        conn.close()
    return result
コード例 #4
0
def query(_db_config, _sql, _args):
    conn = get_pool_connection(_db_config)
    if not isinstance(conn, PooledMySQLConnection):
        cursor = conn.cursor(MySQLdb.cursors.DictCursor)
    else:
        cursor = conn.cursor(dictionary=True)
    result = ()
    try:
        cursor.execute(_sql, _args)
        result = cursor.fetchall()
    except:
        pass
        rootLogger.error("query exception sql is %s ,_args is %s,stacks is %s",
                         _sql, _args, get_caller_info_total())
        rootLogger.exception("message")
    finally:
        cursor.close()
        conn.close()
    return result
コード例 #5
0
def emptyTable(_db, _sql, _args):
    result = 0
    conn = get_pool_connection(_db)
    cursor = conn.cursor(buffered=True)
    #conn.autocommit(True) #replace False -> True
    try:
        cursor.execute(_sql, _args)
        conn.commit()
        result = cursor.rowcount
    except:
        pass
        rootLogger.error(" emptyTable exception sql is %s ,_args is %s", _sql, _args)
        rootLogger.exception("message")
        conn.rollback()
    finally:
        print("affected rows = {}".format(cursor.rowcount))
        cursor.close()
        conn.close()
    return result
コード例 #6
0
ファイル: mysql_util.py プロジェクト: wumin1/PyMysqlPool.mod
def check_record_exsit(_db_config, _sql, _args):
    result = 0
    conn = get_pool_connection(_db_config)
    if not isinstance(conn, PooledMySQLConnection):
        cursor = conn.cursor(MySQLdb.cursors.DictCursor)
    else:
        cursor = conn.cursor(buffered=True)
    try:
        cursor.execute(_sql, _args)  # conn.commit()
        result = cursor.rowcount
    except:
        pass
        rootLogger.error("message")
        conn.rollback()
    finally:
        print("the record is has rows = {}".format(cursor.rowcount))
        cursor.close()
        conn.close()
    return result
コード例 #7
0
def insertOrUpdate(_db_config, _sql, _args):
    result = 0
    conn = get_pool_connection(_db_config)
    if not isinstance(conn, PooledMySQLConnection):
        cursor = conn.cursor(MySQLdb.cursors.DictCursor)
    else:
        cursor = conn.cursor(buffered=True)
    try:
        cursor.execute(_sql, _args)
        conn.commit()
        result = cursor.rowcount
    except:
        pass
        rootLogger.error("exception sql is %s ,_args is %s", _sql, _args)
        rootLogger.exception("message")
        conn.rollback()
    finally:
        print("affected rows = {}".format(cursor.rowcount))
        cursor.close()
        conn.close()
    return result