Skip to content

Commit fc8bf2f

Browse files
committed
minor fixups, add backtick quoted identifiers
1 parent 39e44bb commit fc8bf2f

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

countess/utils/expression_to_sql.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def sql(self):
8989

9090

9191
class DoubleQuotedStringLiteral(SqlTemplatingSymbol):
92-
regex = re.compile(r'"(?:\\.|[^"\n])*"')
92+
regex = re.compile(r'"[^"\\]*(?:\\.[^"\\]*)*"')
9393

9494
def sql(self):
9595
return duckdb_escape_literal(self.name[1:-1])
@@ -102,6 +102,13 @@ def sql(self):
102102
return duckdb_escape_identifier(self.name)
103103

104104

105+
class BacktickQuotedLabel(SqlTemplatingSymbol):
106+
regex = re.compile(r"`(?:\\.|[^`\n])*`")
107+
108+
def sql(self):
109+
return duckdb_escape_identifier(self.name[1:-1])
110+
111+
105112
class SqlTemplatingList(pypeg2.List):
106113
before = ""
107114
between = ""
@@ -122,7 +129,7 @@ class FunctionCall(pypeg2.Concat):
122129

123130
def sql(self):
124131
func_name = str(self[0].name).upper()
125-
func_params = ", ".join(s.sql() for s in self[1:])
132+
func_params = ",".join(s.sql() for s in self[1:])
126133

127134
if func_name in LIST_OPS:
128135
return f"LIST_{func_name}([{func_params}])"
@@ -136,6 +143,7 @@ class Value(pypeg2.Concat):
136143
BooleanLiteral,
137144
NullLiteral,
138145
Label,
146+
BacktickQuotedLabel,
139147
DecimalLiteral,
140148
IntegerLiteral,
141149
SingleQuotedStringLiteral,

tests/plugins/test_expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
code_2 = "__filter = bar + baz != 11"
2525

26-
code_3 = "qux = foo + bar + baz\n\nfoo = None\n\nbar = None if qux else 0"
26+
code_3 = "qux = foo + bar + baz\n\nfoo = None\n\nbar = 1 if qux else 0"
2727

2828

2929
def test_expr_1():

0 commit comments

Comments
 (0)