1

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.

3
  • You probably should add more info, i.e. modules versions, table definition, complete non-working code, full traceback etc. As stated now, I can't see any reason for SyntaxError. Commented Nov 24, 2013 at 8:51
  • Please see Last update, I found the reason for the problem Commented Nov 24, 2013 at 10:09
  • 3
    You can self-answer your question; add the solution as an answer below. Don't put the answer in the question, however. Commented Nov 24, 2013 at 11:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.