def _get_fix(db, fix_num, err_id=None, uuid=None): if err_id: sql = "SELECT fixes FROM markers WHERE id = %s" db.execute(sql, (err_id, )) else: sql = "SELECT fixes FROM markers WHERE uuid = %s" db.execute(sql, (uuid, )) fix = db.fetchone() if not fix: abort(410, "Fix is not present in database.") return fixes_default(fix[0])[fix_num]
def _get(db, err_id=None, uuid=None): columns_marker = [ "marker.item", "marker.source", "marker.class", "marker.elems", "marker.fixes", "marker.lat", "marker.lon", "class.title", "marker.subtitle", "dynpoi_class.timestamp", "class.detail", "class.fix", "class.trap", "class.example", "class.source AS source_code", "class.resource", ] if err_id: sql = "SELECT uuid_to_bigint(marker.uuid) AS id, " + ",".join( columns_marker) + """ FROM marker JOIN dynpoi_class ON marker.source = dynpoi_class.source AND marker.class = dynpoi_class.class JOIN class ON marker.item = class.item AND marker.class = class.class WHERE uuid_to_bigint(marker.uuid) = %s """ db.execute(sql, (err_id, )) else: sql = "SELECT " + ",".join(columns_marker) + """ FROM marker JOIN dynpoi_class ON marker.source = dynpoi_class.source AND marker.class = dynpoi_class.class JOIN class ON marker.item = class.item AND marker.class = class.class WHERE marker.uuid = %s """ db.execute(sql, (uuid, )) marker = db.fetchone() if not marker: return None marker['fixes'] = fixes_default(marker['fixes']) marker['elems'] = list( map( lambda elem: dict( elem, type_long={ 'N': 'node', 'W': 'way', 'R': 'relation' }[elem['type']], ), marker['elems'] or [])) return marker
def _get(db, err_id=None, uuid=None): columns_marker = [ "markers.item", "markers.source_id", "markers.class", "elems", "fixes", "lat::float", "lon::float", "title", "subtitle", "updates_last.timestamp", "detail", "fix", "trap", "example", "source AS source_code", "resource", ] if err_id: sql = "SELECT uuid_to_bigint(markers.uuid) AS id, " + ",".join( columns_marker) + """ FROM markers JOIN class ON class.item = markers.item AND class.class = markers.class JOIN updates_last ON updates_last.source_id = markers.source_id WHERE uuid_to_bigint(uuid) = %s """ db.execute(sql, (err_id, )) else: sql = "SELECT " + ",".join(columns_marker) + """ FROM markers JOIN class ON class.item = markers.item AND class.class = markers.class JOIN updates_last ON updates_last.source_id = markers.source_id WHERE uuid = %s """ db.execute(sql, (uuid, )) marker = db.fetchone() if not marker: return None marker['fixes'] = fixes_default(marker['fixes']) marker['elems'] = list( map( lambda elem: dict( elem, type_long={ 'N': 'node', 'W': 'way', 'R': 'relation' }[elem['type']], ), marker['elems'] or [])) return marker