blob: 1edfe3575627a986594a8ea35706855a57d92e87 (
plain)
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
|
import mysqlhack
from secrets import *
from thread_utils import *
from com.ziclix.python.sql import zxJDBC
from traceback import format_exc as trace
class mysql_connect:
def __init__(self):
self.conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
self.curs = self.conn.cursor()
def execute(self, query, args=None):
if args is None:
return self.curs.execute(query)
else:
print query
print args
return self.curs.execute(query, args)
def fetchall(self):
return self.curs.fetchall()
@property
def columns(self):
self.execute("SHOW COLUMNS FROM utils_players")
fetched = self.fetchall()
columns = []
for row in fetched:
columns.append(row[0])
return columns
def __enter__(self):
return self
def __exit__(self, exc_type, exc_inst, exc_tb):
if exc_type is None:
try:
self.conn.commit()
self.curs.close()
self.conn.close()
except:
print(trace())
else:
print(exc_tb)
|