我正在尝试验证更新或在Shell脚本中选择查询。
例如,我的查询是:
update table_name set col_name = 1 where emp_id = '1234'
如果代码将验证第一个单词必须为update
,第二个单词必须为table_name
,第三个单词必须为set
。我试图进行验证,但无法获得结果。
答案 0 :(得分:0)
我创建了一个非常简单的python
脚本,可在v2和v3中使用。
将内容复制到filename.py并执行sudo chmod +x filename.py
#!/usr/bin/env python
string = "update table_name set col_name = 1 where emp_id = '1234'"
x = string.split(' ')
if "update" != x[0]:
print("the first word does not contain update, exiting")
exit
else:
print("the first word contains update")
if "update" != x[1]:
print("the second word does not contain table_name, exiting")
exit
else:
print("the second word contains table_name")
if "update" != x[2]:
print("the third word does not contain set, exiting")
exit
else:
print("the third word contains set")
print("we're good to go")