Unable to insert record into Sqlite from python, Syntax Error

Deano123

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.

Deano123

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting Error in insert record in MySql from Python

From Dev

Sqlite insert gives syntax error

From Dev

Syntax Error in SQLite (Insert Statement)

From Dev

Unable to fetch the record from sqlite table getting ResultSet Closed error

From Dev

Unable to insert new record in SQLite using Emulators

From Dev

SQLITE : near from syntax error:

From Dev

Insert null into Sqlite from Python

From Dev

"Syntax error in INSERT INTO statement" when adding record to Access database

From Dev

Add textbox value to single record: syntax error in INSERT INTO statement

From Dev

Sqlite insert overwriting record

From Dev

Error in select record from sqlite table

From Dev

MySQL Syntax error on Insert Query from PHP

From Dev

mongodb - unable to insert record

From Dev

Unable to insert record in MongoDB

From Dev

Sqlite CTE-insert within trigger gives a syntax error

From Dev

error in sql syntax for python and mysql on insert operation

From Dev

Insert into in python cql throwing syntax error

From Dev

Get error on insert date from code sqlite

From Dev

Unable to insert specific data in database in Sqlite3 Python Django

From Dev

Unable to insert a record in db in PHP

From Dev

Unable to update a record in sqlite database

From Dev

Syntax MySql Insert Error

From Dev

SQL syntax error INSERT INTO

From Dev

syntax error at insert into

From Dev

Syntax MySql Insert Error

From Dev

Error in SQL syntax for INSERT INTO

From Dev

Syntax error in INSERT INTO statement

From Dev

syntax error at insert into

From Dev

PostgreSQL: INSERT INTO syntax error