-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconnecter.py
163 lines (131 loc) · 5.21 KB
/
connecter.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/python
# -*- coding: utf-8 -*-
import mysql.connector
import logging
from abc import ABCMeta, abstractmethod
class mysqlConnect:
@classmethod
def __init__(cls, host, user, password, databank):
cls.host = host
cls.user = user
cls.password = password
cls.databank = databank
#logging.info(str(cls))
@classmethod
def exec_sql(cls, sql):
#logging.info(str(cls))
#logging.info(sql)
cls.connect = mysql.connector.connect(host=cls.host, user=cls.user, password=cls.password, database=cls.databank, charset="utf8")
cls.cursor = cls.connect.cursor()
cls.cursor.execute(sql)
cls.connect.close()
@classmethod
def get_submit_by_id(cls, submit_id):
sql = "SELECT * FROM webtesting WHERE id = %s" % ( submit_id )
logging.info(str(cls))
logging.info(sql)
cls.exec_sql(sql)
cls.data = cls.cursor.fetchone()
#data [0]id, [1]url, [2]deep, [3]time
return cls.data[1], cls.data[2], cls.data[3]
@classmethod
def get_all_inputs_by_id(cls, submit_id):
sql = "SELECT * FROM inputtable WHERE id = %s" % ( submit_id )
cls.exec_sql(sql)
return [ data[0] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def get_all_table_names(cls):
sql = "SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_SCHEMA = \'test\' "
cls.exec_sql(sql)
return [ data[0] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def get_all_column_names(cls, table):
sql = "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME = \'%s\'" % (table)
cls.exec_sql(sql)
#type = tuple of tuple
return [ data[0] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def get_databank_by_column(cls, table, column):
sql = "SELECT %s FROM %s" % ( column, table )
cls.exec_sql(sql)
#type = tuple of tuple
return [ data[0] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def get_databank_by_row(cls, table, row_name, row_value ):
sql = "SELECT * FROM %s WHERE %s = \'%s\' " % ( table, row_name, row_value )
cls.exec_sql(sql)
#type = tuple of tuple
return list( cls.cursor.fetchall()[0] )
#NOT USE
@classmethod
def get_mutation_by_column(cls, table, column, mode):
sql = "SELECT info, %s FROM %s WHERE MODE = %d " % ( column, table , mode )
cls.exec_sql(sql)
#type = tuple of tuple
return [ [data[0], data[1]] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def get_mutation_catalog(cls):
sql = "SELECT name, mutation_table FROM mutation_catalog "
logging.info(str(cls))
logging.info(sql)
cls.exec_sql(sql)
return [ [data[0], data[1]] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def get_mutation_values(cls, table, modes):
logging.info("modes: "+str(modes) )
mode_equation = [ "mode = "+str(m) for m in modes ]
mode_equation = "WHERE "+" OR ".join(mode_equation)
logging.info("mode_equation: "+mode_equation)
sql = "SELECT info, value FROM %s %s" % ( table , mode_equation )
logging.info(str(cls))
logging.info(sql)
cls.exec_sql(sql)
return [ [data[0], data[1]] if type(data)==type(tuple()) else str(data) for data in cls.cursor.fetchall() ]
@classmethod
def __str__(cls):
return "connect to Mysql: host(%s) user(%s) password(%s) databank(%s)" % ( cls.host, cls.user, cls.password, cls.databank )
class nullConnect:
@classmethod
def __init__(cls, host, user, password, databank):
cls.host = host
cls.user = user
cls.password = password
cls.databank = databank
#logging.info(str(cls))
@classmethod
def exec_sql(cls, sql):
#logging.info(str(cls))
#logging.info(sql)
pass
@classmethod
def get_submit_by_id(cls, submit_id):
#data [0]id, [1]url, [2]deep, [3]time
return 'url', 'deep', 'time'
@classmethod
def get_all_inputs_by_id(cls, submit_id):
return [ '...' ]
@classmethod
def get_all_table_names(cls):
return [ '...' ]
@classmethod
def get_all_column_names(cls, table):
return [ '...' ]
@classmethod
def get_databank_by_column(cls, table, column):
return [ '...' ]
@classmethod
def get_databank_by_row(cls, table, row_name, row_value ):
return [ '...' ]
#NOT USE
@classmethod
def get_mutation_by_column(cls, table, column, mode):
return [ '...' ]
@classmethod
def get_mutation_catalog(cls):
return [ '...' ]
@classmethod
def get_mutation_values(cls, table, modes):
return [ '...' ]
@classmethod
def __str__(cls):
return "connect to Mysql: host(%s) user(%s) password(%s) databank(%s)" % ( cls.host, cls.user, cls.password, cls.databank )