搜索 Sqlite 数据库 - 所有表和列 [英] Search Sqlite Database - All Tables and Columns

查看:64
本文介绍了搜索 Sqlite 数据库 - 所有表和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有库或开源实用程序可用于搜索 Sqlite 数据库的所有表和列?唯一的输入是 sqlite 数据库文件的名称.

Is there a library or open source utility available to search all the tables and columns of an Sqlite database? The only input would be the name of the sqlite DB file.

我正在尝试编写取证工具,并想在 sqlite 文件中搜索特定字符串.

I am trying to write a forensics tool and want to search sqlite files for a specific string.

推荐答案

您可以使用 "SELECT name FROM sqlite_master WHERE type='table'"找出数据库中表的名称.从那里很容易选择每个表的所有行.

You could use "SELECT name FROM sqlite_master WHERE type='table'" to find out the names of the tables in the database. From there it is easy to SELECT all rows of each table.

例如:

import sqlite3
import os

filename = ...
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]
        cursor.execute("SELECT * FROM {t}".format(t = table))
        for row in cursor:
            for field in row.keys():
                print(table, field, row[field])

这篇关于搜索 Sqlite 数据库 - 所有表和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆