peterbrewer
February 28th, 2008, 07:43 PM
Hi there. I am using Python as part of a project. I create a SQLite database in it and use the following code to generate a table.
query.exec_("""CREATE TABLE title (
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
name VARCHAR(40) NOT NULL)""")
After this I then use this code to add data to the table, which I know is added as it is viewable from a 3rd party app when I open the database,
for name in ("Mr", "Mrs", "Miss", "Ms", "Prof", "Doctor", "Other"):
query.exec_("INSERT INTO title (name) VALUES ('%s')" % name)
Then I use the following code to ask it to print out the data in the table.
print "Titles:"
query.exec_("SELECT id, name FROM title ORDER BY id")
while query.next():
id = query.value(ID).toInt()[0]
name = unicode(query.value(NAME).toString())
print "%02d: %s" % (id, name)
QApplication.processEvents()
The issue is that all it prints are 7 lines with an id supposedly of 00 and no actual name. It clearly has some access to the table as it prints those 7 lines but I am not sure what is wrong. Any help would be hugely appreciated.
query.exec_("""CREATE TABLE title (
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
name VARCHAR(40) NOT NULL)""")
After this I then use this code to add data to the table, which I know is added as it is viewable from a 3rd party app when I open the database,
for name in ("Mr", "Mrs", "Miss", "Ms", "Prof", "Doctor", "Other"):
query.exec_("INSERT INTO title (name) VALUES ('%s')" % name)
Then I use the following code to ask it to print out the data in the table.
print "Titles:"
query.exec_("SELECT id, name FROM title ORDER BY id")
while query.next():
id = query.value(ID).toInt()[0]
name = unicode(query.value(NAME).toString())
print "%02d: %s" % (id, name)
QApplication.processEvents()
The issue is that all it prints are 7 lines with an id supposedly of 00 and no actual name. It clearly has some access to the table as it prints those 7 lines but I am not sure what is wrong. Any help would be hugely appreciated.