1

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)
1
  • The INSERT statement is INSERT INTO table (col1, col2, ...) VALUES (val1, val2, ...), .... The column list is optional if you're inserting values for every column. Commented May 11, 2018 at 22:06

1 Answer 1

1

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)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.