sqlite3.OperationalError: near "WHERE" using NOT IN clause

Viewed 49

I'm creating a port scanner using python. When it finds an ip address I want it added to my "Devices" table. However I need to check to make sure this same IP is not already in my tables from an earlier scan. So I'm trying to run the following SQL in Python:

cursorObj.execute("INSERT INTO Devices VALUES('"+ipAddrFound+"', null, null, null, null) WHERE '"+ipAddrFound+"' NOT IN (Select ipAddr from Devices)")

However, when I run this I get the following error: sqlite3.OperationalError: near "WHERE": syntax error

I'm not understanding what the problem is. Any advice?

Thanks in advance.

1 Answers

Change Values to Select

cursorObj.execute("INSERT INTO Devices SELECT '"+ipAddrFound+"', null, null, null, null WHERE '"+ipAddrFound+"' NOT IN (Select ipAddr from Devices)")
Related