Board index » delphi » Updating a row that doesn't exist - where's the error

Updating a row that doesn't exist - where's the error

I'm using Delphi 4 and Oracle 8.  I'm using a TQuery to update a table.
The row I'm updating doesn't exist but I'm not getting an error.  How do
I trap errors like this?  I'm currently using code like the following:

      try
        qSQL.ExecSQL;
      except
        on E : EDBEngineError do
           ShowMessage(E.Message);
        on E : Exception do
           ShowMessage(E.Message);
      end;

Thanks, Alan

 

Re:Updating a row that doesn't exist - where's the error


Quote
A Anderson <alana...@concentric.net> wrote:
>I'm using Delphi 4 and Oracle 8.  I'm using a TQuery to update a table.
>The row I'm updating doesn't exist but I'm not getting an error.  How do
>I trap errors like this?  I'm currently using code like the following:

Alan,

There may not be an error and that may be correct behavior.

Assuming that your SQL is in this form:
        Update ATable set Phone = '123-456-7890'
      Where LastName = 'Smith';

You will get no error if there are no rows that qualify. This is
normal behavior for SQL. That is, you asked for conditional update and
the SQL did what you asked. There was no error. The fact that the
condition as always false is not an error.

If you have to know whether there were any changes, there are two
options.

First, check the TQuery.RowsAffected property. If that works with your
database engine, then the property will return the number of rows
actually changed.

Otherwise, you must run a select and count the rows for that condition
before you actually make the changes. For example:
        Count(*) from ATable where LastName = 'Smith';

Phil Cain
--

Other Threads