-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSql.py
83 lines (72 loc) · 2.04 KB
/
Sql.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
import os.path
import json
import pymysql
def connect():
conn = pymysql.connect(
host='gis.test.cn',
user='gis',
passwd='SiPXnZmNDWkcaSJk',
db='gis',
port=3306,
charset="utf8")
return conn
def insertData(data, keyword):
con = connect()
sql = f"INSERT INTO data (mid, user, verified,verifiedType, verifiedReason, createTime, content, keyword) VALUES ({data[0]}, '{data[1]}', {data[2]}, {data[3]}, '{data[4]}', '{data[5]}', '{data[6]}','{keyword}')"
cursor = con.cursor()
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
con.commit()
except:
# Rollback in case there is any error
con.rollback()
con.close()
print(cursor.rowcount, "record inserted.")
def insertPic(mid, picPath):
con = connect()
cursor = con.cursor()
sql = f"INSERT INTO pic (mid, path) VALUES ({mid}, '{picPath}')"
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
con.commit()
except:
# Rollback in case there is any error
con.rollback()
con.close()
print(cursor.rowcount, "record inserted.")
def insertVideo(mid, vidPath):
con = connect()
cursor = con.cursor()
sql = f"INSERT INTO video (mid, path) VALUES ({mid}, '{vidPath}')"
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
con.commit()
except:
# Rollback in case there is any error
con.rollback()
con.close()
print(cursor.rowcount, "record inserted.")
def verifMid(mid):
con = connect()
sql = f"SELECT * FROM data WHERE mid={mid}"
cursor = con.cursor()
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
results = cursor.fetchall()
con.close()
if results != ():
return True
else:
return False
except:
# Rollback in case there is any error
con.close()
return False