1

I have a really frustrating problem

I have a function that accepts a cursor to a sqlite3.Connection object and then modifies the database

my code is something like this:

#DOES NOT WORK
def update(dbc, tableName, value, value2):
    dbc.execute("update ? set MyValue = ? where Something = ?;",\
    [tableName, value, value2])

#WORKS
def update2(dbc, tableName value, value2):
    dbc.execute("update {0} set MyValue = {1} where Something = {2};".format(
    tableName, value, value2))

db = sqlite3.connect('data.db')
c = db.cursor()
c.execute("begin;")
update(c,"Something","Something Else") #FAILS
update2(c,"Something","Something Else") #OK

I get the error:

sqlite3.OperationalError: near "?": syntax error

I have tried commenting out the first execute("begin;") statement because I don't really understand it but I know that it speeds up my code dramatically in other parts instead of having to commit every single input. Does anyone have a clue why this is happening?

3
  • 1
    Ok, I guess it doesn't work for table names, bleh. Solution is here: stackoverflow.com/questions/228912/… Commented Sep 12, 2012 at 6:27
  • 1
    I see you are new here. Welcome. You can answer your own question, don't leave it unanswered. Commented Sep 12, 2012 at 6:29
  • Cant for another 7 hours. Will do it tomorrow I guess. Commented Sep 12, 2012 at 6:40

1 Answer 1

0

Figures that after hours of searching I find the answer in the next 10 minutes. Table names cannot be loaded in this way... Seems silly. Here is a link to the original answer: SQLite parameter substitution problem

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.