我正在创建一个排序应用程序,它从表中挑选学生并将它们放在表单组中。不同群体的性别应该是平等的。它循环遍历每个表插入随机的男学生。
我使用打印功能来跟踪发生的事情。似乎循环正在起作用
print(idMale)
正在打印行。然而,在另一张表中根本没有插入。程序会中断并输出此错误:
这是我的代码:
# loops through each table
for x in range(0,groupNumber):
#Adds I to table name to go through each table
nameGroupList.append('I')
print(nameGroupList)
nameGroup = ''.join(nameGroupList)
#loop to select a student from the main table (sessionName) and insert them into another group
#loop number is subject to the number of males that should be in 1 group
for x in range(0, formMaleInt):
selectMaleRow = cur.execute("SELECT * FROM " + sessionName + " WHERE Gender='M' ORDER BY random() Limit 1")
#-----Find ID of student selected so they can be deleted from sessionName
idMale = selectMaleRow.fetchone()
print(idMale)
idSepChar = list(idMale)
idNum = idSepChar[0]
idNumStr = str(idNum)
#-----Find ID of student selected so they can be deleted from sessionName
insertMaleRow = cur.execute("INSERT INTO " + nameGroup + " SELECT * FROM " + sessionName + " WHERE Gender='M' ORDER BY random() Limit 1")
deleteMaleRow = cur.execute("DELETE FROM " + sessionName + " WHERE ID='" + idNumStr + "'")