Delete entries in mysql database

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rayck23
Posts: 4
Joined: Sat Oct 29, 2011 10:22 pm

Delete entries in mysql database

Post by rayck23 » Sat Oct 29, 2011 10:41 pm

Hi, sorry if this has been covered but I am having issues finding a solution. I want users to be able to delete the entries that have been compiled in a database table I have created by clicking a button. I have been able to allow users to make entries into the database table, but cannot seem to get the coding correct so they can clear it. I have tried following help section, but am unsure where to put the command in my code. Thanks for the help!

This is what my code looks like for the button, I know this is not correct because this is the "Add record" code....
Capture.PNG

This is what I am trying to do.....

And for deleting:
DELETE FROM Table1 WHERE firstName='Mary' AND lastName='Smith'

Then use revExecuteSQL and check for errors as before.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Delete entries in mysql database

Post by bangkok » Sun Oct 30, 2011 9:21 am

I'm not sure to understand correctly what is your problem...

Anyway.
put "DELETE FROM Table1 WHERE firstName='Mary' AND lastName='Smith' " into tySQL
revExecuteSQL gConnectionID,tSQL

if the result is a not a number then
answer "Error : "&the result
else
answer "ok"
end if

PS : i would avoid to use cap in tables and columns names.

rayck23
Posts: 4
Joined: Sat Oct 29, 2011 10:22 pm

Re: Delete entries in mysql database

Post by rayck23 » Sun Oct 30, 2011 3:33 pm

I apologize for the confusion....I was in a rush when I wrote my question. Here we go....

I have a database called "slpproject" that has a table called "table1". I am able to create entries in that table but am having issues with creating a line of code that will allow me to delete all the entries that have been made in that table. I followed the directions in the example for creating an entry to a database here,
creating.PNG
but I am having problems figuring out where to enter the "Delete From" portion of the code into the above example,
delete.PNG
I am sorry again if this confuses anyone....I am very new to this and am reading all I can in order to learn Livecode....but I feel like a 1st grader trying to learn physics!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Delete entries in mysql database

Post by sturgis » Sun Oct 30, 2011 9:15 pm

If i'm understanding correctly, you want to completely clear table "table1" of all entries.

If so, the insert example you give is more intricate than you need. The first paragraph at http://dev.mysql.com/doc/refman/5.0/en/delete.html specifies how to delete all rows (no where clause)

Code: Select all

on MouseUp
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first"
exit to top
end if

-- since you don't need a where clause, its really straight forward. No Where means all rows removed.
put "delete from table1" into tSQL 

revExecuteSQL gConnectionID, tSQL

if the result is a number then
answer info "All rows deleted"
else
answer error "There was a problem clearing table1" & cr & the result
end if
end mouseUp
rayck23 wrote:I apologize for the confusion....I was in a rush when I wrote my question. Here we go....

I have a database called "slpproject" that has a table called "table1". I am able to create entries in that table but am having issues with creating a line of code that will allow me to delete all the entries that have been made in that table. I followed the directions in the example for creating an entry to a database here,
creating.PNG
but I am having problems figuring out where to enter the "Delete From" portion of the code into the above example,
delete.PNG
I am sorry again if this confuses anyone....I am very new to this and am reading all I can in order to learn Livecode....but I feel like a 1st grader trying to learn physics!

rayck23
Posts: 4
Joined: Sat Oct 29, 2011 10:22 pm

Re: Delete entries in mysql database

Post by rayck23 » Mon Oct 31, 2011 12:50 am

THANK YOU!!!!!! Works great....just what I wanted it to do!!!

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Delete entries in mysql database

Post by Klaus » Mon Oct 31, 2011 12:32 pm

Hi rayck,

I would not hurt to take look here, this also got me started with SQL!
http://www.w3schools.com/sql/default.asp 8)


Best

Klaus

Post Reply