summaryrefslogtreecommitdiff
path: root/sqlparse/functions.py
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-05-17 23:11:05 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-05-17 23:11:05 +0200
commit73465819c9d5105f57a9cf5579c5dc78964b37e4 (patch)
tree012eea899112ce6dc8d08af984b7817859b1a42b /sqlparse/functions.py
parentc45e0c62373407544c089ada7240c99da79ff29e (diff)
downloadsqlparse-73465819c9d5105f57a9cf5579c5dc78964b37e4.tar.gz
Added functions from AntiORM
Diffstat (limited to 'sqlparse/functions.py')
-rw-r--r--sqlparse/functions.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/sqlparse/functions.py b/sqlparse/functions.py
new file mode 100644
index 0000000..693fe6a
--- /dev/null
+++ b/sqlparse/functions.py
@@ -0,0 +1,44 @@
+'''
+Created on 17/05/2012
+
+@author: piranna
+
+Several utility functions to extract info from the SQL sentences
+'''
+
+from sqlparse.filters import ColumnsSelect, Limit
+from sqlparse.pipeline import Pipeline
+from sqlparse.tokens import Keyword, Whitespace
+
+
+def GetLimit(stream):
+ """Function that return the LIMIT of a input SQL """
+ pipe = Pipeline()
+
+ pipe.append(Limit())
+
+ result = pipe(stream)
+ try:
+ return int(result)
+ except ValueError:
+ return result
+
+
+def GetColumns(stream):
+ """Function that return the colums of a SELECT query"""
+ pipe = Pipeline()
+
+ pipe.append(ColumnsSelect())
+
+ return pipe(stream)
+
+
+class IsType():
+ """Functor that return is the statement is of a specific type"""
+ def __init__(self, type):
+ self.type = type
+
+ def __call__(self, stream):
+ for token_type, value in stream:
+ if token_type in Whitespace: continue
+ return token_type in Keyword and value == self.type