Fix bugs in previous commit.
authorMarko Kreen <markokr@gmail.com>
Tue, 11 Mar 2008 20:47:24 +0000 (20:47 +0000)
committerMarko Kreen <markokr@gmail.com>
Tue, 11 Mar 2008 20:47:24 +0000 (20:47 +0000)
python/skytools/_pyquoting.py
python/skytools/parsing.py
python/skytools/quoting.py

index 2897c7f9b3cf08d127c9fce9b0137678e19e1510..1b143953cd185fa031d85cfa8323495fe884396a 100644 (file)
@@ -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
 
index 906c25a92285314f58241c34b96b72a081d43368..fd9b9549efb1b76e19db5d62122c5c23cb8b0be5 100644 (file)
@@ -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
index 10492b37d2f4aab0276ea9f4f362b62eccd2e150..6f686bf8d7f260faa7ea9da85d05bb5599d899ec 100644 (file)
@@ -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('""', '"')