summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2009-04-27 06:10:40 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2009-04-27 06:10:40 +0200
commit5366e32e3bc1f83cf4273776f2efd93212921977 (patch)
tree12c98d3922214535cdba61c0a406e7ce1b91fe55 /sqlparse
parent8ef584ca6ff45bebd2934d712ee33f7c6bb10235 (diff)
downloadsqlparse-5366e32e3bc1f83cf4273776f2efd93212921977.tar.gz
Improved handling of invalid identifiers, like for example "a.".
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/sql.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 3ab93ba..2d94440 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -325,8 +325,24 @@ class Identifier(TokenList):
if dot is None:
return self.token_next_by_type(0, T.Name).value
else:
- return self.token_next_by_type(self.token_index(dot),
- (T.Name, T.Wildcard)).value
+ next_ = self.token_next_by_type(self.token_index(dot),
+ (T.Name, T.Wildcard))
+ if next_ is None: # invalid identifier, e.g. "a."
+ return None
+ return next_.value
+
+ def get_parent_name(self):
+ """Return name of the parent object if any.
+
+ A parent object is identified by the first occuring dot.
+ """
+ dot = self.token_next_match(0, T.Punctuation, '.')
+ if dot is None:
+ return None
+ prev_ = self.token_prev(self.token_index(dot))
+ if prev_ is None: # something must be verry wrong here..
+ return None
+ return prev_.value
def is_wildcard(self):
"""Return ``True`` if this identifier contains a wildcard."""