def getSelectStudentNum(courseId): conn = Connection.getConnection() cursor = conn.cursor() sql = "select count(*) from selection where course_id = %d" % ( courseId) cursor.execute(sql) return cursor.fetchone()[0]
def getSelectCourseInfo(studentId): conn = Connection.getConnection() cursor = conn.cursor() sql = "select * from course where course_id in (select course_id from selection where student_id = %d)" % ( studentId) cursor.execute(sql) return cursor.fetchall()
def getSelectCourseNum(studentId): conn = Connection.getConnection() cursor = conn.cursor() sql = "select count(*) from selection where student_id = %d" % ( studentId) cursor.execute(sql) result = cursor.fetchone() return result[0]
def quitCourse(student_id, course_id): conn = Connection.getConnection() cursor = conn.cursor() sql = "select * from selection \ where student_id=%d and course_id=%d" % (student_id, course_id) cursor.execute(sql) if (len(cursor.fetchall()) > 0): sql = "delete from selection \ where student_id=%d and course_id=%d" % (student_id, course_id) cursor.execute(sql) conn.commit() return ('1', u"成功退选该课程") else: return ('0', u"没有选择该课程")
def selectCourse(student_id, course_id): conn = Connection.getConnection() cursor = conn.cursor() sql = "select * from selection \ where student_id=%d and course_id=%d" % (student_id, course_id) cursor.execute(sql) if (len(cursor.fetchall()) == 0): sql = "insert into selection values(%d, %d)" % (student_id, course_id) cursor.execute(sql) conn.commit() return ('1', u"成功选择该课程") else: return ('0', u"已经选过该课程")
def getAllStudentInfo(): conn = Connection.getConnection() cursor = conn.cursor() sql = "select * from student" cursor.execute(sql) return cursor.fetchall()
def getCourseInfoById(id): conn = Connection.getConnection() cursor = conn.cursor() sql = "select * from course where course_id = %d" % (id) cursor.execute(sql) return cursor.fetchall()
def getAllCourseInfo(): conn = Connection.getConnection() cursor = conn.cursor() sql = "select * from course" cursor.execute(sql) return cursor.fetchall()