简体   繁体   English

无法将记录从python插入Sqlite中,语法错误

[英]Unable to insert record into Sqlite from python, Syntax Error

I have been writing some code and for some reason it has stopped working. 我一直在写一些代码,由于某种原因它已停止工作。 I was inserting a record into a table and it has been working fine. 我正在将记录插入表中,并且工作正常。 I changed some other code that is unrelated to this section but now the code no longer works and give me a syntax error. 我更改了与本节无关的其他代码,但是现在该代码不再起作用,并给我带来语法错误。

As a test I tried to take the value of the variables and tried to insert them into the database but I get the same problem. 作为测试,我尝试获取变量的值并将其插入数据库中,但是遇到了同样的问题。 Here is the code. 这是代码。

self.__cdict.execute("INSERT INTO chunks (id, hash, corrupt) VALUES (?,?,?)", (1, "424947758cc4c256a016fa1d0c237c8303bcf77b65180ad3134ae4b997a82f9e", 0))
OperationalError: near "None": syntax error

Any ideas what I am doing wrong? 有什么想法我做错了吗? The statement has not changed and did work so I am at a loss. 声明没有改变并且确实起作用,所以我很茫然。

Update: just tried the following in an sqlite editor to see if it worked and there were no problems at all. 更新:只是在sqlite编辑器中尝试了以下操作,以查看它是否有效,并且完全没有问题。

INSERT INTO chunks (id, hash, corrupt) VALUES (1, "424947758cc4c256a016fa1d0c237c8303bcf77b65180ad3134ae4b997a82f9e", 0)

I'm using Python 2.7, with sqlite3 我正在使用带sqlite3的Python 2.7

Table definition: 表定义:

-- Describe CHUNKS
CREATE TABLE "chunks" (
"id" INTEGER NOT NULL,
"hash" BLOB NOT NULL,
"offset" INTEGER,
"tableid" INTEGER,
"enchash" TEXT,
"corrupt" INTEGER)

Code that stopped working 停止工作的代码

self.__cdict_cur.execute("INSERT INTO chunks (id, hash, corrupt) VALUES (?,?,?)", (self.__chunkID, chunkhash, 0))

Test code I tried to isolate the problem, the values are the ones that i printed out before the error occured. 我试图找出问题的测试代码,这些值是我在错误发生之前打印出的值。

INSERT INTO chunks (id, hash, corrupt) VALUES (1, "424947758cc4c256a016fa1d0c237c8303bcf77b65180ad3134ae4b997a82f9e", 0)

Neither works and I can't work out why. 都不起作用,我也不知道为什么。

Im Really sorry I found the reason for the error. 林真的很抱歉,我找到了错误的原因。 I had quotes around one of the statements when I opened the Database. 打开数据库时,其中一条语句的引号引起了我的注意。

self.__cdict.isolation_level = "None"

Instead of 代替

self.__cdict.isolation_level = None

Before I made the change I had the mode set to 在进行更改之前,我已将模式设置为

self.__cdict.isolation_level = "Exclusive"

So I assumed I needed quotes around the None too. 所以我认为我也需要在None周围加上引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM