lib.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:dbas 作者: hhucn 项目源码 文件源码
def update_row(table_name, uids, keys, values, nickname, _tn):
    """
    Updates the data in a specific row of an table

    :param table_name: Name of the table
    :param uids: Array with uids
    :param keys: Array with keys
    :param values: Array with values
    :param nickname: Current nickname of the user
    :param _tn: Translator
    :return: Empty string or error message
    """
    if not is_user_admin(nickname):
        return _tn.get(_.noRights)

    if not table_name.lower() in table_mapper:
        return _tn.get(_.internalKeyError)

    table = table_mapper[table_name.lower()]['table']
    try:
        update_dict, success = __update_row_dict(table, values, keys, _tn)
        if not success:
            return update_dict  # update_dict is a string
    except ProgrammingError as e:
        logger('AdminLib', 'update_row ProgrammingError in __update_row_dict', str(e))
        return 'SQLAlchemy ProgrammingError: ' + str(e)

    try:
        __update_row(table, table_name, uids, update_dict)

    except IntegrityError as e:
        logger('AdminLib', 'update_row IntegrityError', str(e))
        return 'SQLAlchemy IntegrityError: ' + str(e)
    except ProgrammingError as e:
        logger('AdminLib', 'update_row ProgrammingError', str(e))
        return 'SQLAlchemy ProgrammingError: ' + str(e)

    DBDiscussionSession.flush()
    transaction.commit()
    return ''
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号