Skip to content

Commit

Permalink
Merge 217376f into 9c0f47b
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 committed Sep 29, 2020
2 parents 9c0f47b + 217376f commit 3a11a64
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/translators/sql_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def _get_limit(self, limit, last_n):
def _get_where_clause(self, entity_ids, from_date, to_date, fiware_sp=None,
geo_query=None):
clauses = []
where_clause = ""

if entity_ids:
ids = ",".join("'{}'".format(e) for e in entity_ids)
Expand All @@ -533,8 +534,12 @@ def _get_where_clause(self, entity_ids, from_date, to_date, fiware_sp=None,

if fiware_sp:
# Match prefix of fiware service path
clauses.append(
" " + FIWARE_SERVICEPATH + " ~* '" + fiware_sp + "($|/.*)'")
if fiware_sp == '/':
clauses.append(
" " + FIWARE_SERVICEPATH + " ~* '($|/.*)'")
else:
clauses.append(
" " + FIWARE_SERVICEPATH + " ~* '" + fiware_sp + "($|/.*)'")
else:
# Match prefix of fiware service path
clauses.append(" " + FIWARE_SERVICEPATH + " = ''")
Expand All @@ -543,12 +548,13 @@ def _get_where_clause(self, entity_ids, from_date, to_date, fiware_sp=None,
if geo_clause:
clauses.append(geo_clause)

where_clause = "where " + "and ".join(clauses)
if len(clauses) > 0:
where_clause = "where" + " and ".join(clauses)
return where_clause

def _parse_date(self, date):
try:
return dateutil.parser.isoparse(date.strip('\"'))
return dateutil.parser.isoparse(date.strip('\"')).isoformat()
except Exception as e:
raise InvalidParameterValue(date, "**fromDate** or **toDate**")

Expand Down Expand Up @@ -805,8 +811,10 @@ def query(self,
try:
self.cursor.execute(op)
except Exception as e:
#TODO due to this except in case of sql errors,
#all goes fine, and users gets 404 as result
# Reason 1: fiware_service_path column in legacy dbs.
logging.debug("{}".format(e))
logging.error("{}".format(e))
entities = []
else:
res = self.cursor.fetchall()
Expand Down

0 comments on commit 3a11a64

Please sign in to comment.