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

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

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


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

查看所有标签

猜你喜欢:

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

Flexible Pattern Matching in Strings

Flexible Pattern Matching in Strings

Gonzalo Navarro、Mathieu Raffinot / Cambridge University Press / 2007-7-30 / USD 64.99

String matching problems range from the relatively simple task of searching a single text for a string of characters to searching a database for approximate occurrences of a complex pattern. Recent ye......一起来看看 《Flexible Pattern Matching in Strings》 这本书的介绍吧!

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

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具