简体   繁体   中英

How do I read in lines from a text file and search through all rows and tables in a database for matching strings?

My project involves using Python to extract forensic data from a Windows image file. I have now written programs that carry out the extraction and saved the data to a SQLite Database for analysis. I have a keyword text file that I would like to read in line by line and search all the tables in my database for the strings but I'm having problems carrying this out. I have managed to read all my rows from all the tables in the database but I don't know how to search for the strings that are in my text file and see if they are in any of the rows. Can someone please advise? Much appreciated

condition = ' OR '.join(["field LIKE ?" for k in keywords])
sql = "SELECT * FROM {t} WHERE {c}".format(c=condition, t=tablename)
args = ['%{k}%'.format(k=k) for k in keywords]
cursor.execute(sql, args)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM