1
0
Fork 0

Adding upstream version 20.4.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 21:18:16 +01:00
parent fd9de5e4cb
commit 943dfc0887
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
20 changed files with 562 additions and 52 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import logging
import re
import typing as t
from collections import defaultdict
from functools import reduce
@ -17,6 +18,8 @@ if t.TYPE_CHECKING:
logger = logging.getLogger("sqlglot")
ESCAPED_UNICODE_RE = re.compile(r"\\(\d+)")
class Generator:
"""
@ -917,11 +920,19 @@ class Generator:
def unicodestring_sql(self, expression: exp.UnicodeString) -> str:
this = self.sql(expression, "this")
escape = expression.args.get("escape")
if self.dialect.UNICODE_START:
escape = self.sql(expression, "escape")
escape = f" UESCAPE {escape}" if escape else ""
escape = f" UESCAPE {self.sql(escape)}" if escape else ""
return f"{self.dialect.UNICODE_START}{this}{self.dialect.UNICODE_END}{escape}"
return this
if escape:
pattern = re.compile(rf"{escape.name}(\d+)")
else:
pattern = ESCAPED_UNICODE_RE
this = pattern.sub(r"\\u\1", this)
return f"{self.dialect.QUOTE_START}{this}{self.dialect.QUOTE_END}"
def rawstring_sql(self, expression: exp.RawString) -> str:
string = self.escape_str(expression.this.replace("\\", "\\\\"))