Beispiel #1
0
    def insert_record(cls, table_name, params, reset=False):
        """
        :param table_name:
        :param params:
        :param reset:
        :return:
        """
        if not cls._db:
            return
        cursor = cls._db.cursor()
        if not cursor.execute("show tables like \'%s\'" % table_name):
            cls.create_table(table_name)
        if reset:
            cls.create_table(table_name)

        temp_sql = db_util.get_insert_sql(table_name, params)
        try:
            cursor.execute(temp_sql)
            cls._db.commit()
            Log.logger("insert data success !")
        except Exception as e:
            Log.error("inert data error {0}".format(e))
            cls._db.rollback()
            return False
        return True
Beispiel #2
0
 def get_class(cls, key):
     try:
         _class = cls.map_class[key]
     except Exception as e:
         Log.error("without found method error - > {0}".format(e))
         return None
     return _class
Beispiel #3
0
 def connect(cls, params):
     cls._db = pymysql.connect(params["ip"],
                               'root',
                               'root',
                               "user",
                               charset='utf8')
     Log.logger("connect sql success! ")
Beispiel #4
0
    def load(self):
        Log.init("logic")

        # 初始化数据库
        DBManager.connect(self.get_server_data("DBServer"))
        # 初始化redis
        RedisManager.init(self.get_server_data("RedisServer"))
        # 数据映射
        MapMethod.init()
Beispiel #5
0
 def init(cls, params):
     db = int(params["db"])
     password = params["password"]
     if params["auth"] == "False":
         pool = redis.ConnectionPool(host=params["ip"],
                                     port=params["port"],
                                     db=db)
     else:
         pool = redis.ConnectionPool(host=params["ip"],
                                     port=params["port"],
                                     db=db,
                                     password=password)
     r = redis.Redis(connection_pool=pool)
     cls.r = r
     Log.logger("init redis")
    def check_token(cls, key, token):
        try:
            ts_byte = base64.b64decode(token)
        except Exception as e:
            Log.error("token without find {0}".format(e))
            return False

        temp_list = ts_byte.split(':')
        curr_time = int(time.time())
        origin_time = int(temp_list[0])

        if key != temp_list[1]:
            return False

        if origin_time > curr_time:
            return True
        return False
Beispiel #7
0
    def delete_record(cls, table_name, params):
        """

        :param table_name:
        :param params:
        :return:
        """
        if not cls._db:
            return
        cursor = cls._db.cursor()
        temp_sql = db_util.get_del_sql(table_name, params)
        try:
            cursor.execute(temp_sql)
            cls._db.commit()
        except Exception as e:
            Log.error("delete data error {0}".format(e))
            cls._db.rollback()
            return
        Log.logger("delete data success !")
Beispiel #8
0
    def get_record(cls, table_name, params):
        """

        :param table_name:
        :param params:
        :return:
        """
        if not cls._db:
            return
        cursor = cls._db.cursor()
        temp_sql = db_util.get_record_sql(table_name, params)
        try:
            cursor.execute(temp_sql)
            result = cursor.fetchall()
        except Exception as e:
            Log.error("get data error {0}".format(e))
            cls._db.rollback()
            return
        Log.logger("get data success !")
        if not result:
            return
        return db_util.deal_get_result(table_name, result[0])
Beispiel #9
0
    def create_table(cls, table_name):
        """

        :param table_name:
        :return:
        """
        if not cls._db:
            return

        cursor = cls._db.cursor()
        try:
            cursor.execute("DROP TABLE IF EXISTS %s" % table_name)
        except Exception as e:
            Log.logger("drop table data error {0}".format(e))
            return

        temp_sql = db_util.get_table_sql(table_name)
        try:
            cursor.execute(temp_sql)
            Log.logger("create table success !")
        except Exception as e:
            Log.error("create table error {0}".format(e))
Beispiel #10
0
    def load(self):
        Log.init("logic")

        DBManager.connect(self.get_server_data("DBServer"))
        RedisManager.init(self.get_server_data("RedisServer"))
        MapMethod.init()