Skip to content

Instantly share code, notes, and snippets.

@opencoca
Last active February 12, 2022 21:43
Show Gist options
  • Save opencoca/e3e80f2a236b0778db9f5012f984ed78 to your computer and use it in GitHub Desktop.
Save opencoca/e3e80f2a236b0778db9f5012f984ed78 to your computer and use it in GitHub Desktop.
Python Sqlite search for string
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