Deano123
Deano123

Reputation: 161

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.

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

I'm using Python 2.7, with sqlite3

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.

Upvotes: 1

Views: 311

Answers (1)

Deano123
Deano123

Reputation: 161

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.

Upvotes: 1

Related Questions