I'm practicing how to use SQLite3 and I've having trouble with a particular operation. Could someone please point me in the right direction please?
I'm also sorry in advance if this is a repeated question.
co.execute("INSERT INTO enrolment VALUES" + department_tuple + " WHERE enrolment.student_number =?, (" + student_id + ",)")
The print statement or what SQL will interact of the above code is: INSERT INTO enrolment VALUES('Computer Science') WHERE enrolment.student_number =?, (1299388480,)
When I run the code within my function I get the error: sqlite3.OperationalError: near "WHERE": syntax error
I've searched around for the answer and although there is a solution already but it applies to SQL rather than SQLite and I'm not similar enough with SQL to make anything of it. In particular I'm not sure what provideame, providerlink are or whether they exist is SQLite
The similar solution I found:
The INSERT statement has no WHERE clause.
"If you have a UNIQUE constraint (and if not, you should create one) on the providerLink column, you can simply use INSERT OR IGNORE:
INSERT OR IGNORE INTO someSQLtable(provideame, providerlink)
VALUES ('somestring', 'http://www.someurl.com/stuff/')
Otherwise, you have to replace the VALUES clause with a query:
INSERT INTO someSQLtable(provideame, providerlink) SELECT 'somestring', 'http://www.someurl.com/stuff/' WHERE NOT EXISTS ( SELECT * FROM someSQLtable WHERE providerlink = 'http://www.someurl.com/stuff/')"From C.L sqlite3.OperationalError: near "WHERE": syntax error (Python 2, sqlite3)
