def deleteallBycourseid(courseid): db = DB() cursor = db.connection() mysql = "delete from file where course_id='%s'" % (courseid) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def delete(self): db = DB() cursor = db.connection() mysql = "delete from file where unique_id='%s'" % (self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def queryById(uid): db = DB() cursor = db.connection() mysql = "select * from file where unique_id='%s'" % (uid) result = None try: cursor.execute(mysql) result = cursor.fetchone() db.db.commit() except: db.db.rollback() db.db.close() return result
def query_all(self): db = DB() cursor = db.connection() mysql = "select * from file" try: cursor.execute(mysql) results = cursor.fetchall() db.db.commit() except: db.db.rollback() db.db.close() return results
def queryByurl(self, url): db = DB() cursor = db.connection() mysql = "select * from course where course_url='%s'" % (url) result = None try: cursor.execute(mysql) result = cursor.fetchone() db.db.commit() except: db.db.rollback() db.db.close() return result
def queryByuserid(self, name): db = DB() cursor = db.connection() mysql = "select * from teacher where user_id='%s'" % (name) result = None try: cursor.execute(mysql) result = cursor.fetchone() db.db.commit() except: db.db.rollback() db.db.close() return result
def insert(self): # 加载db类,用于连接数据库 db = DB() # 获取cursor cursor = db.connection() mysql="insert into teacher(unique_id,name,user_id,password,spare1,spare2,spare3,spare4)" \ " values('%s','%s','%s','%s','%s','%s','%s','%s')"\ %(self.unique_id,self.name,self.user_id,self.password,self.spare1,self.spare2,self.spare3,self.spare4) try: # 执行sql语句 cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def update(self): db = DB() cursor = db.connection() mysql = "update file set file_name='%s',file_url='%s',course_id='%s',upload_time='%s',week_no='%s',spare2='%s',\ spare3='%s',spare4='%s' where unique_id='%s'" % ( self.file_name, self.file_url, self.course_id, self.upload_time, self.week_no, self.spare2, self.spare3, self.spare4, self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def query_allByteacher(self, teacher): db = DB() cursor = db.connection() print("teacher:", teacher) mysql = "select * from course where teacher='%s'" % (teacher) results = None try: cursor.execute(mysql) results = cursor.fetchall() db.db.commit() except: db.db.rollback() db.db.close() return results
def update(self): db = DB() cursor = db.connection() mysql = "update course set course_url='%s',name='%s',description='%s',teacher='%s',spare1='%s',spare2='%s',\ spare3='%s',spare4='%s' where unique_id='%s'" % ( self.course_url, self.name, self.description, self.teacher, self.spare1, self.spare2, self.spare3, self.spare4, self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def insert(self): # 加载db类,用于连接数据库 db = DB() # 获取cursor cursor = db.connection() mysql="insert into course(unique_id,course_url,name,description,teacher,spare1,spare2,spare3,spare4)" \ " values('%s','%s','%s','%s','%s','%s','%s','%s','%s')"\ %(self.unique_id,self.course_url,self.name,self.description,self.teacher,self.spare1,self.spare2,self.spare3,self.spare4) print(mysql) try: # 执行sql语句 cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def update(self): db = DB() cursor = db.connection() mysql = "update teacher set name='%s',user_id='%s',password='******',spare1='%s',spare2='%s',\ spare3='%s',spare4='%s' where unique_id='%s'" % ( self.name, self.user_id, self.password, self.spare1, self.spare2, self.spare3, self.spare4, self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def insert(self): # 加载db类,用于连接数据库 db = DB() # 获取cursor cursor = db.connection() mysql = "insert into file(unique_id,file_name,file_url,course_id,upload_time,week_no,spare2,spare3,spare4)" \ " values('%s','%s','%s','%s','%s','%s','%s','%s','%s')" \ % (self.unique_id, self.file_name, self.file_url, self.course_id, self.upload_time, self.week_no, self.spare2, self.spare3, self.spare4) print("Mysql:",mysql) try: # 执行sql语句 cursor.execute(mysql) db.db.commit() print("insert sucess") except: db.db.rollback() print("insert failure") db.db.close()