I can not miss the following error:
Traceback (most recent call last):
File "datascraper.py", line 352, in <module>
URL))
sqlite3.OperationalError: near "WHERE": syntax error
It comes from the following code (line 352 is marked):
Table = someSQLtable //Has columns (providername, [other columns], providerlink)
SQLDatabase = sqlite3.connect(someSQLDatabase.db)
DBControl = cursor(SQLDatabase)
Name = 'somestring'
URL = 'http://www.someurl.com/stuff/'
[...]
DBControl.execute('''INSERT INTO '''+Table+''' (providername, providerlink)
VALUES (?, ?) WHERE NOT EXISTS (
SELECT * FROM '''+Table+'''
WHERE '''+Table+'''.providerlink = ?
);
352) ''', (Name, URL, URL))
For reference, SQL commands completed in Python should look like this:
INSERT INTO someSQLtable (providername, providerlink)
VALUES ('somestring', 'http://www.someurl.com/stuff/')
WHERE NOT EXISTS (
SELECT * FROM someSQLtable
WHERE someSQLtable.providerlink = 'http://www.someurl.com/stuff/')
And my goal is to check if the table already contains the specified record, checking if the link just received (which is unique) was in the table, and then it is written to the table if it does not already exist.
Playing with spaces indicates that an exception appears for the last URL on line 352.
I have already tried modifying the input on another line to see if this works by changing the code to use Python string operations (horror!) And having a drink. Nothing is working yet.