def selectFromLocation(self, whereLocation=None, max_row=None): if self.CONNECTED: table = "location" location = object_DL.Location() if whereLocation is not None and isinstance( whereLocation, object_DL.Location): arr_n = whereLocation.get_arr_name_columns() arr_v = whereLocation.get_value() f_arr_n = [] f_arr_v = [] for i in range(len(arr_v)): if arr_v[i] is not None: f_arr_n.append(arr_n[i]) f_arr_v.append(arr_v[i]) columns, refer = self.__standardize_for_query(f_arr_n) sql = "SELECT {} FROM {} WHERE ({}) = ({})".format( location.get_name_columns(), table, columns, refer) val = f_arr_v try: self.__mycursor.execute(sql, val) except mysql.connector.Error as err: logging.exception( "ERR in selectFromLocation: {}".format(err)) return None else: sql = "SELECT {} FROM {}".format(location.get_name_columns(), table) try: self.__mycursor.execute(sql) except mysql.connector.Error as err: logging.exception( "ERR in selectFromLocation: {}".format(err)) return None if max_row is not None: rs = self.__mycursor.fetchmany(max_row) else: rs = self.__mycursor.fetchall() obj_rs = [] for x in rs: obj_rs.append( object_DL.Location(id=x[0], longtitude=x[1], latitude=x[2], location=x[3])) return obj_rs
def getLocationById(self, idLocation): if self.CONNECTED: sql = "SELECT * FROM location WHERE idLocation = {}".format( idLocation) try: self.__mycursor.execute(sql) rows = self.__mycursor.fetchall() for row in rows: return object_DL.Location(id=row['idLocation'], longtitude=row['longtitude'], latitude=row['latitude'], location=row['location']) except mysql.connector.Error as err: logging.exception("ERR in getLocationById: {}".format(err)) return None return None
def getLocations(self): if self.CONNECTED: sql = "SELECT * FROM location" try: self.__mycursor.execute(sql) rows = self.__mycursor.fetchall() results = [] for row in rows: location = object_DL.Location(id=row['idLocation'], longtitude=row['longtitude'], latitude=row['latitude'], location=row['location']) results.append(location) return results except mysql.connector.Error as err: logging.exception("ERR in getLocations: {}".format(err)) return None return None
def getImages(self): if self.CONNECTED: sql = "SELECT * FROM image " \ + "JOIN person ON image.idPerson = person.idPerson " \ + "JOIN camera ON image.idCamera = camera.idCamera " \ + "JOIN location ON location.idLocation = camera.idLocation" try: self.__mycursor.execute(sql) rows = self.__mycursor.fetchall() results = [] for row in rows: person = object_DL.Person(id=row['idPerson'], name=row['name'], age=row['age'], gender=row['gender'], idcode=row['idCode'], embedding=row['embedding'], b64face=row['b64Face'], b64image=row['b64Image']) location = object_DL.Location(id=row['idLocation'], longtitude=row['longtitude'], latitude=row['latitude'], location=row['location']) camera = object_DL.Camera(id=row['idCamera'], cameraname=row['cameraName'], httpurl=row['HTTPUrl'], rstpurl=row['RSTPUrl'], location=location) image = object_DL.Image(id=row['idImage'], person=person, camera=camera, time=row['time'], b64image=row['b64Image'], b64face=row['b64Face'], embedding=row['embedding'], istrained=row['isTrained']) results.append(image) return results except mysql.connector.Error as err: logging.exception("ERR in getImages: {}".format(err)) return None return None
def getCameraById(self, idCamera): if self.CONNECTED: sql = "SELECT * FROM camera JOIN location ON camera.idLocation = location.idLocation WHERE idCamera = {}".format( idCamera) try: self.__mycursor.execute(sql) rows = self.__mycursor.fetchall() for row in rows: location = object_DL.Location(id=row['idLocation'], longtitude=row['longtitude'], latitude=row['latitude'], location=row['location']) return object_DL.Camera(id=row['idCamera'], cameraname=row['cameraName'], httpurl=row['HTTPUrl'], rstpurl=row['RSTPUrl'], location=location) except mysql.connector.Error as err: logging.exception("ERR in getCameraById: {}".format(err)) return None return None