Пример #1
0
    def insterInterfaceData(self, savePath):
        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:

            sql = 'DROP TABLE IF  EXISTS tmp_x;' \
                  'CREATE TEMPORARY TABLE tmp_x (interFaceName varchar(255),' \
                  ' interFaceNameStr varchar(255) ,' \
                  ' interFaceDescribe text,' \
                  ' interFacepath text,' \
                  ' interFaceBeginTime text,' \
                  ' interFaceEndTime text,' \
                  ' interFaceBeginVersions text,' \
                  ' interFaceEndVersions text);' \
                  'LOAD DATA LOCAL INFILE ' \
                  '"/Users/ubungit/Git/UHPySever/Sever/Data/InterFace.txt" ' \
                  'INTO TABLE tmp_x FIELDS TERMINATED BY "\t" LINES TERMINATED BY "\n"; ' \
                  'REPLACE  SmartHomeInterFace_Table (interFaceName,interFaceNameStr,interFaceDescribe,interFacepath,' \
                  'interFaceBeginTime,interFaceEndTime,interFaceBeginVersions,interFaceEndVersions)' \
                  'SELECT interFaceName,interFaceNameStr,interFaceDescribe,interFacepath,' \
                  'interFaceBeginTime,interFaceEndTime,interFaceBeginVersions,interFaceEndVersions FROM tmp_x;' \
                  'DROP TABLE IF  EXISTS tmp_x'
            cursor.execute(sql)
            connection.commit()
            connection.close()
            return
Пример #2
0
 def getSection(self, userID):
     connection = SqlHabdleGlobal.connectionDb()
     with connection.cursor() as cursor:
         sql = "SELECT * FROM SEDDION_T WHERE userID=%s;"
         cursor.execute(sql, (userID))
         connection.commit()
         connection.close()
Пример #3
0
 def deleteSection(self, userID):
     connection = SqlHabdleGlobal.connectionDb()
     with connection.cursor() as cursor:
         sql = "delete from SEDDION_T where userID=(%s)"
         cursor.execute(sql, (userID))
         connection.commit()
         connection.close()
Пример #4
0
    def loadFC3DDataByText(self, path):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new record
            sql = 'LOAD DATA LOCAL INFILE "' + path + '" INTO TABLE FC3DData_t FIELDS TERMINATED BY " " LINES TERMINATED BY "\\n"'
            cursor.execute(sql)
            connection.commit()
            connection.close()
Пример #5
0
 def getAdminList(self, data, userID):
     connection = SqlHabdleGlobal.connectionDb()
     with connection.cursor() as cursor:
         # Create a new record
         sql = 'SELECT* FROM USER_T'
         cursor.execute(sql)
         connection.commit()
         adminlist = []
         for row in cursor:
             adminlist.append(row)
         return adminlist
Пример #6
0
    def removeAdmin(self, data, userID):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new record
            sql = 'DELETE  FROM USER_T WHERE userID=%s'
            cursor.execute(sql, (data["userID"]))
            connection.commit()
            adminlist = []
            for row in cursor:
                adminlist.append(row)
            return adminlist
Пример #7
0
    def createInterFacetxt(self, savepath):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:

            sql = 'select interFaceName,interFaceNameStr,' \
                  'interFaceDescribe,interFacepath,' \
                  'interFaceBeginTime,interFaceEndTime,' \
                  'interFaceBeginVersions,interFaceEndVersions from SmartHomeInterFace_Table into  outfile "'+ savepath +'"'
            cursor.execute(sql)
            connection.commit()
            connection.close()
            return
Пример #8
0
    def selectGoodslistBySearch(self, data):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            sql = 'select * from GOODS_T'
            if ("searchKey" in data.keys()):
                sql = sql + 'WHERE goodsName = "' + data["searchKey"] + '"'
                data.pop("searchKey")
            cursor.execute(sql)
            goodslist = []
            for row in cursor:
                goodslist.append(row)
            return goodslist
Пример #9
0
    def selectUserInfoBykey(self, key, value):

        if key not in ['userID', 'userName', 'phone', 'wxOpenid', 'email']:
            raise CustomError(-10007)

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:

            sql = 'select userID,passWord,userName,email,createTime,status,permissions,phone,headImage,wxOpenid from USER_T where ' + key + ' = %s'
            cursor.execute(sql, (value))
            for row in cursor:
                cursorData = row
                return cursorData
Пример #10
0
    def selectGoosdinfoByID(self, goodsID):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:

            sql = 'select * from GOODS_T t1  join GOODSDES_T  t2  where t1.goodsID= %s'
            cursor.execute(sql, (goodsID))
            goodslist = []
            for row in cursor:
                goodslist.append(row)
            if (len(goodslist) == 1):
                return goodslist[0]
            else:
                return None
Пример #11
0
 def addGoods(self, data):
     connection = SqlHabdleGlobal.connectionDb()
     with connection.cursor() as cursor:
         # Create a new record
         keystr = ''
         valuestr = ''
         for item in data.keys():
             keystr = keystr + item + ','
             valuestr = valuestr + '"' + data[item] + '",'
         keystr = keystr[0:-1]
         valuestr = valuestr[0:-1]
         sql = 'INSERT INTO GOODS_T (' + keystr + ') VALUES (' + valuestr + ')'
         cursor.execute(sql)
         connection.commit()
Пример #12
0
    def insetUserInfo(self, userName, userTel, userPassWord):
        try:
            connection = SqlHabdleGlobal.connectionDb()
            with connection.cursor() as cursor:
                # Create a new record
                sql = 'INSERT INTO USER_T (userName, passWord, phone) VALUES (%s, %s,%s)'
                cursor.execute(sql, (userName, userPassWord, userTel))
                connection.commit()

        except MySQLError as e:
            if e.args[0] == 1062:
                raise CustomError(-10003)
            else:
                raise e
Пример #13
0
 def deleteParameter(self, data):
     try:
         connection = SqlHabdleGlobal.connectionDb()
         with connection.cursor() as cursor:
             # Create a new record
             sql = 'DELETE FROM SmartHomeParameter_Table WHERE parameterId=%s;'
             cursor.execute(sql, (data['parameterId']))
             connection.commit()
     except BaseException as e:
         returnDic = {"infoCode": -10000}
         return returnDic
     else:
         connection.close()
         returnDic = {"infoCode": 0}
         return returnDic
Пример #14
0
    def getFactionList(self, data, userName):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new record
            fatherID = data["fatherId"]
            sql = 'SELECT * FROM FunctionData_t where fatherID=' + str(
                fatherID)
            print(sql)
            cursor.execute(sql)
            connection.commit()
            list = []
            for row in cursor:
                list.append(row)
            connection.close()
            return list
Пример #15
0
    def getInterFaceInfo(self, interFaceName):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new record
            sql = 'SELECT * FROM ' + INTERFAVE_TABLE + ' where interFaceName=%s;'
            cursor.execute(sql, interFaceName)
            list = []
            for row in cursor:
                list.append(row)
            if len(list) <= 0:
                returnDic = {"infoCode": -10004}
            else:
                returnDic = {"infoCode": 0}
                returnDic['result'] = list
            return returnDic
Пример #16
0
    def addInterFace(self, interFaceName, interFaceNameStr, interFacepath):
        try:
            connection = SqlHabdleGlobal.connectionDb()
            with connection.cursor() as cursor:
                sql = 'INSERT SmartHomeInterFace_Table (interFaceName,interFaceNameStr,interFacepath) VALUES (%s,%s,%s);'
                cursor.execute(
                    sql, (interFaceName, interFaceNameStr, interFacepath))
                connection.commit()

        except BaseException:

            returnDic = {"infoCode": -10000}
            return returnDic
        else:
            connection.close()
            returnDic = {"infoCode": 0}
            return returnDic
Пример #17
0
    def insterSection(self, data):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            keystr = ''
            valuestr = ''
            for item in data.keys():
                keystr = keystr + item + ','
                if type(data[item]) == int or type(data[item]) == float:
                    valuestr = valuestr + str(data[item]) + ','
                else:
                    valuestr = valuestr + '"' + data[item] + '",'
            keystr = keystr[0:-1]
            valuestr = valuestr[0:-1]
            sql = 'INSERT SEDDION_T (' + keystr + ') VALUES (' + valuestr + ');'
            cursor.execute(sql)
            connection.commit()
            connection.close()
Пример #18
0
    def deleteInterFace(self, data):

        try:
            interfaceName = data['inteFaceName']
            connection = SqlHabdleGlobal.connectionDb()
            with connection.cursor() as cursor:
                sql = 'delete from SmartHomeInterFace_Table where interFaceName=(%s);'
                cursor.execute(sql, (interfaceName))
                connection.commit()

        except BaseException:

            returnDic = {"infoCode": -10000}
            return returnDic
        else:
            connection.close()
            returnDic = {"infoCode": 0}
            return returnDic
Пример #19
0
    def getInterfaceParameterList(self, interFaceName, parameterTypeuse):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new record
            sql = 'SELECT * FROM ' + INTERFAVEPARAMETER_TABLE + ' where parameterFatherName=(select interFaceName from ' + INTERFAVE_TABLE + ' where  interFaceName=%s and parameterTypeuse=%s);'
            cursor.execute(sql, (interFaceName, parameterTypeuse))

            list = []
            for row in cursor:
                list.append(row)
            if len(list) <= 0:
                returnDic = {"infoCode": -10004}
            else:
                returnDic = {"infoCode": 0}
                returnDic['result'] = list

            return returnDic
Пример #20
0
 def getLastFCData(self):
     connection = SqlHabdleGlobal.connectionDb()
     with connection.cursor() as cursor:
         # Create a new record
         sql = 'select* from FC3DData_t order by outNO desc limit 0,1'
         cursor.execute(sql)
         connection.commit()
         list = []
         for row in cursor:
             #                 row["outdate"] = str(row["outdate"])
             list.append(row)
         if len(list) <= 0:
             returnDic = {"infoCode": -10004}
         else:
             returnDic = {"infoCode": 0}
             returnDic['result'] = list
         connection.close()
         return returnDic
Пример #21
0
 def getFC3dData(self, data):
     connection = SqlHabdleGlobal.connectionDb()
     with connection.cursor() as cursor:
         # Create a new record
         beginNum = int(data["pageNum"]) * int(data["pageSize"])
         sql = 'select* from FC3DData_t   order by outNO desc limit ' + str(
             beginNum) + ',' + data["pageSize"] + ''
         cursor.execute(sql)
         connection.commit()
         list = []
         for row in cursor:
             row["outdate"] = str(row["outdate"])
             list.append(row)
         if len(list) <= 0:
             returnDic = {"infoCode": -10004}
         else:
             returnDic = {"infoCode": 0}
             returnDic['result'] = list
         connection.close()
         return returnDic
Пример #22
0
    def insetUser(self, data):
        try:
            connection = SqlHabdleGlobal.connectionDb()
            with connection.cursor() as cursor:
                # Create a new record
                keystr = ''
                valuestr = ''
                for item in data.keys():
                    keystr = keystr + item + ','
                    valuestr = valuestr + '"' + data[item] + '",'
                keystr = keystr[0:-1]
                valuestr = valuestr[0:-1]
                sql = 'INSERT INTO USER_T (' + keystr + ') VALUES (' + valuestr + ')'
                cursor.execute(sql)
                connection.commit()

        except MySQLError as e:
            if e.args[0] == 1062:
                raise CustomError(-10003)
            else:
                raise e
Пример #23
0
    def getInterfaceList(self, data):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new record
            sql = 'SELECT * FROM ' + INTERFAVE_TABLE
            if ("searchKey" in data.keys()):
                sql = sql + ' where interFaceName  LIKE "%' + data[
                    'searchKey'] + '%" or interFaceNameStr  LIKE "%' + data[
                        'searchKey'] + '%"'
            sql = sql + ' ;'
            cursor.execute(sql)
            list = []
            for row in cursor:
                list.append(row)
            if len(list) <= 0:
                returnDic = {"infoCode": -10004}
            else:
                returnDic = {"infoCode": 0}
                returnDic['result'] = list
            return returnDic
Пример #24
0
    def replaceGoodsdesInfo(self, data):

        goodsID = data["goodsID"]
        data.pop("goodsID")

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new recors
            sql = 'UPDATE GOODSDES_T SET '

            for key in data.keys():

                if type(data[key]) == int or type(data[key]) == float:
                    sql = sql + key + '=' + str(data[key]) + ','
                else:
                    sql = sql + key + '="' + data[key] + '",'

            sql = sql[0:-1]
            sql = sql + ' WHERE goodsID=' + str(goodsID)
            cursor.execute(sql)
            connection.commit()
            connection.close()
Пример #25
0
    def replaceUserInfo(self, data, userID):

        userData = self.selectUserInfo(data["userID"])
        if userData == None: raise CustomError(-10001)

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            # Create a new recors
            sql = 'UPDATE USER_T SET '

            for key in data.keys():
                if key == "userID": continue

                if type(data[key]) == int or type(data[key]) == float:
                    sql = sql + key + '=' + str(data[key]) + ','
                else:
                    sql = sql + key + '="' + data[key] + '",'

            sql = sql[0:-1]
            sql = sql + ' WHERE userID=' + str(data["userID"])
            cursor.execute(sql)
            connection.commit()
            connection.close()
Пример #26
0
    def getFCDatabyOutData(self, data):

        connection = SqlHabdleGlobal.connectionDb()
        with connection.cursor() as cursor:
            outdata = None
            if ("outNO" in data.keys()):
                outdata = data["outNO"]
            elif ("outdate" in data.keys()):
                outdata = data["outdate"]
            else:
                return None
            sql = 'SELECT * FROM FC3DData_t where outNO = "' + outdata + '" or outdate= "' + outdata + '"'
            cursor.execute(sql)
            tablerows = cursor.fetchall()
            if (len(tablerows) == 1):
                result = tablerows[0]
                result["outdate"] = str(result["outdate"])
                returnDic = {"infoCode": 0}
                returnDic['result'] = result
            else:
                returnDic = {"infoCode": -10004}
            connection.close()
            return returnDic
Пример #27
0
 def addParametervalue(self, parameterDic):
     try:
         connection = SqlHabdleGlobal.connectionDb()
         with connection.cursor() as cursor:
             # Create a new record
             sql = 'call p_ReplaceInterFaceParameter(%s,%s,%s,%s,%s,%s,%s,%s,%s)'
             cursor.execute(sql, (parameterDic['parameterName'],
                                  parameterDic['parameterFatherName'],
                                  parameterDic['parameterDescribe'],
                                  parameterDic['parameterCanNil'],
                                  parameterDic['parameterEndTime'],
                                  parameterDic['parameterBeginVersions'],
                                  parameterDic['parameterEndVersions'],
                                  parameterDic['parameterType'],
                                  parameterDic['parameterTypeuse']))
             connection.commit()
     except BaseException as e:
         returnDic = {"infoCode": -10000}
         return returnDic
     else:
         connection.close()
         returnDic = {"infoCode": 0}
         return returnDic
Пример #28
0
    def replaceIntefaceInfo(self, data):
        try:
            interfaceName = data['repInteFaceName']
            setstr = 'set '
            for key in data.keys():
                keystr = str(key)
                if (keystr != str("repInteFaceName")
                        and keystr != str("inefaceMode")):
                    setstr = setstr + key + '="' + data[key] + '",'
            setstr = setstr[:-1]
            connection = SqlHabdleGlobal.connectionDb()
            with connection.cursor() as cursor:
                sql = 'UPDATE   SmartHomeInterFace_Table  ' + setstr + ' WHERE interFaceName = "' + interfaceName + '"'
                cursor.execute(sql)
                connection.commit()
        except BaseException:

            returnDic = {"infoCode": -10000}
            return returnDic
        else:
            connection.close()
            returnDic = {"infoCode": 0}
            return returnDic