def InsertIllegal(self, obj): # obj->list List = [ obj.get_illegalid(), obj.get_userid(), obj.get_bookid(), obj.get_amount(), obj.get_isprocessed(), obj.get_illegaldate(), obj.get_illegaltype() ] Tum = tuple(List) List = [] List.append(Tum) print(List) mysql = Mysql() sql = "insert into Illegal(illegalid,userid,bookid,amount,isprocessed,illegaldate,illegaltype) " + \ "values(%s,%s,%s,%s,%s,%s,%s)" # val try: mysql.insertMany(sql, List) mysql.end('commit') print("insert success!") return True except Exception as e: mysql.end(None) mysql.dispose() return False
def InsertBookRecord(self, obj): # obj->list List = [obj.get_bookid(), obj.get_bookname(), obj.get_author(), obj.get_pages(), obj.get_collecttime(), obj.get_version(), obj.get_major(), obj.get_discipline(), obj.get_isbn(), obj.get_booklanguage(), obj.get_publisher(), obj.get_status(), obj.get_abstract(), obj.get_stack(), obj.get_shelf(), obj.get_floor(), obj.get_bookvalue()] Tum = tuple(List) List = [] List.append(Tum) print(List) mysql = Mysql() # 插入图书 # sql sql = "insert into book(bookid,bookname,author,pages,collecttime,version,\ major,discipline,isbn,booklanguage,publisher,status,abstract,stack,shelf,floor,bookvalue) " + \ "values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" # val try: mysql.insertMany(sql, List) mysql.end('commit') print("insert success!") except Exception as e: print('error') mysql.end(None) mysql.dispose()
def InsertBorrowRecord(self, obj): # obj->list List = [ obj.get_borrowid(), obj.get_userid(), obj.get_bookid(), obj.get_borrowdate(), obj.get_presretdate(), obj.get_actretdate() ] Tum = tuple(List) List = [] List.append(Tum) print(List) mysql = Mysql() sql = "insert into borrow(borrowid,userid,bookid,borrowdate,presretdate,actretdate) values(%s,%s,%s,%s,%s,%s)" try: mysql.insertMany(sql, List) mysql.end('commit') print("insert success!") return True except Exception as e: print("except") mysql.end(None) mysql.dispose() return False
def InsertUserRecord(self, obj): # 将所有value加入一个list listforinsert = [ obj.getid(), obj.getusername(), obj.getpassword(), obj.getfaculty(), obj.getdepartment(), obj.getage(), obj.getgendar(), obj.getuseridentity(), obj.getuserconnection(), obj.getstatus() ] # 转化为元组 listforinsert = (tuple(listforinsert)) # 加入list List = [] List.append(listforinsert) mysql = Mysql() sql = "insert into user(userid,username,password,faculty,department,age,gender,useridentity,userconnection" \ ",status) " + "values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" try: mysql.insertMany(sql, List) mysql.end('commit') print("insert success!") return True except Exception as e: print("insert failed!") mysql.end(None) mysql.dispose() return None
def InsertRecommandRecord(self, obj, id): recom = [] recom.append(id) recom.append(obj.getbookname()) recom.append(obj.getauthor()) recom.append(obj.getpublisher()) recom.append(obj.getversion()) recom.append(obj.getrecomreason()) recom.append('待定') reco = tuple(recom) List = [] List.append(reco) mysql = Mysql() try: sql = "insert into recommand(userid,bookname,author,publisher,version,recomreason,statue)" + \ "values(%s, %s, %s, %s, %s, %s, %s)" # sql2 = "select * from recommand where userid='" + id + "'" # print(sql2) # rs = mysql.getAll(sql2) # print(rs) # count = len(rs) # print(count) # sql3 = "select useridentity from user where userid = '" + id + "'" # print(sql3) # s = mysql.getOne(sql3) # print(s[0]) # sql4 = "select * from usertype where useridentity = '" + s[0] + "'" # print(sql4) # result = mysql.getOne(sql4) # print(result[2]) # if(count >= result[2]): # print("can't more recommand") # else: mysql.insertMany(sql, List) mysql.end('commit') print("insert success!") return True except Exception as e: print(e) mysql.end(None) mysql.dispose() return False