samedi 17 octobre 2015

sqlite3 - Error when inserting into db - (near '?' mark)

I'm trying to create a statement INSERT using placeholders in SQLite3. The problem is that it returns unclear `sqlite3.OperationalError: near "?": syntax error

Here is a method which uses a statement:

def insert_product(self, object):

    self.conn.execute('INSERT or REPLACE INTO products(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', (
    object.name, object.url, object.shops[0].name, object.shops[0].cena, object.shops[0].doprava,
    object.shops[0].stav,
    object.shops[1].name, object.shops[1].cena, object.shops[1].doprava, object.shops[1].stav,
    object.shops[2].name, object.shops[2].cena, object.shops[2].doprava, object.shops[2].stav,
    object.shops[3].name, object.shops[3].cena, object.shops[3].doprava, object.shops[3].stav,
    object.shops[4].name, object.shops[4].cena, object.shops[4].doprava, object.shops[4].stav))
    self.conn.commit()

Here is the error:

    object.shops[4].name, object.shops[4].cena, object.shops[4].doprava, object.shops[4].stav))
sqlite3.OperationalError: near "?": syntax error

Could you give me an advice how to avoid this error? I can't find a place where the problem is.

EDIT: I've renamed object variable to _object in case that there is a problem with built in name but no change happend.

Aucun commentaire:

Enregistrer un commentaire