Answer the question
In order to leave comments, you need to log in
How to check in Python if there are values in any column of a SQLite table that are equal to a given variable?
I populate a SQLite database with certain file characteristics and paths to those files. I did not want to repeat myself and tried to figure out how to remove from the database the lines characterizing a file that has a path identical to the path to the new file, information about which is added to the database.
For example, I have a file whose path is C:\file.txt . My code adds information about files to the database, among which there is a file whose path is the same - C:\file.txt . The code has a path variable that characterizes this path. Is it possible to remove the previous information first before adding information about a file with the same location?
Answer the question
In order to leave comments, you need to log in
And what for to delete, then again to fill with the new data.
Use UPDATE in an SQL query to update data.
That is, you can first make a SELECT selection with the WHERE path='path_to_file' condition.
If nothing is returned, then there is no such file in the database yet, and you add a new record via INSERT. If a row from the database for such a file is returned, use UPDATE to update the fields of this row in the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question