summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2011-09-06 08:01:37 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2011-09-06 08:01:37 +0200
commit62d03c2d3144d3a89d805b95f6d0887aac598260 (patch)
tree076950f554517cd73d242b5c2c6388dce8be4c48 /sqlparse
parentbcaf3269b3a8746a4ee8c848256d5f2b11b25d27 (diff)
parentea9551b5a128508b5d8fb27d727bfd6e45d2042c (diff)
downloadsqlparse-62d03c2d3144d3a89d805b95f6d0887aac598260.tar.gz
Merge.
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/__init__.py6
-rw-r--r--sqlparse/filters.py16
-rw-r--r--sqlparse/pipeline.py31
3 files changed, 49 insertions, 4 deletions
diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py
index 7698e46..5ccf092 100644
--- a/sqlparse/__init__.py
+++ b/sqlparse/__init__.py
@@ -53,3 +53,9 @@ def split(sql):
stack = engine.FilterStack()
stack.split_statements = True
return [unicode(stmt) for stmt in stack.run(sql)]
+
+
+from sqlparse.engine.filter import StatementFilter
+def split2(stream):
+ splitter = StatementFilter()
+ return list(splitter.process(None, stream)) \ No newline at end of file
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index cba7b8f..6f9b579 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -420,7 +420,7 @@ class ColumnsSelect(Filter):
elif mode == 1:
if value == 'FROM':
if oldValue:
- yield Name, oldValue
+ yield oldValue
mode = 3 # Columns have been checked
@@ -431,7 +431,7 @@ class ColumnsSelect(Filter):
elif (token_type == Punctuation
and value == ',' and not parenthesis):
if oldValue:
- yield Name, oldValue
+ yield oldValue
oldValue = ""
elif token_type not in Whitespace:
@@ -446,7 +446,7 @@ class ColumnsSelect(Filter):
elif mode == 2:
# We check also for Keywords because a bug in SQLParse
if token_type == Name or token_type == Keyword:
- yield Name, value
+ yield value
mode = 1
@@ -463,6 +463,14 @@ class SerializerUnicode(Filter):
res += '\n'
return res
+def Tokens2Unicode(stream):
+ result = ""
+
+ for _, value in stream:
+ result += unicode(value)
+
+ return result
+
class OutputPythonFilter(Filter):
@@ -576,4 +584,4 @@ class Limit(Filter):
if index and token_type in Keyword and value == 'LIMIT':
return stream[4 - index][1]
- return -1
+ return -1 \ No newline at end of file
diff --git a/sqlparse/pipeline.py b/sqlparse/pipeline.py
new file mode 100644
index 0000000..34dad19
--- /dev/null
+++ b/sqlparse/pipeline.py
@@ -0,0 +1,31 @@
+# Copyright (C) 2011 Jesus Leganes "piranna", piranna@gmail.com
+#
+# This module is part of python-sqlparse and is released under
+# the BSD License: http://www.opensource.org/licenses/bsd-license.php.
+
+from types import GeneratorType
+
+
+class Pipeline(list):
+ """Pipeline to process filters sequentially"""
+
+ def __call__(self, stream):
+ """Run the pipeline
+
+ Return a static (non generator) version of the result
+ """
+
+ # Run the stream over all the filters on the pipeline
+ for filter in self:
+ # Functions and callable objects (objects with '__call__' method)
+ if callable(filter):
+ stream = filter(stream)
+
+ # Normal filters (objects with 'process' method)
+ else:
+ stream = filter.process(None, stream)
+
+ # If last filter return a generator, staticalize it inside a list
+ if isinstance(stream, GeneratorType):
+ return list(stream)
+ return stream