python 操作 员工信息表
要求:
可进行模糊查询,语法至少支持下面3种:
select name,age from staff_table where age > 22
select * from staff_table where dept = "IT"
select * from staff_table where enroll_date like "2013"
查到的信息,打印后,最后面还要显示查到的条数
可创建新员工纪录,以phone做唯一键,staff_id需自增
可删除指定员工信息纪录,输入员工id,即可删除
可修改员工信息,语法如下:
UPDATE staff_table SET dept="Market" WHERE where dept = "IT"
注意:以上需求,要充分使用函数,请尽你的最大限度来减少重复代码
达成要求:
查询命令的各单词之间可以有任意数量的空格
查询时不设定条件(where语句)也可以执行
错误信息高亮显示
代码:
#! /usr/bin/env python3
# Author:Jailly
import pickle,re
# 查找
def search(search_condition):
res = [] # 储存查找结果
# where条件存在
if search_condition:
# 三种条件格式
m1 = re.search(r‘age\s+(>|
m2 = re.search(r‘‘‘
(?P(staff_id)|(name)|(age)|(phone)|(dept)|(enroll_date))
\s+=\s+
(?P.*)
‘‘‘, search_condition, re.X)
m3 = re.search(r‘‘‘
(?P(staff_id)|(name)|(age)|(phone)|(dept)|(enroll_date))