prices.py 文件源码

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

项目:Enibar 作者: ENIB 项目源码 文件源码
def add_descriptor(name, category, quantity):
    """ Add price descriptor

    :param str name: Price name
    :param int category: category id
    :param int quantity: The quantity (in mL) of the product
    :return int: Return price id created or None
    """
    with Database() as database:
        database.transaction()
        cursor = QtSql.QSqlQuery(database)
        cursor.prepare("INSERT INTO price_description(label, category, quantity) \
            VALUES(:label, :category, :quantity)")
        cursor.bindValue(":label", name)
        cursor.bindValue(":category", category)
        cursor.bindValue(":quantity", quantity)
        if cursor.exec_():
            desc_id = cursor.lastInsertId()
            cursor.prepare("SELECT id FROM products WHERE category=:category")
            cursor.bindValue(":category", category)
            if cursor.exec_():
                while cursor.next():
                    pcurser = QtSql.QSqlQuery(database)
                    pcurser.prepare("INSERT INTO prices(price_description, \
                            product, value) VALUES(:desc, :product, :value)")
                    pcurser.bindValue(":desc", desc_id)
                    pcurser.bindValue(":product", cursor.value('id'))
                    pcurser.bindValue(":value", 0.00)
                    pcurser.exec_()
            database.commit()
            return desc_id

        # Something went wrong
        database.rollback()
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号