import sqlite3
def foundValueInTable(v,tname,con):
sqlstr = "select * from "+ tname + ";"
cur = con.cursor()
cur.execute(sqlstr)
rows = cur.fetchall()
bfound=False
for row in rows:
for colval in row:
if((colval)==v):
bfound=True
print(row)
break
if(bfound==True):
print("\nFound in TableName: "+tname+"\n\n")
cur.close()
def foundValueInTable_fuzzy(varg,tname,con):
v=str(varg).lower()
sqlstr = "select * from "+ tname + ";"
cur = con.cursor()
cur.execute(sqlstr)
rows = cur.fetchall()
bfound=False
for row in rows:
for colval in row:
colvalstr = str(colval).lower()
if(v in colvalstr):
bfound=True
print(row)
break
if(bfound==True):
print("\nFound in TableName: "+tname+"\n\n")
cur.close()
def foundValueInTables(v,dbname,fuzzy=False):
con = sqlite3.connect(dbname)
cur = con.cursor()
cur.execute("select name,type,tbl_name from sqlite_master where type='table'")
rows = cur.fetchall()
tableNames=[row[0] for row in rows]
cur.close()
if fuzzy:
for name in tableNames:
foundValueInTable_fuzzy(v, name,con)
else:
for name in tableNames:
foundValueInTable(v, name,con)
con.close()
if __name__ == '__main__':
foundValueInTables('Category','d:/n1.db',True)
print('found in tables end')