Python_查看sqlite3表结构,查询语句的示例代码

yipeiwu_com6年前Python基础

如下所示:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import sqlite3
 
conn = sqlite3.connect('test.db')
# 创建一个Cursor:
cursor = conn.cursor()
 
# 查询记录:
conn = sqlite3.connect('calendar.db')
cursor = conn.cursor()
# 执行查询语句:
cursor.execute('select * from perpetualCalendar')
# 获得查询结果集:
values = cursor.fetchall()
print(values)
 
# cursor.execute('PRAGMA table_info(perpetualCalendar)')
print (cursor.fetchall())
cursor.close()
conn.close()

查看表结构:cursor.execute('PRAGMA table_info(表名)')

以上这篇Python_查看sqlite3表结构,查询语句的示例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python实现加载及解析properties配置文件的方法

本文实例讲述了Python实现加载及解析properties配置文件的方法。分享给大家供大家参考,具体如下: 这里参考前面一篇:/post/137393.htm 我们都是在java里面遇...

Python的Django框架中使用SQLAlchemy操作数据库的教程

零、SQLAlchemy是什么? SQLAlchemy的官网上写着它的介绍文字: SQLAlchemy is the Python SQL toolkit and Object Rela...

Python实现优先级队列结构的方法详解

最简单的实现 一个队列至少满足2个方法,put和get. 借助最小堆来实现. 这里按"值越大优先级越高"的顺序. #coding=utf-8 from heapq import h...

在Python中用get()方法获取字典键值的教程

 get()方法返回给定键的值。如果键不可用,则返回默认值None。 语法 以下是get()方法的语法: dict.get(key, default=None) 参数...

python 实时遍历日志文件

open 遍历一个大日志文件 使用 readlines() 还是 readline() ? 总体上 readlines() 不慢于python 一次次调用 readline(...