mirror of
https://devops.liangqichi.top/qichi.liang/Orbitin.git
synced 2026-02-10 07:41:29 +08:00
fix: 数据库insert方法使用INSERT OR REPLACE更新已存在记录
This commit is contained in:
@@ -108,23 +108,12 @@ class DailyLogsDatabase:
|
|||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def insert(self, log: Dict) -> bool:
|
def insert(self, log: Dict) -> bool:
|
||||||
"""插入记录(存在则跳过,不存在则插入)"""
|
"""插入记录(存在则替换,不存在则插入)"""
|
||||||
try:
|
try:
|
||||||
cursor = self.conn.cursor()
|
cursor = self.conn.cursor()
|
||||||
# 检查是否已存在
|
# 使用 INSERT OR REPLACE 来更新已存在的记录
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT id FROM daily_handover_logs
|
INSERT OR REPLACE INTO daily_handover_logs
|
||||||
WHERE date = ? AND shift = ? AND ship_name = ?
|
|
||||||
''', (log['date'], log['shift'], log['ship_name']))
|
|
||||||
existing = cursor.fetchone()
|
|
||||||
|
|
||||||
if existing:
|
|
||||||
# 记录已存在,跳过
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
# 插入新记录
|
|
||||||
cursor.execute('''
|
|
||||||
INSERT INTO daily_handover_logs
|
|
||||||
(date, shift, ship_name, teu, efficiency, vehicles, created_at)
|
(date, shift, ship_name, teu, efficiency, vehicles, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||||
''', (
|
''', (
|
||||||
|
|||||||
Reference in New Issue
Block a user