diff options
| author | Jesús Leganés Combarro "Piranna" <piranna@gmail.com> | 2012-05-19 22:48:11 +0200 |
|---|---|---|
| committer | Jesús Leganés Combarro "Piranna" <piranna@gmail.com> | 2012-05-19 22:48:11 +0200 |
| commit | 9f717a9b72124231e561fcd190eafeb021c22bdd (patch) | |
| tree | 2bef49977c1ba3cd8b28fae6fb7fb7483c59f8f4 /sqlparse/functions.py | |
| parent | 057864594e126158c23bc8997647f8a43608959c (diff) | |
| parent | 0a43050ab370a90f1036f37bf27b082e40419546 (diff) | |
| download | sqlparse-9f717a9b72124231e561fcd190eafeb021c22bdd.tar.gz | |
Merge branch 'master' into milestone_0.1.5
Diffstat (limited to 'sqlparse/functions.py')
| -rw-r--r-- | sqlparse/functions.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/sqlparse/functions.py b/sqlparse/functions.py new file mode 100644 index 0000000..aaf6fb8 --- /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 not in Whitespace: + return token_type in Keyword and value == self.type |
