0% found this document useful (0 votes)
6 views4 pages

back

The document contains Python functions for managing a SQLite database related to teachers, courses, students, and attendance. It includes functionalities for user authentication, registration, password modification, course and student management, and attendance tracking. Each function handles database operations with error handling and returns success messages or errors as needed.

Uploaded by

12232223445
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

back

The document contains Python functions for managing a SQLite database related to teachers, courses, students, and attendance. It includes functionalities for user authentication, registration, password modification, course and student management, and attendance tracking. Each function handles database operations with error handling and returns success messages or errors as needed.

Uploaded by

12232223445
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import sqlite3

import uuid

def userexist(gh):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
#cur.execute("select * from teacher where workno = '"+gh+"' ")
#cur.execute("select * from teacher where workno = '%s' "%(gh,))
cur.execute("select * from teacher where workno = ? ",(gh,))
data=cur.fetchall()
conn.close()
if len(data)==1:
return True
else:
return False

def userpass(gh,mm):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()

cur.execute("select password from teacher where workno = ? ",(gh,))


data=cur.fetchall()
conn.close()

if mm==data[0][0]:
return True
else:
return False

def reg(gh,name,mm):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("insert into teacher(workno,name,password) values (?,?,?) ",
(gh,name,mm))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err

def modpassword(gh,newmm):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("update teacher set password=? where workno =? ",(newmm,gh))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def deluser(gh):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("delete from teacher where workno =? ",(gh,))
if cur.rowcount==1:
conn.commit()
conn.close()
return 'success'
else:
conn.rollback()
conn.close()
return '删除了 0 行数据'
except Exception as err:
conn.rollback()
conn.close()
return err

def addcourse(courseuuid,gh,code,coursename):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("insert into course values (?,?,?,?) ",
(courseuuid,gh,code,coursename))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err

def courselist(gh):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
cur.execute("select * from course where workno =?",(gh,))
data=cur.fetchall()
conn.close()
return data

def addstud(studuuid,courseuuid,xh,name):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("insert into student values (?,?,?,?) ",
(studuuid,courseuuid,xh,name))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err

def addbatch(batchuuid,courseuuid,batchname):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
#1 插入 batch 数据
cur.execute("insert into batch values (?,?,?) ",
(batchuuid,courseuuid,batchname))
#2 取对应课程的学生名单
cur.execute("select * from student where courseuuid=?",(courseuuid,))
studlist=cur.fetchall()
#3 插入到 attend
for s in studlist:
attenduuid=str(uuid.uuid1())
cur.execute("insert into attend values (?,?,?,?)",
(attenduuid,batchuuid,s[0],'已到'))
#如果程序能走到这里,说明都成功了
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err

def getattend(batchuuid):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()

cur.execute("select * from attendstud where batchuuid = ? ",(batchuuid,))


data=cur.fetchall()
conn.close()
return data

def modattend(attenduuid,attendance):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
attdict={'1':'已到','2':'缺勤','3':'请假',}
try:
cur.execute("update attend set attendance=? where uuid =? ",
(attdict[attendance],attenduuid))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err

def tj(courseuuid):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
sql='''select
student.xh,
student.name,
(select count(*) from attend where attend.studuuid=student.uuid and attendance='已
到'),
(select count(*) from attend where attend.studuuid=student.uuid and attendance='缺
勤'),
(select count(*) from attend where attend.studuuid=student.uuid and attendance='请
假')
FROM
student
WHERE
student.courseuuid = ?
'''
cur.execute(sql,(courseuuid,))
data=cur.fetchall()
conn.close()
return data

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy