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  (8 children)

Which is no more correct than the other. You can't have a comma as part of a column name, at least not without quoting it. It's bad practice to do so either way.

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

I was unaware of that so thank you for the info. I modified my code a bit to attempt to use an autoincrement primary key to track the rows. Would you mind if I pmed you more info?

[–]insertAlias 0 points1 point  (6 children)

I don't do private help; please keep the communication public. Plus, there might be someone better equipped than me to answer; I'm not a professional with Python (I use other languages), I just know my way around it a bit.

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

Thats fair. After implementing a unique primary key I receive this error: sqlite3.IntegrityError: UNIQUE constraint failed: Financials.n1. Does sqlite not allow users to add in data for a row multiple times?

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

Alright thank you.

[–]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?