database.py 文件源码

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

项目:oclubs 作者: SHSIDers 项目源码 文件源码
def insert_row(table, insert):
    """
    Execute an ``INSERT`` on a table.

    :param basestring table: table name
    :param dict insert: inserted data, with keys as the column name and
        values as the corresponding values
    :returns: the id of the inserted row
    :rtype: int or long
    :raises AlreadyExists: if the row already exists and insertion would
        result in duplicate keys
    """
    try:
        keys = _encode_name(insert.keys())
        values = ','.join([_encode(value) for value in insert.values()])

        return _execute("INSERT INTO %s (%s) VALUES (%s);"
                        % (_encode_name(table), keys, values),
                        write=True, ret='lastrowid')
    except MySQLdb.IntegrityError as e:
        if e[0] == 1062:
            raise AlreadyExists
        raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号