def UpdateRecord(self, table, key1, val1, key2, val2): # key1和val1是修改键和值,val1和val2是条件键和值,如果是val是非数字,则需要写成'"数"'传入 mysql = Mysql() sql = "update " + table + " set " + key1 + "='" + val1 + "' where " + key2 + "='" + val2 + "'" try: mysql.update(sql, None) # mysql.update("update book") mysql.end('commit') print("update succes!") except Exception as e: print(e) mysql.end(None) mysql.dispose()
def DeleteRecord(self, table, key, val): # key字段名 val值 mysql = Mysql() sql = "delete from " + table + " where " + str(key) + "=" + str(val) try: mysql.delete(sql, None) mysql.end('commit') print("delete success!") return True except Exception as e: print("delete error!") mysql.end(None) mysql.dispose() return False
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