如何通过python使用sqlite3获取表名? [英] How to get table names using sqlite3 through python?

查看:78
本文介绍了如何通过python使用sqlite3获取表名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 sqlite3 数据库获取数据时遇到问题.我找不到表的名称及其编码.当我通过 sqlitebrowser 打开数据库时,名称只是不可读的字符.与数据库的连接正常.

I have a problem to get data from the sqlite3 database. I can't find out the names of tables and their encoding. When I open DB through sqlitebrowser names were just unreadable characters. Connection to DB is fine.

conn = sqlite3.connect('my.db')
conn_cursor = conn.cursor()
conn.text_factory = str

但是我怎样才能得到表的名称和它们的编码呢?

But how can I get the names of tables and their encoding?

推荐答案

您可以使用此查询来获取表名称.

You can use this query to get tables names.

res = conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
for name in res.fetchall():
    print(name[0])

这篇关于如何通过python使用sqlite3获取表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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