-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataHandler.py
More file actions
52 lines (47 loc) · 1.89 KB
/
dataHandler.py
File metadata and controls
52 lines (47 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sqlite3
class DataHandler :
@staticmethod
def addRecord(userId, userName, month, day):
conn = sqlite3.connect("ClockInRecord.db")
cursor = conn.cursor()
#查找是否已经存在当天记录
cursor.execute("SELECT * FROM clock_in WHERE user_id = ? AND month = ? AND day = ?", (userId, month, day))
result = cursor.fetchone()
if result:
# 如果存在,更新记录
cursor.execute("UPDATE clock_in SET count = count + 1 WHERE user_id = ? AND month = ? AND day = ?", (userId, month, day))
else:
# 如果不存在,插入新记录
cursor.execute("INSERT INTO clock_in (user_id, user_name, month, day, count) VALUES (?, ?, ?, ?, ?)", (userId, userName, month, day, 1))
conn.commit()
conn.close()
@staticmethod
def getCount(userId, month, day):
conn = sqlite3.connect("ClockInRecord.db")
cursor = conn.cursor()
cursor.execute("SELECT count FROM clock_in WHERE user_id = ? AND month = ? AND day = ?", (userId, month, day))
result = cursor.fetchone()
conn.close()
if result is None:
return 0
return result
@staticmethod
def findMessageId(messageId):
conn = sqlite3.connect("ClockInRecord.db")
cursor = conn.cursor()
cursor.execute("select * from message where message_id = ?", (messageId,))
result = cursor.fetchone()
conn.close()
if result is not None:
return True
return False
@staticmethod
def addMessageId(messageId):
if DataHandler.findMessageId(messageId):
return;
conn = sqlite3.connect("ClockInRecord.db")
cursor = conn.cursor()
cursor.execute("insert into message (message_id) values (?)", (messageId,))
conn.commit()
cursor.fetchone()
conn.close()