Delete record from table

It is my first project with Ignition so please bare with me.

Among other things I want the user to be able to delete records from my recipe table. So I need to have an inputfield, so he enters the record to be deleted and then a Delete button.

I used the following script in a button and it works but is it not linked to the inputbox (so no good):

deleteQuery = “DELETE FROM recipes WHERE id=10”

I then changed the script to that but is doesnt work:
recordToDelete = 11
deleteQuery = “DELETE FROM recipes WHERE id=(recordToDelete)”

It complains that there is no recordToDelete column in my table (the idea is that recordToDelete will be binded to an inputbox).

Also, what is the best way to popup a msgbox asking the user if he realy wants to proceed or not when the delete button is pressed?


Hi! Welcome to the forums! :smiley:

The problem is that you made “recordToDelete” part of the query string. It’s literally looking for something called “recordToDelete”.

What you need is to make the value of “recordToDelete” part of the string. Here’s the down and dirty method (I’ll illustrate another in another post. Got a meeting to go to shortly. :wink: )


recordToDelete = 11 deleteQuery = "DELETE FROM recipes WHERE id="+str(recordToDelete) system.db.runUpdateQuery(deleteQuery)

What this does it takes the value of recordToDelete, make a string out of it and tag it onto the end of the query string.

Hope this helps!


Ok, meeting cancelled. :laughing:

A more “Pythonic” way would be to use foramatting placeholders in your string. In your case it would look something like:

recordToDelete = 11 deleteQuery = "DELETE FROM recipes WHERE id=%d" system.db.runUpdateQuery(deleteQuery % (recordToDelete))
The “%d” is a placholder specifying that a decimal value will be inserted here. This page (about halfway down) gives a nice overview on the different types of placeholders you can use.

The last line, where it uses ‘deleteQuery & (recordToDelete)’ is where values get plugged into the placeholders.

EDIT: Another example of how to use this is in the User’s Manual here.

Thank you. Your suggestion did the trick.