【发布时间】:2015-07-14 04:25:44
【问题描述】:
我在 Kubuntu 上使用 Python 2.7.5+ 13.10 和 wx 2.8.12.1。
我没有大型数据库(大约 3150 行),我只有一个员工表(名字、姓氏、地址、电话、电子邮件)。在我的应用程序中,我将它们存储在SQLite 数据库中,并使用wx.ListCtrl 向用户显示行。
但是,将这样的数据库加载到wx.ListCtrl 需要很长时间(我认为超过 10 秒)。 问题是:有没有可能提高选择速度?
首先,在我的 Python 代码中,我创建了一个表:
def createEmployeesTable(self):
connection = sqlite.connect(self.dbname)
try:
with connection:
cursor = connection.cursor()
sql = '''\
CREATE TABLE IF NOT EXISTS Employees (
ID INTEGER PRIMARY KEY NOT NULL,
FIRSTNAME TEXT,
LASTNAME TEXT,
EMAIL TEXT,
ADDRESS TEXT,
PHONE TEXT)
'''
cursor.execute(sql)
finally:
connection.close()
然后,我插入一些员工的数据,最后选择在带有wx.ListCtrl的弹出窗口中显示数据:
def getAllEmployees(self):
employees = []
connection = sqlite.connect(self.dbname)
try:
with connection:
cursor = connection.cursor()
sql = "SELECT firstname, lastname, email, phone, address FROM Employees"
cursor.execute(sql)
for (firstname, lastname, email, phone, address, ) in cursor:
employees.append(Employee(firstname, lastname, email, phone, address))
finally:
connection.close()
return employees
非常感谢您的帮助。
【问题讨论】:
标签: python sqlite select wxpython wxwidgets