-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBManager.py
54 lines (42 loc) · 1.49 KB
/
DBManager.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
# -*- coding: UTF-8 -*-
__author__ = 'Jeffrey'
import MySQLdb
from MySQLdb.cursors import DictCursor
from utils import error_catch, logging
class Connector(object):
_index = 0
@error_catch
def __init__(self, host, user, pwd, dbName, port=3306, charset="utf8"):
self._host = host
self._user = user
self._pwd = pwd
self._dbName = dbName
self._port = port
self._charset = charset
self._connector = MySQLdb.connect(host=self._host,
user=self._user,
passwd=self._pwd,
db=self._dbName,
port=self._port,
charset=self._charset,
cursorclass=DictCursor,
)
@property
def connector(self):
return self._connector
@connector.setter
def connector(self, connector=None):
if not connector:
raise
self._connector = connector
def close(self):
self._connector.cursor().close()
self._connector.close()
logging("error", "DBM close!")
@classmethod
def execute_sql(cls,func):
def wrapper(*args,**kwargs):
print func.__class__, func.__name__
return func(*args,**kwargs)
return wrapper
QDB = Connector("localhost", "root", "zjh921117", "youaiwang", 3306)