# -*- coding: utf-8 -*-
# @Time : 2023/7/21 15:22
# @Author : Cocktail_py
import os
import sys
import sqlite3
APP_ROOT = getattr(sys, '__APP_ROOT__', os.path.split(os.path.realpath(__file__))[0])
APP_PATH = getattr(sys, '__APP_PATH__', os.path.join(APP_ROOT, 'packages'))
APP_PATH and sys.path.insert(0, APP_PATH)
db_path = APP_ROOT + '/' + "data"
if not os.path.exists(db_path):
os.makedirs(db_path)
def dict_factory(cursor,row):
"""以字典形式返回值"""
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
conn = sqlite3.connect(db_path+"/"+"eth_gas_price.db")
# 以字典形式返回查询数据
conn.row_factory = dict_factory
cursor = conn.cursor()
# 不存在创建相应数据库
db_sql = """CREATE TABLE IF NOT EXISTS gas_price (
id integer primary key autoincrement,
coin_name varchar(15) not null UNIQUE,
low integer,
avg integer,
high integer,
c_time integer
);"""
cursor.execute(db_sql)
cursor.execute("select * from gas_price limit 10;")
# cursor.fetchall()
conn.commit()
cursor.close()
conn.close()
# 参考:https://blog.youkuaiyun.com/qq_39147299/article/details/121953056
sqlite基本操作
最新推荐文章于 2025-06-07 12:42:21 发布

356

被折叠的 条评论
为什么被折叠?



