Skip to content

Commit

Permalink
[修复]subtokens递归重复赋值的操作
Browse files Browse the repository at this point in the history
  • Loading branch information
longfengpili committed Oct 12, 2024
1 parent 652d277 commit 5edf71c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pydbapi/sql/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: longfengpili
# @Date: 2024-10-09 16:33:05
# @Last Modified by: longfengpili
# @Last Modified time: 2024-10-12 10:12:45
# @Last Modified time: 2024-10-12 14:13:22
# @github: https://github.com/longfengpili


Expand Down Expand Up @@ -107,12 +107,14 @@ def tablename(self):
if tables:
return tables[0]

def get_subqueries(self, tokens: list, subtokens: list[Token] = None, subqueries: list[list[Token, ]] = None, keep_last: bool = True):
def get_subqueries(self, tokens: list, subtokens: list[Token] = None, subqueries: list[TokenList, ] = None, keep_last: bool = True):
def append_subquery(subtokens: list, subqueries: list):
subtokens = TokenList(subtokens)
subtoken_first = subtokens.token_first(skip_cm=True)
_subqueries = subtokens.copy()
sub_tokenlist = TokenList(_subqueries)
subtoken_first = sub_tokenlist.token_first(skip_cm=True)
if subtoken_first:
subqueries.append(subtokens)
subqueries.append(sub_tokenlist)
subtokens.clear()

if subqueries is None:
subqueries = []
Expand All @@ -125,19 +127,17 @@ def append_subquery(subtokens: list, subqueries: list):
continue
elif token.ttype in (DML, DDL, CTE):
append_subquery(subtokens, subqueries)
subtokens.append(token)
if token.value.lower() == 'select':
islast = True
subtokens = [token]
elif token.ttype == Punctuation and not islast:
append_subquery(subtokens, subqueries)
subtokens = []
elif isinstance(token, Identifier): # Identifier 也是 TokenList, 所有必须在下个判断之前
subtokens.append(token)
elif isinstance(token, TokenList) or isinstance(token, IdentifierList):
self.get_subqueries(token.tokens, subtokens, subqueries)
else:
subtokens.append(token)

if keep_last:
append_subquery(subtokens, subqueries)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sqlparse
psycopg2-binary
pandas
pymysql
Expand Down

0 comments on commit 5edf71c

Please sign in to comment.