https://blog.csdn.net/qq_39607437/article/details/79620383

import sqlparse

def look(statement):
print("statement: {}".format(statement))
print("type: {}".format(type(statement)))
for token in statement:
print("{} ------ {} ----- {} ".format(type(token), token.ttype, token.value))
print("\n")
return None string_1 = "select * from history"
string_1_statement = sqlparse.parse(string_1)[0]
look(string_1_statement) string_2 = "select age from history where id = 10"
string_2_statement = sqlparse.parse(string_2)[0]
look(string_2_statement) string_3 = "select count(*) from history where age>10"
string_3_statment = sqlparse.parse(string_3)[0]
look(string_3_statment) string_4 = "select count(age) from history where age>10 and gender='women'"
string_4_statement = sqlparse.parse(string_4)[0]
look(string_4_statement) string_5 = "where id = 10"
string_5_statement = sqlparse.parse(string_5)[0]
look(string_5_statement)
print(string_5_statement.tokens)
print("\n")
look(string_5_statement[0])
look(string_5_statement[0][2]) string_6 = "where age >10 or gender != woman"
string_6_statement = sqlparse.parse(string_6)[0]
look(string_6_statement) # where 语句
look(string_6_statement[0]) # where 语句 是一种tokenlist string_7 = "age >10"
string_7_statement = sqlparse.parse(string_7)[0]
look(string_7_statement)
look(string_7_statement[0]) string_8 = "max(age)>10"
string_8_statement = sqlparse.parse(string_8)[0]
look(string_8_statement)
look(string_8_statement[0])
look(string_8_statement[0][0])
look(string_8_statement[0][0][1]) string_9 = "(age<10 or gender=man) and (age>18 and gender=10)"
string_9_statement = sqlparse.parse(string_9)[0]
look(string_9_statement)
look(string_9_statement[0]) string_10 = "select name as rs from applicant where zhima>557 limit 100, 100;"
string_10_statement = sqlparse.parse(string_10)[0]
look(string_10_statement) string_11 = "/* context_name=cut_age */ select count(*), gender from history where age>18 group by gender;"
string_11_statement = sqlparse.parse(string_11)[0]
look(string_11_statement) string_12 = "select age from applicant where applicant.name=tom"
string_12_statement = sqlparse.parse(string_12)[0]
look(string_12_statement) string_13 = "count(age)"
string_13_statement = sqlparse.parse(string_13)[0]
look(string_13_statement)
look(string_13_statement[0])

python sqlparse 各种 token的更多相关文章

  1. Python SyntaxError: invalid token

    python命名不能以数字开头,import时会报错

  2. Python itsdangerous 生成token和验证token

    代码如下 class AuthToken(object): # 用于处理token信息流程: # 1.更加给定的用户信息生成token # 2.保存生成的token,以便于后面验证 # 3.对用户请求 ...

  3. python接口自动化-token参数关联登录(二)

    原文地址https://www.cnblogs.com/yoyoketang/p/9098096.html 原文地址https://www.cnblogs.com/yoyoketang/p/68866 ...

  4. python接口自动化-token参数关联登录(登录拉勾网)

    前言 登录网站的时候,经常会遇到传token参数,token关联并不难,难的是找出服务器第一次返回token的值所在的位置,取出来后就可以动态关联了 登录拉勾网 1.先找到登录首页https://pa ...

  5. python Web生成token的几种方法,你确定不进来看看?

    1.使用rest_framework_jwt from rest_framework_jwt.settings import api_settings jwt_payload_handler = ap ...

  6. python中使用token模拟登录

    背景:在接口测试中我们经常是需要一个登陆token,或者获取其他用到的参数来关联下一个接口用到的参数. Token的意义及用法 一.Token的来源: 当客户端多次向服务端请求数据时,服务端就需要多次 ...

  7. python, Django csrf token的问题

    环境 Window 7 Python2.7 Django1.4.1 sqlite3 问题 在使用Django搭建好测试环境后,写了一个提交POST表单提交留言的测试页面. 如图: 填写表单,点击“提交 ...

  8. openstack python sdk list tenants get token get servers

    1,openstack python sdk 获取token 获取租户tenants projects #!/bin/bash export OS_PROJECT_DOMAIN_ID=default ...

  9. Python NLP入门教程

    本文简要介绍Python自然语言处理(NLP),使用Python的NLTK库.NLTK是Python的自然语言处理工具包,在NLP领域中,最常使用的一个Python库. 什么是NLP? 简单来说,自然 ...

随机推荐

  1. pacbio bax.h5文件处理及ccs计算

    1.NCBI文件格式如下: 2.格式转换 (1) bas.h5 -> ccs source /share/nas2/genome/biosoft/smrtanalysis/2.3.0/smrta ...

  2. ios MQTT协议的实际应用

    1,创建单视图项目,pod search mqtt找到一个库,然后在项目目录下pod init 出Podfile 2,pod install 安装mqtt库 3,主要代码: #import " ...

  3. [LeetCode&Python] Problem 257. Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...

  4. 洛谷P1357 花园(状态压缩 + 矩阵快速幂加速递推)

    题目链接:传送门 题目: 题目描述 小L有一座环形花园,沿花园的顺时针方向,他把各个花圃编号为1~N(<=N<=^).他的环形花园每天都会换一个新花样,但他的花园都不外乎一个规则,任意相邻 ...

  5. 一台服务器绑定多个ip地址

    一台服务器绑定多个ip地址. 方法一: 使用标准的网络配置工具(比如ifconfig和route命令)添加lP别名: 在eth0网卡再绑定一个ip:192.168.101.103 /sbin/ifco ...

  6. 百度地图 JavaScript API

    最近有点懒  项目结尾了  完了好长时间 没有去总结项目中的问题 想了下还是写写吧 这是一个关于百度地图的 网页展示 <!DOCTYPE html><html><head ...

  7. Go并发编程实战 (郝林 著)

    第1章 初识Go语言 1.1 语言特性 1.2 安装和设置 1.3 工程构造 1.3.1 工作区 1.3.2 GOPATH 1.3.3 源码文件 package main import ( " ...

  8. sqluldr2 学习心得

    前言 最近正在做一个项目,需要导出数据库中的表,单数数据库中有很多带有虚拟列的表,而且表中的数据非常的庞大,有些表中的数据上亿条,项目经理让我研究如何快速导出这些数据. 下面是我研究的一些经历: (1 ...

  9. redis的内存优化【转】

    Redis所有的数据都在内存中,而内存又是非常宝贵的资源.对于如何优化内存使用一直是Redis用户非常关注的问题.本文让我们深入到Redis细节中,学习内存优化的技巧.分为如下几个部分: 一.redi ...

  10. nginx屏蔽某段IP、某个国家的IP

    nginx中可通过写入配置文件的方法来达到一定的过滤IP作用,可使用deny来写. deny的使用方法可用于前端服务器无防护设备的时候过滤一些异常IP,过滤的client ip会被禁止再次访问,起到一 ...