示例#1
0
def insertOrUpdate_getId(_db_config, _sql, _args):
    result = 0
    id = 0
    config = _db_config
    conn = MySQLdb.connect(host=config['host'],
                           port=config['port'],
                           user=config['user'],
                           passwd=config['passwd'],
                           db=config['db'],
                           charset=config['charset'],
                           use_unicode=True)
    #conn = get_pool_connection(_db_config)
    cursor = conn.cursor(MySQLdb.cursors.DictCursor)
    #conn.autocommit(True) #replace False -> True
    try:
        cursor.execute(_sql, _args)
        id = conn.insert_id()
        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, id
示例#2
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
示例#3
0
def query_single(_db, _sql, _args):
    config = db_config[_db]
    conn = MySQLdb.connect(host=config['host'], port=config['port'], user=config['user'], passwd=config['passwd'],
                          db=config['db'], charset=config['charset'], use_unicode=True)
    cursor = conn.cursor(MySQLdb.cursors.DictCursor)
    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
示例#4
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
示例#5
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
示例#6
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
示例#7
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
示例#8
0
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
示例#9
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