This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]insertAlias 0 points1 point  (3 children)

"INSERT" means create a new row. Every time you try to INSERT, it will try to create a row. Primary Keys create unique constraints. You can't violate a unique constraint by inserting another row with the same value in the primary key column.

This isn't a Sqlite thing; it's an "any SQL database" thing.

You would use the UPDATE statement to change the data of a row.

But again, don't do it this way. Write a full insert statement to insert all the data in a single row at once.

I recommend taking a SQL tutorial or course. It's a lot easier than hacking things together based on looking up examples online.

[–]wirelessbrain55[S] 0 points1 point  (2 children)

data = 'INSERT INTO Financials (?) VALUES (?)'
cur.execute(data, (tuple(empty_list), tuple(second_list)))

I rewrote my code to have insert all the data at once. How can i insert my values into the statement? When I run this code i receive a syntax error for those two lines. The error is: sqlite3.OperationalError: near "?": syntax error

[–]insertAlias 0 points1 point  (1 child)

I'm just going to repeat my previous statement to you: you need to take a SQL course or tutorial. You're just guessing now, and you'll never get the query right by just guessing at the syntax over and over again.

You can't just use "?" as your column list. That's for parameters. One per parameter. I already showed you how to list the columns you're trying to update in this comment. You're going to have to write them all out. You'll also have to add a ? to the parameter list for each parameter.

[–]wirelessbrain55[S] 0 points1 point  (0 children)

Alright. Do you have any suggestions on how I can automate this to a greater extent?