Re: DELETE Statement Apparently Not Working
Adrian Klaver <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
On Tuesday 02 October 2007 4:31 pm, Rich Shepard wrote:
> OK. I have the variables all straightened out now, but ... it's still
> not working. That is, The DELETE statement supposedly is executed, the
> COMMIT supposedly runs, but the row is still in the database table.
>
> Here's the complete function:
>
> def OnDel(self, event):
> dlg = wx.MessageDialog(None, "WARNING: Deleting this variable will
> also delete the term sets and rules. Are you sure you want to do this?",
> caption="Deleting a Variable", style=wx.YES_NO|wx.ICON_EXCLAMATION) showme
> = dlg.ShowModal()
> if showme == wx.ID_YES:
> print self.vname.GetValue()
> print self.vcomp.GetValue()
> print self.vsub.GetValue()
> self.appData.cur.execute ("DELETE from Variable where name='%s' and
> comp_name='%s' and subcomp_name='%s'" %
> (self.vname.GetValue(),self.vcomp.GetValue(),self.vsub.GetValue()))
> self.appData.con.commit()
> dlg.Destroy()
>
> The correct strings are printed on the virtual console, and no error
> messages are displayed.
>
> How do I test why the execute and commit are not working as intended?
> Can I step into that function using winpdb? Is my SQL syntax incorrect?
>
> Rich
Several questions/steps.
1) The row you want to delete actually exists in the database?
Not finding a row to delete is not an error just a non-op.
2) As I mentioned previously are you sure that everything about the values
being supplied to the where clause is the same as the values in the database?
3) Set up a simplified test case. I usually drop into ipython and hardwire an
SQL statement with values I know will work.
4) I usually find I have fewer problems if I use one of pysqlites parameter
styles. I prefer the named version. Ex: name=:name and comp_name=:comp_name',
{'name':self.vname.GetValue(),'comp_name':self.vcomp.GetValue()}
--
Adrian Klaver
[email protected]