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 定义给定初值或长度的list方法

python 定义给定初值或长度的list方法

1. 给定初值v,和长度l,定义list s 或者: 2. 产生一个数值递增list 2.1 从0开始以1递增 2.2 在[a,b)区间上以1递增 2.3 在[a,b)区间上以c...

python解析中国天气网的天气数据

使用方法:terminal中输入复制代码 代码如下:python weather.py http://www.weather.com.cn/weather/101010100.shtml...

python读文件逐行处理的示例代码分享

复制代码 代码如下:import os ## for os.path.isfile() def dealline(line) :    print(line...

Python常见加密模块用法分析【MD5,sha,crypt模块】

本文实例讲述了Python常见加密模块用法。分享给大家供大家参考,具体如下: 1. md5模块 md5.new([arg])     返回一个md...

python实现的udp协议Server和Client代码实例

直接上代码:Server端:复制代码 代码如下: #!/usr/bin/env python # UDP Echo Server -  udpserver....