Re: Delete query returns true value but still delete doesn't occur

From: Tony Mountifield <tony_at_mountifield.org>
Date: Tue, 28 Mar 2017 15:30:57 +0000 (UTC)
Message-ID: <obdvjh$2ce$1_at_softins.softins.co.uk>


In article <38becceb-a83c-48d5-9e5e-436f6905f86a_at_googlegroups.com>, kushal bhattacharya <bhattacharya.kushal4_at_gmail.com> wrote:
> Hi,
> I am running delete query on some table as
>
>
> delete from msg_table where msg_id=? and (state=? and sock_fd=?)
>
>
> the return values gives true and most of the time the query works and deletes the entry.But in some rare occurences,my return value is true but still the row is
> not deleted.Is there any special reason about this?

Most likely in those rare occurrences, some condition in the WHERE clause did not match for the row in question. The query will still be considered successful (no error) if no rows match the complete WHERE condition, as MySQL successfully deleted all zero matching rows.

If you want to know how many rows were deleted, most MySQL APIs give you a method to find out, such as mysql_affected_rows() or mysql_num_rows(), or something else depending on what language and API you are using.

Cheers
Tony

-- 
Tony Mountifield
Work: tony_at_softins.co.uk - http://www.softins.co.uk
Play: tony_at_mountifield.org - http://tony.mountifield.org
Received on Tue Mar 28 2017 - 17:30:57 CEST

Original text of this message