summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <jesus.lc@vaelsys.com>2012-05-17 16:52:01 +0200
committerJesús Leganés Combarro "Piranna" <jesus.lc@vaelsys.com>2012-05-17 16:52:01 +0200
commitf141b2d344bbd09a7469d5c9ecffb38ed6ccd618 (patch)
tree5888f2f601bab879173dfaa9bf91e142dd0800e2 /sqlparse
parent93eb88cbc88d239e70268b98ab9a96236c73efee (diff)
downloadsqlparse-f141b2d344bbd09a7469d5c9ecffb38ed6ccd618.tar.gz
Raise exception on INCLUDE loading failure
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 8430687..e17766d 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -92,12 +92,13 @@ def StripWhitespace(stream):
class IncludeStatement:
"""Filter that enable a INCLUDE statement"""
- def __init__(self, dirpath=".", maxRecursive=10):
+ def __init__(self, dirpath=".", maxRecursive=10, raiseonload=False):
if maxRecursive <= 0:
raise ValueError('Max recursion limit reached')
self.dirpath = abspath(dirpath)
self.maxRecursive = maxRecursive
+ self.raiseonload = raiseonload
self.detected = False
@@ -127,15 +128,22 @@ class IncludeStatement:
raw_sql = f.read()
f.close()
except IOError, err:
+ # Raise the exception to the interpreter
+ if self.raiseonload:
+ raise
+
+ # Put the exception as a comment on the SQL code
yield Comment, u'-- IOError: %s\n' % err
else:
# Create new FilterStack to parse readed file
# and add all its tokens to the main stack recursively
- # [ToDo] Add maximum recursive iteration value
+ filtr = IncludeStatement(self.dirpath,
+ self.maxRecursive - 1,
+ self.raiseonload)
+
stack = FilterStack()
- stack.preprocess.append(IncludeStatement(self.dirpath,
- self.maxRecursive - 1))
+ stack.preprocess.append(filtr)
for tv in stack.run(raw_sql):
yield tv