You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.7 KiB

6 months ago
import pymysql
import logging
def QueryBook(conn,para1,para2,index):
if para1=="" or para2=="":
return "输入不能为空"
cursor=conn.cursor()
##目前进度单值查询已做完区间查询没有做。并且最后return的是一个比较乱的tuple。在show()函数中应该要一层一层的处理
try:
if index==0:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where bclass=%s"
elif index==1:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where bname=%s"
elif index==2:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where publisher=%s"
elif index==4:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where author=%s"
elif index==3:
y1=int(para1)
y2=int(para2)
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where year>%s and year<%s"
elif index==5:
p1=float(para1)
p2=float(para2)
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where price>%s and price<%s"
try:
if index==0 or index==1 or index==2 or index==4:
cursor.execute(sql,para1)
elif index==5:
cursor.execute(sql,(p1,p2))
else:
cursor.execute(sql,(y1,y2))
conn.commit()
result=cursor.fetchall()
return result
except Exception as e:
conn.rollback()
return e
except Exception as e:
return e