summaryrefslogtreecommitdiff
path: root/sqlparse
Commit message (Collapse)AuthorAgeFilesLines
* Move file_types list to compat module.Andi Albrecht2016-08-102-9/+6
|
* Merge pull request #279 from phdru/issue-190Vik2016-08-051-1/+7
|\ | | | | closes #190
| * Fix a bug: recognize file (Python 2) as a streamOleg Broytman2016-08-061-1/+7
| |
* | Avoid double apostrophesOleg Broytman2016-08-061-2/+11
|/ | | | | | | | If the value is Single it's already quoted with apostrophes. Avoid double apostrophes it that case by using double-quotes instead. For example, if the value is 'value' the output is "'value'" instead of ''value''.
* Fix parsing of streams (fixes #273).Andi Albrecht2016-07-221-1/+3
|
* Switch back to development version.Andi Albrecht2016-07-201-1/+1
|
* Bump version to 0.2.0.0.2.0Andi Albrecht2016-07-201-1/+1
|
* Cleanup: Don't redefine underscore.Andi Albrecht2016-07-201-1/+1
|
* Format keywords.pyVictor Uriarte2016-06-281-2/+4
|
* Merge pull request #269 from dlenski/oracle-11g-keywordsVik2016-06-281-1/+134
|\ | | | | add all Oracle 11g reserved words that aren't already in sqlparse.keywords
| * add all Oracle 11g NON-RESERVED keywords (in a separate dict, as @vmuriart ↵Dan Lenski2016-06-281-1/+106
| | | | | | | | suggested)
| * I think ROWID, ROWLABEL, ROWNUM, and SYSDATE should be classified as ↵Dan Lenski2016-06-261-4/+4
| | | | | | | | Name.Builtin rather than Keyword, since they are identifier-like
| * add all Oracle 11g reserved words that aren't already in sqlparse.keywordsDan Lenski2016-06-261-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Oracle has at least three categories of keywords: 1. reserved words (can't be used in unquoted identifiers) 2. "non-reserved" keywords (which have a specific syntactic meaning, but which *can* be used in unquoted identifiers… which is insane) 3. reserved words which are specific to PL/SQL (so probably shouldn't be considered special by sqlparse) This PR adds everything from #1 which sqlparse didn't already include. Some of these are used in other SQL databases as well (e.g. SYNONYM, ENABLE, DISABLE) while most are Oracle-specific. I referred to the Oracle 11g docs for these lists: http://docs.oracle.com/cd/B28359_01/appdev.111/b31231/appb.htm#BABGHAFH And I used the following script to find the ones that were missing from sqlparse: import sqlparse import textwrap # Oracle 11g reserved words: http://docs.oracle.com/cd/B28359_01/appdev.111/b31231/appb.htm#BABGHAFH reserved = { 'ACCESS', 'ELSE', 'MODIFY', 'START', 'ADD', 'EXCLUSIVE', 'NOAUDIT', 'SELECT', 'ALL', 'EXISTS', 'NOCOMPRESS', 'SESSION', 'ALTER', 'FILE', 'NOT', 'SET', 'AND', 'FLOAT', 'NOTFOUND', 'SHARE', 'ANY', 'FOR', 'NOWAIT', 'SIZE', 'ARRAYLEN', 'FROM', 'NULL', 'SMALLINT', 'AS', 'GRANT', 'NUMBER', 'SQLBUF', 'ASC', 'GROUP', 'OF', 'SUCCESSFUL', 'AUDIT', 'HAVING', 'OFFLINE', 'SYNONYM', 'BETWEEN', 'IDENTIFIED', 'ON', 'SYSDATE', 'BY', 'IMMEDIATE', 'ONLINE', 'TABLE', 'CHAR', 'IN', 'OPTION', 'THEN', 'CHECK', 'INCREMENT', 'OR', 'TO', 'CLUSTER', 'INDEX', 'ORDER', 'TRIGGER', 'COLUMN', 'INITIAL', 'PCTFREE', 'UID', 'COMMENT', 'INSERT', 'PRIOR', 'UNION', 'COMPRESS', 'INTEGER', 'PRIVILEGES', 'UNIQUE', 'CONNECT', 'INTERSECT', 'PUBLIC', 'UPDATE', 'CREATE', 'INTO', 'RAW', 'USER', 'CURRENT', 'IS', 'RENAME', 'VALIDATE', 'DATE', 'LEVEL', 'RESOURCE', 'VALUES', 'DECIMAL', 'LIKE', 'REVOKE', 'VARCHAR', 'DEFAULT', 'LOCK', 'ROW', 'VARCHAR2', 'DELETE', 'LONG', 'ROWID', 'VIEW', 'DESC', 'MAXEXTENTS', 'ROWLABEL', 'WHENEVER', 'DISTINCT', 'MINUS', 'ROWNUM', 'WHERE', 'DROP', 'MODE', 'ROWS', 'WITH', } # Oracle 11g "non-reserved" keywords (don't blame me, I didn't come up with this insane concept): # http://docs.oracle.com/cd/B28359_01/appdev.111/b31231/appb.htm#BABHJHFE keywords = { 'ADMIN', 'CURSOR', 'FOUND', 'MOUNT', 'AFTER', 'CYCLE', 'FUNCTION', 'NEXT', 'ALLOCATE', 'DATABASE', 'GO', 'NEW', 'ANALYZE', 'DATAFILE', 'GOTO', 'NOARCHIVELOG', 'ARCHIVE', 'DBA', 'GROUPS', 'NOCACHE', 'ARCHIVELOG', 'DEC', 'INCLUDING', 'NOCYCLE', 'AUTHORIZATION', 'DECLARE', 'INDICATOR', 'NOMAXVALUE', 'AVG', 'DISABLE', 'INITRANS', 'NOMINVALUE', 'BACKUP', 'DISMOUNT', 'INSTANCE', 'NONE', 'BEGIN', 'DOUBLE', 'INT', 'NOORDER', 'BECOME', 'DUMP', 'KEY', 'NORESETLOGS', 'BEFORE', 'EACH', 'LANGUAGE', 'NORMAL', 'BLOCK', 'ENABLE', 'LAYER', 'NOSORT', 'BODY', 'END', 'LINK', 'NUMERIC', 'CACHE', 'ESCAPE', 'LISTS', 'OFF', 'CANCEL', 'EVENTS', 'LOGFILE', 'OLD', 'CASCADE', 'EXCEPT', 'MANAGE', 'ONLY', 'CHANGE', 'EXCEPTIONS', 'MANUAL', 'OPEN', 'CHARACTER', 'EXEC', 'MAX', 'OPTIMAL', 'CHECKPOINT', 'EXPLAIN', 'MAXDATAFILES', 'OWN', 'CLOSE', 'EXECUTE', 'MAXINSTANCES', 'PACKAGE', 'COBOL', 'EXTENT', 'MAXLOGFILES', 'PARALLEL', 'COMMIT', 'EXTERNALLY', 'MAXLOGHISTORY', 'PCTINCREASE', 'COMPILE', 'FETCH', 'MAXLOGMEMBERS', 'PCTUSED', 'CONSTRAINT', 'FLUSH', 'MAXTRANS', 'PLAN', 'CONSTRAINTS', 'FREELIST', 'MAXVALUE', 'PLI', 'CONTENTS', 'FREELISTS', 'MIN', 'PRECISION', 'CONTINUE', 'FORCE', 'MINEXTENTS', 'PRIMARY', 'CONTROLFILE', 'FOREIGN', 'MINVALUE', 'PRIVATE', 'COUNT', 'FORTRAN', 'MODULE', 'PROCEDURE', 'PROFILE', 'SAVEPOINT', 'SQLSTATE', 'TRACING', 'QUOTA', 'SCHEMA', 'STATEMENT_ID', 'TRANSACTION', 'READ', 'SCN', 'STATISTICS', 'TRIGGERS', 'REAL', 'SECTION', 'STOP', 'TRUNCATE', 'RECOVER', 'SEGMENT', 'STORAGE', 'UNDER', 'REFERENCES', 'SEQUENCE', 'SUM', 'UNLIMITED', 'REFERENCING', 'SHARED', 'SWITCH', 'UNTIL', 'RESETLOGS', 'SNAPSHOT', 'SYSTEM', 'USE', 'RESTRICTED', 'SOME', 'TABLES', 'USING', 'REUSE', 'SORT', 'TABLESPACE', 'WHEN', 'ROLE', 'SQL', 'TEMPORARY', 'WRITE', 'ROLES', 'SQLCODE', 'THREAD', 'WORK', 'ROLLBACK', 'SQLERROR', 'TIME' } # Oracle 11g reserved words for PL/SQL only: # http://docs.oracle.com/cd/B28359_01/appdev.111/b31231/appb.htm#BABDFFBA plsql_reserved = { 'ABORT', 'BETWEEN', 'CRASH', 'DIGITS', 'ACCEPT', 'BINARY_INTEGER', 'CREATE', 'DISPOSE', 'ACCESS', 'BODY', 'CURRENT', 'DISTINCT', 'ADD', 'BOOLEAN', 'CURRVAL', 'DO', 'ALL', 'BY', 'CURSOR', 'DROP', 'ALTER', 'CASE', 'DATABASE', 'ELSE', 'AND', 'CHAR', 'DATA_BASE', 'ELSIF', 'ANY', 'CHAR_BASE', 'DATE', 'END', 'ARRAY', 'CHECK', 'DBA', 'ENTRY', 'ARRAYLEN', 'CLOSE', 'DEBUGOFF', 'EXCEPTION', 'AS', 'CLUSTER', 'DEBUGON', 'EXCEPTION_INIT', 'ASC', 'CLUSTERS', 'DECLARE', 'EXISTS', 'ASSERT', 'COLAUTH', 'DECIMAL', 'EXIT', 'ASSIGN', 'COLUMNS', 'DEFAULT', 'FALSE', 'AT', 'COMMIT', 'DEFINITION', 'FETCH', 'AUTHORIZATION', 'COMPRESS', 'DELAY', 'FLOAT', 'AVG', 'CONNECT', 'DELETE', 'FOR', 'BASE_TABLE', 'CONSTANT', 'DELTA', 'FORM', 'BEGIN', 'COUNT', 'DESC', 'FROM', 'FUNCTION', 'NEW', 'RELEASE', 'SUM', 'GENERIC', 'NEXTVAL', 'REMR', 'TABAUTH', 'GOTO', 'NOCOMPRESS', 'RENAME', 'TABLE', 'GRANT', 'NOT', 'RESOURCE', 'TABLES', 'GROUP', 'NULL', 'RETURN', 'TASK', 'HAVING', 'NUMBER', 'REVERSE', 'TERMINATE', 'IDENTIFIED', 'NUMBER_BASE', 'REVOKE', 'THEN', 'IF', 'OF', 'ROLLBACK', 'TO', 'IN', 'ON', 'ROWID', 'TRUE', 'INDEX', 'OPEN', 'ROWLABEL', 'TYPE', 'INDEXES', 'OPTION', 'ROWNUM', 'UNION', 'INDICATOR', 'OR', 'ROWTYPE', 'UNIQUE', 'INSERT', 'ORDER', 'RUN', 'UPDATE', 'INTEGER', 'OTHERS', 'SAVEPOINT', 'USE', 'INTERSECT', 'OUT', 'SCHEMA', 'VALUES', 'INTO', 'PACKAGE', 'SELECT', 'VARCHAR', 'IS', 'PARTITION', 'SEPARATE', 'VARCHAR2', 'LEVEL', 'PCTFREE', 'SET', 'VARIANCE', 'LIKE', 'POSITIVE', 'SIZE', 'VIEW', 'LIMITED', 'PRAGMA', 'SMALLINT', 'VIEWS', 'LOOP', 'PRIOR', 'SPACE', 'WHEN', 'MAX', 'PRIVATE', 'SQL', 'WHERE', 'MIN', 'PROCEDURE', 'SQLCODE', 'WHILE', 'MINUS', 'PUBLIC', 'SQLERRM', 'WITH', 'MLSLABEL', 'RAISE', 'START', 'WORK', 'MOD', 'RANGE', 'STATEMENT', 'XOR', 'MODE', 'REAL', 'STDDEV', 'NATURAL', 'RECORD', 'SUBTYPE' } - reserved for batch, name in ((reserved, 'Oracle 11g reserved words'), (keywords, 'Oracle 11g "non-reserved" keywords'), (plsql_reserved, 'Oracle 11g reserved words for PL/SQL only'),): missing = batch - set(sqlparse.keywords.KEYWORDS) - set(sqlparse.keywords.KEYWORDS_COMMON) if missing: print("{} out of {} {} are missing from sqlparse.keywords.KEYWORDS (v{}):".format(len(missing), len(batch), name, sqlparse.__version__)) print(textwrap.fill(repr(missing), initial_indent=' ', subsequent_indent=' ')) else: print("All {} {} are in from sqlparse.keywords.KEYWORDS (v{}).".format(len(batch), name, sqlparse.__version__))
* | Returning clause ends where clauseDarik Gamble2016-06-251-1/+1
| |
* | Add RETURNING keywordDarik Gamble2016-06-241-0/+1
| |
* | Format cli.py and add cli-testsVictor Uriarte2016-06-201-7/+5
| |
* | token_next shouldn't ignore skip_cmDarik Gamble2016-06-201-19/+7
| |
* | Previous fix for period failed when another token (non-groupable) followed.Victor Uriarte2016-06-191-3/+8
| |
* | Revert behavior of dangling period(hanging schema qualifier)Victor Uriarte2016-06-181-2/+2
| | | | | | | | | | | | Related to #261. Reverting to previous behavior until a way to handle behavior/grouping of invalid sql is agreed upon.
* | Misc. small code clean-up/commentsVictor Uriarte2016-06-183-4/+4
| |
* | Merge pull request #260 from vmuriart/long_live_indexesVik2016-06-166-293/+405
|\ \ | | | | | | Long live indexes - Improve performance
| * | Change group_matching back to idxVictor Uriarte2016-06-151-6/+16
| | |
| * | remove group left_rightVictor Uriarte2016-06-151-27/+0
| | |
| * | Change grouping from _left_right to _groupVictor Uriarte2016-06-151-18/+71
| | |
| * | remove extra recurse and rename varsVictor Uriarte2016-06-151-30/+43
| | | | | | | | | | | | | | | # Conflicts: # sqlparse/engine/grouping.py
| * | Refactor _group's prev token logicVictor Uriarte2016-06-151-13/+11
| | |
| * | Reduce calls by _group to get tk idxVictor Uriarte2016-06-151-4/+15
| | |
| * | Re-Write grouping functionsVictor Uriarte2016-06-151-29/+47
| | |
| * | Reorder grouping code and func call orderVictor Uriarte2016-06-151-67/+66
| | | | | | | | | | | | Remove repeated for-each/for grouping
| * | Make use of token_index more obviousVictor Uriarte2016-06-153-15/+9
| | |
| * | Normalize behavior between token_next and token_next_byVictor Uriarte2016-06-155-26/+26
| | | | | | | | | | | | both will now return the "next" token and not itself when passing own index
| * | Rename token_idx_ funcs to simply token_ funcsVictor Uriarte2016-06-155-98/+98
| | |
| * | Remove functions no-longer usedVictor Uriarte2016-06-152-63/+0
| | |
| * | Change token_ funcs to token_idx funcsVictor Uriarte2016-06-155-130/+160
| | |
| * | Change argument order to match order of all other functionsVictor Uriarte2016-06-142-3/+4
| | |
| * | Refactor _group_matchingVictor Uriarte2016-06-141-17/+13
| | |
| * | Apply alt style for grouping left/rightVictor Uriarte2016-06-141-7/+9
| | |
| * | Reapply fix for case within paranthesisVictor Uriarte2016-06-141-1/+3
| | |
| * | Remove unused code from sql.py and style up some changesVictor Uriarte2016-06-141-38/+7
| | |
| * | Merge remote-tracking branch 'core/long_live_indexes' into developVictor Uriarte2016-06-143-69/+175
| |\ \ | | |/ | |/|
| | * Use a specialized token_idx_next.Sjoerd Job Postmus2016-06-122-4/+24
| | | | | | | | | | | | Prevent calling token_index.
| | * Index-based token_idx_prevSjoerd Job Postmus2016-06-122-8/+25
| | | | | | | | | | | | | | | Prevent some more calls to token_index in group_identifier_list. They are now all gone.
| | * Use specialized token_idx_next_by in group_aliased.Sjoerd Job Postmus2016-06-122-6/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The method group_aliased was making a lot of calls to token_index. By specializing token_next_by to token_idx_next_by, the calls to token_index became superfluous. Also use token_idx_next_by in group_identifier_list. It was making a lot of calls, which is now more than reduced in half.
| | * Re-use token index in group_identifier.Sjoerd Job Postmus2016-06-121-8/+13
| | |
| | * Replace _group_matching with an inward-out grouping algorithmSjoerd Job Postmus2016-06-123-13/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All the matching between open/close was done all the time, first finding the matching closing token, and then grouping the tokens in between, and recurse over the newly created list. Instead, it is more efficient to look for the previous open-token on finding a closing-token, group these two together, and then continue on. squashed: Handle token indices in group_tokens_between and find_matching.
| | * Special-case group_tokens(..., tokens_between())Sjoerd Job Postmus2016-06-122-24/+37
| | | | | | | | | | | | | | | | | | When having been guaranteed that the tokens form a range, it is possible to get rid of a lot of calls to `Token.tokens.remove(...)` which are expensive.
| | * Call `Token`-methods index based.Sjoerd Job Postmus2016-06-122-25/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A lot of methods have token-to-idx magic due to `Token._find_matching` converting tokens to indexes. Unknowingly, this turns innocent looking algorithms into O(n^2) (or worse). This does not solve the problem, but makes it more clear by moving the call to `Token.token_index` obvious at the call-site, at the cost of repeating it over-and-over.
* | | Separate __main__ and main() to allow for testingVictor Uriarte2016-06-153-136/+173
| | | | | | | | | | | | | | | Also reference example in: https://github.com/ionelmc/cookiecutter-pylibrary
* | | Clarify `split` text processing on __init__.pyVictor Uriarte2016-06-151-2/+2
| | |
* | | Correct argparse --version flag for py3.Victor Uriarte2016-06-151-2/+7
|/ /