summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2013-06-29 19:12:53 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2013-06-29 19:14:58 +0200
commit84725ee64570622135bf68d87823643b826d05b6 (patch)
treed340ae595b2a22c31fa192df6806c3f412fb76a9
parent4edfd2fe0ac4e6aca1ee014ea47f9d6b13bfcfbe (diff)
downloadsqlparse-84725ee64570622135bf68d87823643b826d05b6.tar.gz
Improve parsing of PEP249-style placeholder (fixes #103).
-rw-r--r--CHANGES1
-rw-r--r--sqlparse/lexer.py1
-rw-r--r--tests/test_parse.py11
3 files changed, 13 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 39beee4..56cf249 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@ Enhancements
* sqlparse.split() now removes leading and trailing whitespaces from splitted
statements.
* Add USE as keyword token (by mulos).
+* Improve parsing of PEP249-style placeholders (issue103).
Release 0.1.7 (Apr 06, 2013)
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index 8b61fc1..00d0462 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -182,6 +182,7 @@ class Lexer(object):
(r"´(´´|[^´])*´", tokens.Name),
(r'\$([^\W\d]\w*)?\$', tokens.Name.Builtin),
(r'\?{1}', tokens.Name.Placeholder),
+ (r'%\(\w+\)s', tokens.Name.Placeholder),
(r'[$:?%]\w+', tokens.Name.Placeholder),
# FIXME(andi): VALUES shouldn't be listed here
# see https://github.com/andialbrecht/sqlparse/pull/64
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 7016af9..10da8e1 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -2,11 +2,15 @@
"""Tests sqlparse function."""
+import pytest
+
from tests.utils import TestCaseBase
import sqlparse
import sqlparse.sql
+from sqlparse import tokens as T
+
class SQLParseTest(TestCaseBase):
"""Tests sqlparse.parse()."""
@@ -139,3 +143,10 @@ def test_psql_quotation_marks(): # issue83
....
$PROC_2$ LANGUAGE plpgsql;""")
assert len(t) == 2
+
+
+@pytest.mark.parametrize('ph', ['?', ':1', ':foo', '%s', '%(foo)s'])
+def test_placeholder(ph):
+ p = sqlparse.parse(ph)[0].tokens
+ assert len(p) == 1
+ assert p[0].ttype is T.Name.Placeholder