Python sqlparse.tokens.Error() Examples
The following are 5
code examples of sqlparse.tokens.Error().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlparse.tokens
, or try the search function
.
Example #1
Source File: utils.py From pgcli with BSD 3-Clause "New" or "Revised" License | 8 votes |
def parse_partial_identifier(word): """Attempt to parse a (partially typed) word as an identifier word may include a schema qualification, like `schema_name.partial_name` or `schema_name.` There may also be unclosed quotation marks, like `"schema`, or `schema."partial_name` :param word: string representing a (partially complete) identifier :return: sqlparse.sql.Identifier, or None """ p = sqlparse.parse(word)[0] n_tok = len(p.tokens) if n_tok == 1 and isinstance(p.tokens[0], Identifier): return p.tokens[0] elif p.token_next_by(m=(Error, '"'))[1]: # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar' # Close the double quote, then reparse return parse_partial_identifier(word + '"') else: return None
Example #2
Source File: utils.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 6 votes |
def parse_partial_identifier(word): """Attempt to parse a (partially typed) word as an identifier word may include a schema qualification, like `schema_name.partial_name` or `schema_name.` There may also be unclosed quotation marks, like `"schema`, or `schema."partial_name` :param word: string representing a (partially complete) identifier :return: sqlparse.sql.Identifier, or None """ p = sqlparse.parse(word)[0] n_tok = len(p.tokens) if n_tok == 1 and isinstance(p.tokens[0], Identifier): return p.tokens[0] if p.token_next_by(m=(Error, '"'))[1]: # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar' # Close the double quote, then reparse return parse_partial_identifier(word + '"') return None
Example #3
Source File: utils.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _parsed_is_open_quote(parsed): # Look for unmatched single quotes, or unmatched dollar sign quotes return any(tok.match(Token.Error, ("'", "$")) for tok in parsed.flatten())
Example #4
Source File: utils.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _parsed_is_open_quote(parsed): # Look for unmatched single quotes, or unmatched dollar sign quotes return any(tok.match(Token.Error, ("'", '"', "$")) for tok in parsed.flatten())
Example #5
Source File: lexer.py From SublimeText-SQLTools with GNU General Public License v3.0 | 4 votes |
def get_tokens(text, encoding=None): """ Return an iterable of (tokentype, value) pairs generated from `text`. If `unfiltered` is set to `True`, the filtering mechanism is bypassed even if filters are defined. Also preprocess the text, i.e. expand tabs and strip it if wanted and applies registered filters. Split ``text`` into (tokentype, text) pairs. ``stack`` is the inital stack (default: ``['root']``) """ if isinstance(text, file_types): text = text.read() if isinstance(text, text_type): pass elif isinstance(text, bytes_type): if encoding: text = text.decode(encoding) else: try: text = text.decode('utf-8') except UnicodeDecodeError: text = text.decode('unicode-escape') else: raise TypeError(u"Expected text or file-like object, got {!r}". format(type(text))) iterable = enumerate(text) for pos, char in iterable: for rexmatch, action in SQL_REGEX: m = rexmatch(text, pos) if not m: continue elif isinstance(action, tokens._TokenType): yield action, m.group() elif callable(action): yield action(m.group()) consume(iterable, m.end() - pos - 1) break else: yield tokens.Error, char