I can't seem to get past 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 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/'
[...] # Random other lines
DBControl.execute('''INSERT INTO '''+Table+''' (providername, providerlink)
VALUES (?, ?) WHERE NOT EXISTS (
SELECT * FROM '''+Table+'''
WHERE '''+Table+'''.providerlink = ?
);
352) ''', (Name, URL, URL))
For reference, the SQL commands wrapped up in the 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 entry in question by checking if the freshly retrieved link (which is unique) to the table, then writing to the table if it isn't already there.
Playing with whitespace shows that the exception comes up for the last URL on line 352.
I've already tried modifying the input to another string to see if that works, changing the code to use Python's string ops (horror!), and having a drink. Nothing seems to work so far.