Skip to content
Snippets Groups Projects
Commit a9f804d3 authored by florian's avatar florian
Browse files

WIP: Replace single quotes in query

parent 55a54e56
No related branches found
No related tags found
2 merge requests!53Release 0.1,!48F fix ident query
...@@ -52,8 +52,11 @@ def convert_value(value): ...@@ -52,8 +52,11 @@ def convert_value(value):
return str(value.id) return str(value.id)
elif isinstance(value, datetime): elif isinstance(value, datetime):
return value.isoformat() return value.isoformat()
elif isinstance(value, str):
# replace single quotes, otherwise they may break the queries
return str(value.replace("'", "\'"))
else: else:
return str(value) return value
class IdentifiableAdapter(metaclass=ABCMeta): class IdentifiableAdapter(metaclass=ABCMeta):
...@@ -387,7 +390,8 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter): ...@@ -387,7 +390,8 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
if self.check_record(record, identifiable): if self.check_record(record, identifiable):
candidates.append(record) candidates.append(record)
if len(candidates) > 1: if len(candidates) > 1:
raise RuntimeError("Identifiable was not defined unambigiously.") raise RuntimeError(
f"Identifiable was not defined unambigiously. Possible candidates are {candidates}")
if len(candidates) == 0: if len(candidates) == 0:
return None return None
return candidates[0] return candidates[0]
...@@ -469,7 +473,8 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): ...@@ -469,7 +473,8 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
query_string = self.create_query_for_identifiable(identifiable) query_string = self.create_query_for_identifiable(identifiable)
candidates = db.execute_query(query_string) candidates = db.execute_query(query_string)
if len(candidates) > 1: if len(candidates) > 1:
raise RuntimeError("Identifiable was not defined unambigiously.") raise RuntimeError(
f"Identifiable was not defined unambigiously.\n{query_string}\nReturned the following {candidates}.")
if len(candidates) == 0: if len(candidates) == 0:
return None return None
return candidates[0] return candidates[0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment