Delete from where?

Easy question for most, but I’m not able to find a good example. I am trying to delete a record (row) from a MySql db table using the action script on a button. To keep it simple, the intended row to be deleted will be the selected row. The where clause is dynamic with the selected row so what would work for this?

fpmi.db.runUpdateQuery("DELETE FROM table_name WHERE Id = ? ")

Thanks!

I’m assuming you’re selecting a row in a table component, then deleteing that record from the MySQL table…

I just had the same application what I did was add a dyniamic property to the table component that reflected the value in the id column. You can then reference the dynamic property in your script. The reference will look similar to:

query= "DELETE FROM table_name WHERE Id="+event.source.table.DynamicProperty
fpmi.db.runUpdateQuery(query)

Thanks for the example, although I get the error listed below.

query = “DELETE FROM 200_mil_Thickness WHERE ID =” + event.source.parent.getComponent(‘Table’).value
fpmi.db.runUpdateQuery(query)

Traceback (innermost last):
File “event:actionPerformed”, line 1, in ?
TypeError: add nor radd defined for these operands

In concatenation you need to make sure the value is a string. So you can do one of two things:

  1. query = "DELETE FROM 200_mil_Thickness WHERE ID = " + str(event.source.parent.getComponent('Table').value) 
  2. query = "DELETE FROM 200_mil_Thickness WHERE ID = %d" % event.source.parent.getComponent('Table').value 

Thanks!