-
Notifications
You must be signed in to change notification settings - Fork 0
/
Connection.py
74 lines (60 loc) · 2.29 KB
/
Connection.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
import pymysql
class SqlSetting():
def __init__(self):
self.dbconfing = {}
def MySQLConnection(self):
"""
Host = host
UserName = user
Password = password
Databases = db
"""
MySQLlib = MySQL()
self.setinit("autocommit", True)
self.setinit("charset", "utf8")
self.setinit("use_unicode", True)
MySQLlib.connection(self.dbconfing)
return MySQLlib
def setinit(self, Key, Value):
self.dbconfing[Key] = Value
def removeinit(self, Key):
self.dbconfing.pop(Key)
def gettinit(self, Key):
return self.dbconfing[Key]
class MySQL(SqlSetting):
def connection(self, dbconfing):
self.con = pymysql.connect(
**dbconfing).cursor(pymysql.cursors.DictCursor)
def execute(self, SQL, values=None):
if values:
self.con.execute(SQL, values)
else:
self.con.execute(SQL)
return self.con.fetchall()
def updateTable(self):
self.execute("""ALTER TABLE commands ADD comment VARCHAR(255);""")
def initTable(self):
self.execute("""CREATE TABLE IF NOT EXISTS commands(
ID VARCHAR(255),
datetime DATETIME,
comment VARCHAR(255),
command VARCHAR(255),
target VARCHAR(255),
targets TEXT,
value VARCHAR(255),
projectID VARCHAR(255),
projectVersion VARCHAR(255),
projectName VARCHAR(255),
projectURL VARCHAR(255),
testID VARCHAR(255),
testName VARCHAR(255),
timecost VARCHAR(20)
);""")
self.execute("""SET NAMES UTF8;""")
def insertResult(self, command):
sqlinsert = ("INSERT INTO commands(ID ,datetime , comment,command ,target ,targets ,value ,projectID ,projectVersion ,projectName ,projectURL ,testID ,testName ,timecost)" +
"VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)")
if command:
# print (sqlinsert)
# print (command)
self.execute(sqlinsert, command)