python – sqlite3.Warning:一次只能执行一个语句

栏目: Python · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/15513854/sqlite3-warning-you-can-only-execute-one-statement-at-a-time

运行此代码时出现错误:

import sqlite3

user_name = raw_input("Please enter the name: ")
user_email = raw_input("Please enter the email: ")

db = sqlite3.connect("customer")
cursor=db.cursor()

sql = """INSERT INTO customer
        (name, email) VALUES (?,?);, 
        (user_name, user_email)"""

cursor.execute(sql)

为什么会这样?

虽然其他海报对于您的语句格式是正确的,但您收到此特定错误,因为您尝试在一个查询中执行多个语句(请注意查询中的;分隔语句).

从Python sqlite3文档:

“execute() will only execute a single SQL statement. If you try to execute more than one  statement with it, it will raise a Warning. Use executescript() if you want to execute  multiple SQL statements with one call.”

https://docs.python.org/2/library/sqlite3.html

现在,即使您使用了executioncript(),您的语句也无法正确执行,因为格式化方式存在其他问题(请参阅其他已发布的答案).但是您收到的错误特别是因为您的多个陈述.我正在为搜索该错误后可能在这里闲逛的其他人发布此答案.

翻译自:https://stackoverflow.com/questions/15513854/sqlite3-warning-you-can-only-execute-one-statement-at-a-time


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Lean Startup

The Lean Startup

Eric Ries / Crown Business / 2011-9-13 / USD 26.00

更多中文介绍:http://huing.com Most startups fail. But many of those failures are preventable. The Lean Startup is a new approach being adopted across the globe, chan ging the way companies are built and ......一起来看看 《The Lean Startup》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具