sqlite3 在Python中使用

SQLite是一种关系型数据库管理系统,使用SQL语言进行数据操作。Python内置了一个SQLite模块,可以轻松地在Python中使用SQLite数据库。

python 复制代码
"""
文件型数据库: 就是一个文件,不需要在电脑安装数据库软件
python3 内置了sqlite3  可以管理sqlite数据库
"""

import sqlite3
con = sqlite3.connect("python2407.abc")
cur = con.cursor()

# cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
# print(cur.fetchall())

# cur.execute("""
# CREATE TABLE users (
#     id INTEGER PRIMARY KEY AUTOINCREMENT,
#     username TEXT NOT NULL UNIQUE,
#     password TEXT NOT NULL
# );
# """)

# cur.execute("PRAGMA table_info(users);")
# print(cur.fetchall())

# cur.executemany("INSERT INTO users (username, password) VALUES (?, ?);", [
#     ('user3', 'password'),
#     ('user4', 'password'),
#     ('user5', 'password'),
#     ('user6', 'password'),
#     ('user7', 'password'),
# ])
#
# con.commit()

cur.execute("SELECT * FROM users;")
print(cur.fetchall())


cur.close()
con.close()
相关推荐
用户0332126663671 小时前
使用 Python 从零创建 Word 文档
python
Csvn5 小时前
Python 两大经典坑点 —— 可变默认参数 & 闭包延迟绑定
后端·python
曲幽6 小时前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
用户556918817538 小时前
#从脚本到独立程序:Python + Playwright 批量抓取的完整踩坑记录
python·自动化运维
兵慌码乱1 天前
基于 MediaPipe 与 PySide2 的手势交互音乐控制系统实现:轻量化视觉交互全流程解析
python·opencv·计算机视觉·人机交互·手势识别·mediapipe·pyside2
luckdewei1 天前
FastAPI 资产管理系统实战:复杂 ORM 关联、Alembic 迁移与 N+1 查询优化
python
aqi001 天前
15天学会AI应用开发(八)使用向量数据库实现RAG功能
人工智能·python·大模型·ai编程·ai应用
Csvn1 天前
`functools.lru_cache` —— 一行代码搞定缓存加速
后端·python
金銀銅鐵2 天前
[Python] 从《千字文》中随机挑选汉字
后端·python