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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

Effective Java: Second Edition

Effective Java: Second Edition

Joshua Bloch / Addison-Wesley / 2008-05-28 / USD 54.99

Written for the working Java developer, Joshua Bloch's Effective Java Programming Language Guide provides a truly useful set of over 50 best practices and tips for writing better Java code. With plent......一起来看看 《Effective Java: Second Edition》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换