当前位置:   article > 正文

python sqlparse_使用sqlparse解析表名、超级强大、支持子查询、左联接等,tablename,leftjoin...

python sqlparse tokens

import sqlparse

from sqlparse.sql import IdentifierList, Identifier

from sqlparse.tokens import Keyword, DML

# 支持的join方式

ALL_JOIN_TYPE = ('LEFT JOIN', 'RIGHT JOIN', 'INNER JOIN', 'FULL JOIN', 'LEFT OUTER JOIN', 'FULL OUTER JOIN')

def is_subselect(parsed):

"""

是否子查询

:param parsed:

:return:

"""

if not parsed.is_group:

return False

for item in parsed.tokens:

if item.ttype is DML and item.value.upper() == 'SELECT':

return True

return False

def extract_from_part(parsed):

"""

提取from之后模块

:param parsed:

:return:

"""

from_seen = False

for item in parsed.tokens:

if from_seen:

if is_subselect(item):

for x

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/540961
推荐阅读
相关标签
  

闽ICP备14008679号