-
Notifications
You must be signed in to change notification settings - Fork 5
/
insert.py
100 lines (52 loc) · 1.9 KB
/
insert.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pymysql
# 插入操作(任务输入)
def insert_A (message,id ):
conn = pymysql.connect ( host='localhost', user='root', password='qwe1234..', db='user', port=3306, charset='utf8' )
cur = conn.cursor ( )
sql_insert = "insert into users values ('%s', '%d')"%(message,id)
cur.execute ( sql_insert )
conn.commit ( )
cur.close ( )
conn.close ( )
# 带信息查重的插入操作(任务输入)
def insert_B ( messgae, id):
conn = pymysql.connect ( host='localhost', user='root', password='qwe1234..', db='user', port=3306, charset='utf8' )
cur = conn.cursor ( )
sql_insert = "insert into users values ('%s', %d)" % (message,id)
sql_query = "select count(*) from users where id = '%s'" % (id)
cur.execute ( sql_query )
conn.commit ( )
data = cur.fetchone ( )
if data [ 0 ] == 1:
print ( "信息已存在, 不可重复插入" )
else:
cur.execute ( sql_insert )
conn.commit ( )
cur.close ( )
conn.close ( )
#天数签到为1,未签到为0
# 插入操作(签到输入)
def insert_c (day_count,id ):
conn = pymysql.connect ( host='localhost', user='root', password='qwe1234..', db='user', port=3306, charset='utf8' )
cur = conn.cursor ( )
sql_insert = "insert into days values ('%d', '%d')"%(day_count,id)
cur.execute ( sql_insert )
conn.commit ( )
cur.close ( )
conn.close ( )
# 带信息查重的插入操作(签到输入)
def insert_D ( day_count, id):
conn = pymysql.connect ( host='localhost', user='root', password='qwe1234..', db='user', port=3306, charset='utf8' )
cur = conn.cursor ( )
sql_insert = "insert into days values ('%d', %d)" % (message,id)
sql_query = "select count(*) from days where id = '%d'" % (id)
cur.execute ( sql_query )
conn.commit ( )
data = cur.fetchone ( )
if data [ 0 ] == 1:
print ( "信息已存在, 不可重复插入" )
else:
cur.execute ( sql_insert )
conn.commit ( )
cur.close ( )
conn.close ( )