Web2Py插入数据库错误

时间:2016-05-16 06:44:05

标签: sql database insert web2py

我正在尝试插入。这是我的代码:

db.define_table('orders',
            Field('idProduct', type = 'integer'),
            Field('quantity', type = 'integer'),
            Field('idUser', type = 'integer'),
            Field('status'),
            Field('order_date'),
            Field('product_price', type = 'integer'))

SQL:

sql = "Insert into orders (idProduct,idUser,quantity,status,order_date,product_price) values "
sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," + str(quantity) + ",'cart','" + str(order_date)+ "," + str(product_price)+"')"

我收到了以下错误:

<class 'sqlite3.OperationalError'> 5 values for 6 columns

我不明白出了什么问题,因为如果我删除product_price,一切正常。

感谢。

1 个答案:

答案 0 :(得分:1)

在最后一个结束括号之前你有额外的报价。删除它,它将修复错误:

sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," +
str(quantity) + ",'cart','" + str(order_date)+ "," +
str(product_price)+")"