forked from Mercy-akuma/2022-Summer-Research
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
73 lines (63 loc) · 2.59 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 此文件用于用户记录
from dataset import select
# 通过用户名,获取用户记录,如果不存在,则返回None
def query_user(username):
# 先获取数据库用户信息
users = select('select * from User where Name = \'%s\'' %username,'transaction')
for user in users:
if user['Name'] == username:
return user
def search_all_saledataset():
#查询所有在售的数据
all_data = select('select * from Dataset where State = 1', 'transaction')
#返回一个列表, 列表元素为字典
return all_data;
def search_seller_dataset(Name):
#查询某个seller的的数据
all_data = select('select * from Dataset where Owner = \'%s\''%Name, 'transaction')
#返回一个列表, 列表元素为字典
return all_data;
def search_dataset(keyword, did, seller_name, begin_date, end_date):
sql="SELECT * FROM Dataset WHERE Name like "+ "\'"+"%" + "%s"%keyword + "%"+ "\'"
if did != "":
sql += " and DID = %s"%did
if seller_name != "":
sql += " and Owner like "+ "\'"+"%" + "%s"%seller_name + "%"+ "\'"
if begin_date != "":
sql += " and CreateDate >= " + "\'%s\'"%begin_date
if end_date != "":
sql += " and CreateDate <= " + "\'%s\'"%end_date
# print(sql)
return select(sql, "transaction")
# 判断sql语句的正确性
# def isLegal(sql):
# return True
# 定价函数
def getSQLPrice():
return 1
def searchOrderOfBuyer(Buyer):
all_data = select('select * from order_table where Buyer = \'%s\''%Buyer, 'transaction')
#返回一个列表, 列表元素为字典
return all_data;
def searchOrderOfSeller(Seller):
all_data = select('select * from order_table where Seller = \'%s\''%Seller, 'transaction')
#返回一个列表, 列表元素为字典
return all_data;
def searchALLOrder():
all_data = select('select * from order_table', 'transaction')
#返回一个列表, 列表元素为字典
return all_data;
def search_order(Datasetname, oid, buyer_name,seller_name, begin_date, end_date):
sql="SELECT * FROM order_table WHERE DName like "+ "\'"+"%" + "%s"%Datasetname + "%"+ "\'"
if oid != "":
sql += " and OID = %s"%oid
if seller_name != "":
sql += " and Seller like "+ "\'"+"%" + "%s"%seller_name + "%"+ "\'"
if buyer_name != "":
sql += " and Buyer like "+ "\'"+"%" + "%s"%buyer_name + "%"+ "\'"
if begin_date != "":
sql += " and CreateDate >= " + "\'%s\'"%begin_date
if end_date != "":
sql += " and CreateDate <= " + "\'%s\'"%end_date
# print(sql)
return select(sql, "transaction")