memos_migr.py
· 443 B · Python
Неформатований
import sqlite3
conn_source = sqlite3.connect('db/source.db')
conn_target = sqlite3.connect('db/memos_prod.db')
cur_source = conn_source.cursor()
cur_target = conn_target.cursor()
#? change here
cur_source.execute('SELECT * FROM tag')
rows = cur_source.fetchall()
#? change here
for row in rows:
cur_target.execute('INSERT INTO tag VALUES (?, ?)', row) # 假设表有两列
conn_target.commit()
conn_source.close()
conn_target.close()
1 | import sqlite3 |
2 | |
3 | conn_source = sqlite3.connect('db/source.db') |
4 | conn_target = sqlite3.connect('db/memos_prod.db') |
5 | |
6 | cur_source = conn_source.cursor() |
7 | cur_target = conn_target.cursor() |
8 | |
9 | #? change here |
10 | cur_source.execute('SELECT * FROM tag') |
11 | rows = cur_source.fetchall() |
12 | |
13 | #? change here |
14 | for row in rows: |
15 | cur_target.execute('INSERT INTO tag VALUES (?, ?)', row) # 假设表有两列 |
16 | |
17 | conn_target.commit() |
18 | |
19 | conn_source.close() |
20 | conn_target.close() |