UniDAC and Batch Options - when SQL UPDATE fails to UPDATE
Posted: Tue 21 Jun 2022 19:33
When using BATCH updates in UniDAC, the RowsAffected does reflect the number of rows UPDATED. However, I have the following scenario where there is an attempted UPDATE that fails because it could not find a corresponding table record based on the WHERE clause.
I build my UPDATE statement like this:
UPDATE SAMPLE Set AStringField=:AStringField WHERE AIncrementKey=:AIncrementKey
I then can use the PARAMS to populate the UPDATE statement, i.e.
When I run TUniQuery.Execute(2), I get back TUniQuery.RowsAffected := 1 telling me one row is updated. However, I'd like to know the error on the second update because it tried to update a record that did not exist.
Is there anyway to get information about which records in the PARAMS array failed to UPDATE?
Thanks.
Code: Select all
SAMPLE TABLE FIELDS
=============
AIncrementKey
AStringField(10)
AIntegerField
Code: Select all
SAMPLE DATA
=================
1 happy 10
2 sad 11
UPDATE SAMPLE Set AStringField=:AStringField WHERE AIncrementKey=:AIncrementKey
I then can use the PARAMS to populate the UPDATE statement, i.e.
Code: Select all
TUniQuery.Params[0][0].AsString := 'mad';
TUniQuery.Params[1][0].AsInteger := 2;
// Note that this record does not exist in the database table SAMPLE
TUniQuery.Params[0][1].AsString := 'frumpy';
TUniQuery.Params[1][1].AsInteger := 3;
Is there anyway to get information about which records in the PARAMS array failed to UPDATE?
Thanks.