2

I'm doing something like this in my code:

import sqlite3
...
sqlString=company['name']+","+simplejson.dumps(info)
cur.execute("INSERT INTO companyInfo VALUES("+sqlString+")")

but I'm getting the following error: cur.execute("INSERT INTO companyBlobs VALUES("+valueString+")") sqlite3.OperationalError: unrecognized token: "{"

I guess this is a problem with the escaping of the JSON data, but not sure how to fix it. Ideas?

leonsas
  • 4,718
  • 6
  • 43
  • 70
  • I know what you're saying, but I'm doing a very large number of queries to an API and I need to have everything as JSON before processing the data, so I'm just temporarily storing the JSON in sqlite. – leonsas Jan 14 '13 at 19:01

1 Answers1

5

try to use parametrized query:

sqlString=company['name']+","+simplejson.dumps(info)
cur.execute("INSERT INTO companyInfo VALUES (?)", (sqlString, ))

this will automatically escape your inputs.

MBarsi
  • 2,417
  • 1
  • 18
  • 18