Last active
February 12, 2022 21:43
-
-
Save opencoca/e3e80f2a236b0778db9f5012f984ed78 to your computer and use it in GitHub Desktop.
Python Sqlite search for string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import os | |
filename = "simple.db" | |
search = "search" | |
with sqlite3.connect(filename) as conn: | |
conn.row_factory = sqlite3.Row | |
cursor = conn.cursor() | |
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'") | |
for tablerow in cursor.fetchall(): | |
table = tablerow[0] | |
if "sorl" in table: | |
continue | |
#print("SELECT * FROM {t}".format(t = table)) | |
cursor.execute("SELECT * FROM {t}".format(t = table)) | |
for row in cursor: | |
for field in row.keys(): | |
if type(row[field]) is unicode: | |
if search in row[field]: | |
print(row[field], field, table) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment