Cradac
Cradac

Reputation: 35

SQLite Placeholder error in Python script

I am currently working on a discord bot that implements some kind of economy into the server.

While implementing a function to add items to the SQLite Database I ran into this problem:

    cur.execute("INSERT INTO items (?,?,?,?,?,?)", item)
sqlite3.OperationalError: near "?": syntax error

I already switched to "?" as placeholder thanks to this post and found this post but it didn't help me much.

All values are gotten via arguments to the command in discord and are cast to either string or int. I use SQLiteStudio and have the datatypes set to "Text" and "Integer" respectively.

conn = create_connection(db_file)
        with conn:
            cur = conn.cursor()
            item = (itemname, price, info_text, buy_text, use_text, role,)
            market = (itemname, stock,)
            cur.execute("INSERT INTO items (?,?,?,?,?,?)", item)
            cur.execute("INSERT INTO market (?,?)", market)

Upvotes: 1

Views: 508

Answers (1)

Sam Rockett
Sam Rockett

Reputation: 3205

Your SQL queries are invalid. Syntax for INSERT is one of

INSERT INTO table VALUES (...)
INSERT INTO table (columns) VALUES (...)

So you should be able to change your query to

cur.execute("INSERT INTO items VALUES (?,?,?,?,?,?)", item)

and that will fix it. (docs)

Upvotes: 1

Related Questions