Mysqlconnector部分注意自己mark

mysql connector 步骤
以下是项目部分代码:

if table.db_id.driver == 'mys':
                con = mysql.connector.connect(
                    host=table.db_id.host,
                    user=table.db_id.user,
                    password=table.db_id.password,
                    database=table.db_id.dbname)
                cursor = con.cursor()
                ```
              

如果表是innodb 需要提交 ,如果是MYISAM则是自动提交,不用commit

for col in rec_data:
                        for product_item in product:
                            if product_item.default_code == col[1]:
                                cursor.execute("UPDATE fin_opg_item_info SET avg_price=%s WHERE item_no='%s'"%(product_item.standard_price,col[1]))
                                cursor.execute("UPDATE fin_opg_item_info SET inv_amount=avg_price*qty")
                                con.commit()
                con.close()

你可能感兴趣的:(odoo,数据库)