summaryrefslogtreecommitdiff
path: root/python/skytools/parsing.py
diff options
context:
space:
mode:
authorMarko Kreen2008-03-11 20:47:24 +0000
committerMarko Kreen2008-03-11 20:47:24 +0000
commitc73f2559e3a26c31ff1d82b2f55b892e22fcf532 (patch)
treeceba935cceccd8f02d4b334b85c3c923412f7d87 /python/skytools/parsing.py
parent906c5e614fe4c669f73b712487201c5b0a53beec (diff)
Fix bugs in previous commit.
Diffstat (limited to 'python/skytools/parsing.py')
-rw-r--r--python/skytools/parsing.py14
1 files changed, 7 insertions, 7 deletions
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