Skip to content

Commit 7a764f3

Browse files
committed
fix: fix query sql parsing
1 parent 5a7ccc2 commit 7a764f3

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

tagreader/web_handlers.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,6 @@ def fetch(
222222
txt = res.text.replace('"v":nan', '"v":NaN').replace('"v":-nan', '"v":NaN')
223223
return json.loads(txt)
224224

225-
def fetch_text(
226-
self, url, params: Optional[Union[str, Dict[str, str]]] = None
227-
) -> str:
228-
res = self.session.get(url, params=params)
229-
res.raise_for_status()
230-
231-
return res.text
232-
233225
def connect(self):
234226
try:
235227
self.verify_connection(self.datasource)
@@ -667,10 +659,12 @@ def generate_sql_query(
667659
'dso="CHARINT=N;CHARFLOAT=N;CHARTIME=N;CONVERTERRORS=N" '
668660
f'm="{max_rows}" to="30" s="1">'
669661
)
670-
query = query.replace("\t"," ").replace('\n'," ") # Replace new lines and tabs that are typical in formatted SQL queries with spaces.
671-
662+
query = query.replace("\t", " ").replace(
663+
"\n", " "
664+
) # Replace new lines and tabs that are typical in formatted SQL queries with spaces.
665+
672666
# Need a solution to LIKE comments. These have a % symbol in the query that does not seem to pass through the request
673-
667+
674668
connection_string += f"<![CDATA[{query}]]></SQL>"
675669
return connection_string
676670

@@ -709,21 +703,23 @@ def query_sql(self, query: str, parse: bool = True) -> Union[str, pd.DataFrame]:
709703
max_rows=self._max_rows,
710704
datasource=None,
711705
)
712-
res_text = self.fetch_text(url, params=params)
713-
# For now just return result as text regardless of value of parse
706+
707+
res = self.session.get(url, params=params)
708+
res.raise_for_status()
709+
714710
if parse:
715-
dict = res.json()['data'][0]
716-
711+
parsed_dict = res.json()["data"][0]
712+
717713
cols = []
718-
for i in dict['cols']:
719-
cols.append(i['n'])
720-
714+
for i in parsed_dict["cols"]:
715+
cols.append(i["n"])
716+
721717
rows = []
722-
723-
for i in dict['rows']:
718+
719+
for i in parsed_dict["rows"]:
724720
element = []
725-
for j in i['fld']:
726-
element.append(j['v'])
721+
for j in i["fld"]:
722+
element.append(j["v"])
727723
rows.append(element)
728724
return pd.DataFrame(data=rows, columns=cols)
729725
return res.text

0 commit comments

Comments
 (0)