Skip to content

Commit

Permalink
fix for 702
Browse files Browse the repository at this point in the history
  • Loading branch information
pooja1pathak committed Jun 5, 2024
1 parent 270a4e2 commit 0b66fc8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### New features

- Added escaping in crate-exporter.py (#702)

### Bug fixes

- Fix to return OK/200 and an empty result set when no data found (#720)
Expand Down
31 changes: 25 additions & 6 deletions timescale-container/crate-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,42 @@ def get(self):
class CrateSql:
"""Crate SQL utilities."""

@staticmethod
def escape_single_quote(x: str) -> str:
"""
Single quote escaping for Postres strings: replace any single quote
with two single quotes. E.g. x'y'z ~~~> x''y''z
"""
return x.replace("'", "''")

@staticmethod
def escape_double_quote(x: str) -> str:
"""
Double quote escaping for Postres quoted identifiers: replace any
double quote with two double quotes. E.g. x"y"z ~~~> x""y""z
"""
return x.replace('"', '""')

@staticmethod
def to_string(x) -> str:
"""
Convert the input into a Crate string.
Convert the input into a Crate string, escaping if needed.
E.g. input ~~~> 'input'
in'put ~~~> 'in''put'
"""
v = str(x) # TODO consider escaping?
return f"'{v}'"
escaped = CrateSql.escape_single_quote(str(x))
return f"'{escaped}'"

@staticmethod
def to_quoted_identifier(x) -> str:
"""
Convert the input into a Crate quoted identifier.
Convert the input into a Crate quoted identifier, escaping if
needed.
E.g. input ~~~> "input"
in"put ~~~> "in""put"
"""
v = str(x) # TODO consider escaping?
return f'"{v}"'
escaped = CrateSql.escape_double_quote(str(x))
return f'"{escaped}"'


class CrateTableIdentifier:
Expand Down

0 comments on commit 0b66fc8

Please sign in to comment.