mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-02-19 18:00:32 +03:00
Greatly improve performance when inserting large strings (credit to M1hacka for identifying the problem)
This commit is contained in:
parent
7145984797
commit
ec99044fab
|
@ -6,6 +6,7 @@ Unreleased
|
|||
- Add support for ReplacingMergeTree (leenr)
|
||||
- Fix problem with SELECT WITH TOTALS (pilosus)
|
||||
- Update serialization format of DateTimeField to 10 digits, zero padded (nikepan)
|
||||
- Greatly improve performance when inserting large strings (credit to M1hacka for identifying the problem)
|
||||
|
||||
v0.8.0
|
||||
------
|
||||
|
|
|
@ -17,15 +17,18 @@ SPECIAL_CHARS = {
|
|||
SPECIAL_CHARS_REGEX = re.compile("[" + ''.join(SPECIAL_CHARS.values()) + "]")
|
||||
|
||||
|
||||
|
||||
def escape(value, quote=True):
|
||||
'''
|
||||
If the value is a string, escapes any special characters and optionally
|
||||
surrounds it with single quotes. If the value is not a string (e.g. a number),
|
||||
converts it to one.
|
||||
'''
|
||||
def escape_one(match):
|
||||
return SPECIAL_CHARS[match.group(0)]
|
||||
|
||||
if isinstance(value, string_types):
|
||||
if SPECIAL_CHARS_REGEX.search(value):
|
||||
value = "".join(SPECIAL_CHARS.get(c, c) for c in value)
|
||||
value = SPECIAL_CHARS_REGEX.sub(escape_one, value)
|
||||
if quote:
|
||||
value = "'" + value + "'"
|
||||
return text_type(value)
|
||||
|
|
Loading…
Reference in New Issue
Block a user