def delete_station2(inData): ''' :param inData: :return:{ 2:'there is no id in inData', 3:'there is no such id' } ''' ret=0 if(not inData.has_key('id')): ret=2 return ret query=session.query(Station) tmpStation=query.filter(Station.id==inData['id']).first() if(tmpStation==None): ret=3 return ret else: from sensor import Sensor tmpAllSensor=Sensor.select({'stationId': tmpStation.id}) for tmpSensor in tmpAllSensor['pureData']: tmpSensor.stationId=0 session.delete(tmpStation) session.commit() ret=1 return ret
def delete_station2(inData): ''' :param inData: :return:{ 2:'there is no id in inData', 3:'there is no such id' } ''' ret = 0 if('id' not in inData): ret = 2 return ret query = session.query(Station) tmpStation = query.filter(Station.id == inData['id']).first() if(tmpStation is None): ret = 3 return ret else: from sensor import Sensor tmpAllSensor = Sensor.select({'stationId': tmpStation.id}) for tmpSensor in tmpAllSensor['pureData']: tmpSensor.stationId = 0 session.delete(tmpStation) session.commit() ret = 1 return ret
def delete_data(self,id): try: """删除数据,默认开始事务""" rows = session.query(ProductModel).filter(ProductModel.id == id).first() session.delete(rows) session.commit() return True except: session.rollback()
def delete_user(*args,**kwargs): """" query>User.username=='cainiao' """ try: rows = session.query(User).filter(*args).filter_by(**kwargs)[0] session.delete(rows) session.commit() except Exception as e: session.rollback() raise e
def init(): Base.metadata.create_all(engine) old = Hardware.get_all_hardware() if old: print '[i] delete old data in hardware table...' for item in old: session.delete(item) session.commit() hardware_info_csv = 'hardware_info.csv' Hardware.read_hardware_info(hardware_info_csv) print '[i] complete initing the hardware table...'
def retData(timeSpan, inType): if (inType == 'py'): query = session.query(Atkinfo) sensorQuery = session.query(Sensor) nowTime = time.time() limitTime = nowTime - timeSpan allInfos = query.filter( and_(Atkinfo.pyRead == 0, Atkinfo.atkTime > limitTime)) ret = [] for tmpInfo in allInfos: tmpInfo.pyRead = 1 tmp = {} tmp['attackId'] = tmpInfo.atkId tmp['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(tmpInfo.atkTime)) tmpSensor = sensorQuery.filter( Sensor.mac == tmpInfo.sensorMac).first() if (tmpSensor is not None): tmp['sensorId'] = tmpSensor.number else: tmp['sensorId'] = 'not known' tmp['src'] = {} tmp['src']['ip'] = tmpInfo.srcIp tmp['src']['port'] = tmpInfo.srcPort tmp['src']['lng'] = float(tmpInfo.srcLng) tmp['src']['lat'] = float(tmpInfo.srcLat) tmp['src']['name'] = '' tmp['dst'] = {} tmp['dst']['ip'] = tmpInfo.dstIp tmp['dst']['port'] = tmpInfo.dstPort tmp['dst']['lng'] = float(tmpInfo.dstLng) tmp['dst']['lat'] = float(tmpInfo.dstLat) tmp['dst']['name'] = '' tmp['protocalA'] = tmpInfo.cmProtocal tmp['trails'] = tmpInfo.trails tmp['references'] = tmpInfo.refer tmp['infos'] = tmpInfo.infos ret.append(tmp) session.delete(tmpInfo) session.commit() return ret else: return {}
def delete_auth2(inData): ''' :param inData: :return: {2:'there is no id', 3:'this is so such record'} ''' ret = 1 if (inData.has_key('id')): query = session.query(Auth) tmpAuth = query.filter(Auth.id == inData['id']).first() if (tmpAuth != None): session.delete(tmpAuth) session.commit() ret = 1 else: ret = 3 else: ret = 2 return ret
def delete_auth2(inData): ''' :param inData: :return: {2:'there is no id', 3:'this is so such record'} ''' ret=1 if(inData.has_key('id')): query=session.query(Auth) tmpAuth=query.filter(Auth.id==inData['id']).first() if(tmpAuth!=None): session.delete(tmpAuth) session.commit() ret=1 else: ret=3 else: ret=2 return ret
def retData(timeSpan, inType): if(inType=='py'): query=session.query(Atkinfo) nowTime=time.time() limitTime=nowTime-timeSpan delInfos=query.filter(Atkinfo.atkTime<=limitTime) allInfos=query.filter(and_(Atkinfo.atkTime>limitTime)) ret=[] for tmpInfo in delInfos: session.delete(tmpInfo) for tmpInfo in allInfos: tmp={} tmp['attackId']=tmpInfo.atkId tmp['time']=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(tmpInfo.atkTime)) tmp['sensorId']=tmpInfo.sensorNumber tmp['src']={} tmp['src']['ip']=tmpInfo.srcIp tmp['src']['port']=tmpInfo.srcPort tmp['src']['lng']=float(tmpInfo.srcLng) tmp['src']['lat']=float(tmpInfo.srcLat) tmp['src']['name']='' tmp['dst']={} tmp['dst']['ip']=tmpInfo.dstIp tmp['dst']['port']=tmpInfo.dstPort tmp['dst']['lng']=float(tmpInfo.dstLng) tmp['dst']['lat']=float(tmpInfo.dstLat) tmp['dst']['name']='' tmp['protocalA']=tmpInfo.cmProtocal tmp['trails']=tmpInfo.trails tmp['references']=tmpInfo.refer tmp['infos']=tmpInfo.infos ret.append(tmp) session.delete(tmpInfo) session.commit() return ret else: return {}
def del_user2(inData): ''' :param inData: :return{0: error, 2: no id in inData, 3: no such id in userv2, }: ''' ret = 0 if ('id' not in inData): ret = 2 return ret query = session.query(User) tmpUser = query.filter(User.id == inData['id']).first() if (tmpUser is None): ret = 3 return ret else: from user_old import User_old User_old.add(tmpUser) from auth import Auth authQuery = session.query(Auth) authQuery.filter(Auth.userId == tmpUser.id).delete() session.delete(tmpUser) session.commit() ret = 1 return ret
def del_user2(inData): ''' :param inData: :return{0: error, 2: no id in inData, 3: no such id in userv2, }: ''' ret=0 if(not inData.has_key('id')): ret=2 return ret query=session.query(User) tmpUser=query.filter(User.id==inData['id']).first() if(tmpUser==None): ret=3 return ret else: from user_old import User_old User_old.add(tmpUser) from auth import Auth authQuery=session.query(Auth) authQuery.filter(Auth.userId==tmpUser.id).delete() session.delete(tmpUser) session.commit() ret=1 return ret
def delete_user(): row = session.query(User).filter(User.name == 'chenyanqi')[0] print(row) session.delete(row) session.commit()
def delete_user(): rows = session.query(User).filter(User.username == 'xpss')[0] session.delete(rows) #删除第一条记录 #rows.deleted() #批量删除 session.commit()