Deleting a record from the database in corona sample app.

Today I downloaded the sample business app. love it!

I’ve added a ‘Delete button’ on ‘edit account’ screen in the app but don’t know how to delete that particular record from the database. (That already stored at any point in database ID)

Please Help!

https://github.com/coronalabs-samples/business-app-sample/blob/master/database.lua

There’s a delete method which may help but I am unsure since I never used the api.

There are a ton of resources on SQLite that can be searched on. But in general SQL has a command called DELETE. The syntax is:

DELETE FROM table WHERE condition;

You just need to provide the table name and the condition. But as Supergoldstars1 pointed out, I set up simple methods to handle the basic CRUD features (Create, Read, Update, Delete). If you call db.delete(“your where clause”) it should handle deleting the record for you. Since I don’t know your criteria to delete, I can’t predict what you’re where clause should be but if you’re using this with just these modifications you might want to try

db.delete( "id = " .. tostring( databaseID ) )

Rob

Sorry I’m late but thanks Rob and supergoldstars1 for your replay… I checked out your suggestions and finally solved my problem. Here is the code if anyone else need it:

----- Delete Function

local function deleteData(event)

local record = {}

record.firstName = firstNameField.text

record.lastName = lastNameField.text

record.email = emailAddressBox.text

record = "id = " … tostring( databaseID )

db.delete( record )

----- Delete Button

deleteButton = widget.newButton({

       width = 160,

       height = 40,

       label = “Delete”,

       labelColor = { 

           default = { 0.90, 0.60, 0.34 }, 

           over = { 0.79, 0.48, 0.30 } 

       },

       labelYOffset = -4, 

       font = myApp.font,

       fontSize = 18,

       emboss = false,

       onRelease = deleteData

   })

   deleteButton.x = display.contentCenterX

   deleteButton.y = emailAddressBox.y + 180

   sceneGroup:insert( deleteButton )

end

Thank You!

https://github.com/coronalabs-samples/business-app-sample/blob/master/database.lua

There’s a delete method which may help but I am unsure since I never used the api.

There are a ton of resources on SQLite that can be searched on. But in general SQL has a command called DELETE. The syntax is:

DELETE FROM table WHERE condition;

You just need to provide the table name and the condition. But as Supergoldstars1 pointed out, I set up simple methods to handle the basic CRUD features (Create, Read, Update, Delete). If you call db.delete(“your where clause”) it should handle deleting the record for you. Since I don’t know your criteria to delete, I can’t predict what you’re where clause should be but if you’re using this with just these modifications you might want to try

db.delete( "id = " .. tostring( databaseID ) )

Rob

Sorry I’m late but thanks Rob and supergoldstars1 for your replay… I checked out your suggestions and finally solved my problem. Here is the code if anyone else need it:

----- Delete Function

local function deleteData(event)

local record = {}

record.firstName = firstNameField.text

record.lastName = lastNameField.text

record.email = emailAddressBox.text

record = "id = " … tostring( databaseID )

db.delete( record )

----- Delete Button

deleteButton = widget.newButton({

       width = 160,

       height = 40,

       label = “Delete”,

       labelColor = { 

           default = { 0.90, 0.60, 0.34 }, 

           over = { 0.79, 0.48, 0.30 } 

       },

       labelYOffset = -4, 

       font = myApp.font,

       fontSize = 18,

       emboss = false,

       onRelease = deleteData

   })

   deleteButton.x = display.contentCenterX

   deleteButton.y = emailAddressBox.y + 180

   sceneGroup:insert( deleteButton )

end

Thank You!