将SQL Python数据库转换为类

将SQL Python数据库转换为类,python,database,sqlite,class,for-loop,Python,Database,Sqlite,Class,For Loop,我已经为我的项目创建了这个员工数据库,需要将它转换为一个类(包括类我会得到更多的分数),但我需要遍历每一列(ID,name,jobRole,等等),并创建我创建的employee类的对象 这是我目前的代码: tableID = c.execute('select employeeID from employeeData') for r in tableID: tableName = c.execute('select employeeName from employeeData')

我已经为我的项目创建了这个员工数据库,需要将它转换为一个类(包括类我会得到更多的分数),但我需要遍历每一列(
ID
name
jobRole
,等等),并创建我创建的
employee
类的对象

这是我目前的代码:

tableID = c.execute('select employeeID from employeeData')
for r in tableID:
    tableName = c.execute('select employeeName from employeeData')
    for s in tableName:
        tableJobRole = c.execute('select employeeJobRole from employeeData')
        for t in tableJobRole:
            tableYearlySalary = c.execute('select employeeYearlySalary from employeeData')
            for u in tableYearlySalary:
                v = s
                exec(str(v))
                v = Employee(r, s, t, u)
当我在GUI中运行代码并单击某个按钮时,它不会执行我希望它执行的操作。我如何创建一段代码来遍历第一行,将列中的数据设置为
r
s
t
u
,然后同时进入下一行

r
s
t
u
中的每一个都将等于第一行,然后我希望它们都等于下一行,而不是前三个留在第一行,
u
进入下一行,直到
t
增加,然后
s


因此,我希望以某种方式将“for each in…”中的每个字段同时递增一个。

您可以使用单个查询返回表中每行的所有字段。试试这个:

employees = []
c.execute('select employeeID, employeeName, employeeJobRole, employeeYearlySalary from employeeData')
results = cursor.fetchall()
for row in results:
    employees.append(Employee(row[0], row[1], row[2], row[3]))

这个问题很不清楚。如果您正在寻找用Python类表示数据库模式的通用解决方案,您可能会对ORM库感兴趣。谢谢!我会试试看,然后告诉你我是怎么做的:)它起作用了。但是我似乎无法插入代码。。。当我按enter键时,它只是提交注释。谢谢你的时间和帮助。谢谢你!