revExecuteSQL not returning result with DELETE ALL

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

revExecuteSQL not returning result with DELETE ALL

Post by marksmithhfx » Thu Aug 23, 2012 5:54 pm

Hi there, I hope you can help me out with a little problem that is driving me crazy.

Database has 3 records in it; object_numbers 1,2,3

The following code works


put "delete from myDB WHERE object_number > 1" into tSQL
revExecuteSQL gdbLibDefaultID, tSQL
put return & the result after msg
refreshDataGrid -- code in card script

And displays "2" for the result (indicating 2 records deleted). The updated DataGrid also now only displays 1 record. All good.

However the following code returns the correct DataGrid result (no records) but 0 for the "the result" instead of 3.

put "delete from myDB" into tSQL -- i.e. delete all of the records
revExecuteSQL gdbLibDefaultID, tSQL
put return & the result after msg
refreshDataGrid -- code in card script

Why's that? It appears a delete without a WHERE clause does not return the number of rows affected. Can anyone independently verify that? Is it a bug?

Thanks
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

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

Re: revExecuteSQL not returning result with DELETE ALL

Post by bangkok » Thu Aug 23, 2012 6:01 pm

which database do you use ?

MySQL ? Which version ?

"In MySQL 3.23, DELETE without a WHERE clause returns zero as the number of affected rows. "

http://dev.mysql.com/doc/refman/4.1/en/delete.html

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: revExecuteSQL not returning result with DELETE ALL

Post by marksmithhfx » Thu Aug 23, 2012 8:06 pm

bangkok wrote:which database do you use ?

"In MySQL 3.23, DELETE without a WHERE clause returns zero as the number of affected rows. "

http://dev.mysql.com/doc/refman/4.1/en/delete.html

Thanks Bangkok. I was using SQLite which is doing the same thing. Not consistent since the number of rows affected is clearly not 0. I can force it to return the number of rows affected by doing something silly like "DELETE from MyDB WHERE object_number > 0" which is the same thing since object_numbers auto increment from 1. Other suggestions for if you want to delete all the rows and know the number deleted?

Thanks
-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: revExecuteSQL not returning result with DELETE ALL

Post by mwieder » Thu Aug 23, 2012 8:17 pm

It's not clear to me why you want the number of rows if you're going to delete all of them anyway, but...

Code: Select all

revDataFromQuery(tab,return,gdbLibDefaultID,"select count() from myDB")
should give you the number of rows in the myDB table. Then do your delete command.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: revExecuteSQL not returning result with DELETE ALL

Post by marksmithhfx » Thu Aug 23, 2012 9:23 pm

mwieder wrote: should give you the number of rows in the myDB table. Then do your delete command.
Hi Mark,

It was more for confirmation during development:

revExecuteSQL myConnectID, mySQL
put the result into tResult
if tResult > 0 then
answer tResult && "records deleted"
else
answer error tResult
end if

If I delete a few records (using a WHERE clause) I would get a confirmation of the number deleted. If I delete all of them I get an error message. Seemed (and still seems) odd to me to have it work in one situation and not the other. BUT I DIGRESS, rules is rules :-)

-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: revExecuteSQL not returning result with DELETE ALL

Post by mwieder » Thu Aug 23, 2012 9:40 pm

Seemed (and still seems) odd to me
Seems odd to me, too, but I read it on the internet and it was in color, so there you go. :D

afshannoomi
Posts: 1
Joined: Fri Jun 07, 2013 8:27 am

Re: revExecuteSQL not returning result with DELETE ALL

Post by afshannoomi » Fri Jun 07, 2013 11:23 am

I haven't tested with asterisk 10 or 11, it's better you use asteris
Last edited by afshannoomi on Wed Jun 12, 2013 9:02 am, edited 1 time in total.

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

Re: revExecuteSQL not returning result with DELETE ALL

Post by sturgis » Fri Jun 07, 2013 5:42 pm

If you want a count, while its silly to have to do so, you can use an always true condition and will end up with a count being returned.

Something like this:

Code: Select all

put "delete from myDB where 1=1" into tSQL -- i.e. delete all of the records
I suspect that for speed purposes when deleting all, the db engine skips... lots. no need to count, no going through the data, just remove it, so no row count is involved. Forcing any type of check will make it count, but will slow down the delete.

Post Reply