greyfox1
June 11th, 2009, 10:40 PM
Hi All,
I can't figure out what the problem with a delete statement I've written is. I am working on a simple database manager (it actually started as a response to LaRoza's BPC #7 (http://ubuntuforums.org/showthread.php?p=5926632) and turned into a bit of a monster as I added more and more functionality once I satisfied the initial requirements).
The program is written in Python and uses a sqlite database. Nearly everything works as intended (including all the sqlite-related pieces) except a portion where I try to delete a record from the database.
I have a sqlite table called 'main' with an integer primary key called 'id' as well as fields for first name last name, and age. There is a variable edOrDel which determines whether to update an existing record or delete it. The update portion of things works as intended (when edOrDel is 'E') but the delete statement fails (when edOrDel is 'D').
Here is the code in question:
if edOrDel=='E':
cursor.execute('UPDATE main SET FName=?, LName=?, age=? WHERE id=?', (dataFName, dataLName, dataAge, record))
elif edOrDel=='D':
cursor.execute('DELETE FROM main WHERE id=?', (record))
connection.commit()
dataFName, dataLName, and dataAge are strings of data entered by the user, and
the 'record' variable is an integer that corresponds to the primary key for the database row that I want to delete.
When edOrDel is 'D' and the second bit of code runs, I get this error from the interpreter:
File "BPC7DBOperations.py", line 96, in DBWrite
cursor.execute('DELETE FROM main WHERE id=?', (record))
ValueError: parameters are of unsupported type
I can't figure out what I'm doing wrong. The statement works when I hard-code the record number (WHERE id=1 for example) but I need it to work for any record number needed. The program checks that the number indicated by the 'record' variable is valid before this piece of code is written.
Any help would be much appreciated!
I can't figure out what the problem with a delete statement I've written is. I am working on a simple database manager (it actually started as a response to LaRoza's BPC #7 (http://ubuntuforums.org/showthread.php?p=5926632) and turned into a bit of a monster as I added more and more functionality once I satisfied the initial requirements).
The program is written in Python and uses a sqlite database. Nearly everything works as intended (including all the sqlite-related pieces) except a portion where I try to delete a record from the database.
I have a sqlite table called 'main' with an integer primary key called 'id' as well as fields for first name last name, and age. There is a variable edOrDel which determines whether to update an existing record or delete it. The update portion of things works as intended (when edOrDel is 'E') but the delete statement fails (when edOrDel is 'D').
Here is the code in question:
if edOrDel=='E':
cursor.execute('UPDATE main SET FName=?, LName=?, age=? WHERE id=?', (dataFName, dataLName, dataAge, record))
elif edOrDel=='D':
cursor.execute('DELETE FROM main WHERE id=?', (record))
connection.commit()
dataFName, dataLName, and dataAge are strings of data entered by the user, and
the 'record' variable is an integer that corresponds to the primary key for the database row that I want to delete.
When edOrDel is 'D' and the second bit of code runs, I get this error from the interpreter:
File "BPC7DBOperations.py", line 96, in DBWrite
cursor.execute('DELETE FROM main WHERE id=?', (record))
ValueError: parameters are of unsupported type
I can't figure out what I'm doing wrong. The statement works when I hard-code the record number (WHERE id=1 for example) but I need it to work for any record number needed. The program checks that the number indicated by the 'record' variable is valid before this piece of code is written.
Any help would be much appreciated!