summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2008-03-11 20:47:24 +0000
committerMarko Kreen2008-03-11 20:47:24 +0000
commitc73f2559e3a26c31ff1d82b2f55b892e22fcf532 (patch)
treeceba935cceccd8f02d4b334b85c3c923412f7d87
parent906c5e614fe4c669f73b712487201c5b0a53beec (diff)
Fix bugs in previous commit.
-rw-r--r--python/skytools/_pyquoting.py2
-rw-r--r--python/skytools/parsing.py14
-rw-r--r--python/skytools/quoting.py8
3 files changed, 13 insertions, 11 deletions
diff --git a/python/skytools/_pyquoting.py b/python/skytools/_pyquoting.py
index 2897c7f9..1b143953 100644
--- a/python/skytools/_pyquoting.py
+++ b/python/skytools/_pyquoting.py
@@ -177,7 +177,7 @@ def unquote_literal(val, stdstr = False):
return _esql_rc.sub(_sub_unescape_sqlext, val[1:-1])
elif len(val) > 2 and val[0] in ('E', 'e') and val[1] == "'" and val[-1] == "'":
return _esql_rc.sub(_sub_unescape_sqlext, val[2:-1])
- elif val.tolower() == "null":
+ elif val.lower() == "null":
return None
return val
diff --git a/python/skytools/parsing.py b/python/skytools/parsing.py
index 906c25a9..fd9b9549 100644
--- a/python/skytools/parsing.py
+++ b/python/skytools/parsing.py
@@ -3,7 +3,7 @@
import re
-from skytools.quoting import unescape, unquote_sql_string, unquote_sql_ident
+from skytools.quoting import unescape, unquote_literal, unquote_ident
from skytools.sqltools import dbdict
__all__ = ["parse_pgarray", "parse_logtriga_sql", "parse_tabbed_table", "parse_statements"]
@@ -123,8 +123,8 @@ class _logtriga_parser:
# last sanity check
if len(fields) == 0 or len(fields) != len(values):
raise Exception("syntax error, fields do not match values")
- fields = [unquote_sql_ident(f) for f in fields]
- values = [unquote_sql_string(f) for f in values]
+ fields = [unquote_ident(f) for f in fields]
+ values = [unquote_literal(f) for f in values]
return dbdict(zip(fields, values))
def parse_logtriga_sql(op, sql):
@@ -174,9 +174,9 @@ _base_sql = r"""
| (?P<dolq> (?P<dname> [$] (?: [_a-z][_a-z0-9]*)? [$] )
.*?
(?P=dname) )
- | (?P<num> [0-9][0-9.e]*
+ | (?P<num> [0-9][0-9.e]* )
| (?P<numarg> [$] [0-9]+ )
- | (?P<pyold> [%][(] [a-z0-9_]+ [)][s] | [%][%])
+ | (?P<pyold> [%][(] [a-z0-9_]+ [)][s] | [%][%] )
| (?P<pynew> [{] [^}]+ [}] | [{][{] | [}] [}] )
| (?P<ws> (?: \s+ | [/][*] .*? [*][/] | [-][-][^\n]* )+ )
| (?P<sym> . )"""
@@ -211,7 +211,7 @@ def sql_tokenizer(sql, standard_quoting = False, ignore_whitespace = False):
_copy_from_stdin_re = "copy.*from\s+stdin"
_copy_from_stdin_rc = None
-def parse_statements(sql):
+def parse_statements(sql, standard_quoting = False):
"""Parse multi-statement string into separate statements.
Returns list of statements.
@@ -222,7 +222,7 @@ def parse_statements(sql):
_copy_from_stdin_rc = re.compile(_copy_from_stdin_re, re.X | re.I)
tokens = []
pcount = 0 # '(' level
- for typ, t in _sql_tokenizer(sql):
+ for typ, t in sql_tokenizer(sql, standard_quoting = standard_quoting):
# skip whitespace and comments before statement
if len(tokens) == 0 and typ == "ws":
continue
diff --git a/python/skytools/quoting.py b/python/skytools/quoting.py
index 10492b37..6f686bf8 100644
--- a/python/skytools/quoting.py
+++ b/python/skytools/quoting.py
@@ -5,12 +5,14 @@
import re
__all__ = [
+ # _pyqoting / _cquoting
"quote_literal", "quote_copy", "quote_bytea_raw",
"db_urlencode", "db_urldecode", "unescape",
-
+ "unquote_literal",
+ # local
"quote_bytea_literal", "quote_bytea_copy", "quote_statement",
"quote_ident", "quote_fqident", "quote_json", "unescape_copy",
- "unquote_ident", "unquote_literal",
+ "unquote_ident",
]
try:
@@ -106,7 +108,7 @@ def unescape_copy(val):
return None
return unescape(val)
-def unquote_sql_ident(val):
+def unquote_ident(val):
"""Unquotes possibly quoted SQL identifier."""
if val[0] == '"' and val[-1] == '"':
return val[1:-1].replace('""', '"')