一、環境準備
1、python3中自帶了sqlite3
參考https://www.runoob.com/sqlite/sqlite-tutorial.html
2、在sqlite中建表
CREATE TABLE [stock]
(
[id] NVARCHAR(48),
[name] NVARCHAR(24),
[code] NVARCHAR(24),
[date] INTEGER NOT NULL,
[open] REAL ,
[close] REAL ,
[high] REAL ,
[low] REAL ,
[volume] REAL ,
[extend_num] REAL ,
[extend1] NVARCHAR(30),
[extend2] NVARCHAR(30),
[extend3] NVARCHAR(30),
CONSTRAINT [PK_stock] PRIMARY KEY ([id])
);
DELETE from stock ;
CREATE UNIQUE INDEX stock_code_date_I ON stock(code, date);```
二、構造語句
1、查詢
```bash
def select():
db_path = r'D:\Users\Administrator\PycharmProjects\Stocks\tushareTest\stock\data_sqlite\finance.db'
conn = sqlite3.connect(db_path)
cur = conn.cursor()
cur.execute('select * from stock')
print(cur```