Subject Re: UPDATE question
Author burmair
--- In firebird-support@yahoogroups.com, "Ivan Prenosil"
<Ivan.Prenosil@...> wrote:
>
> >> Is there any way to determine the number of rows updated by an UPDATE
> >> operation, especially if that number is 0?
> >>
> >
> > If it is done inside PSQL (trigger or stored procedure), you can check
> > the ROW_COUNT context variable. I am not sure if it is possible using
> > standard DSQL though.
>
> isc_dsql_sql_info(...)
>
> Ivan
>

That's it. Thanks!

With information gleaned from the IB docs, ibase.h, and some code at
http://www.krugle.com/examples/p-3ZxxoAKYIVuyghiJ/StatementBase.cs
from Carlos Guzman Alvarez, I've got a solution. For future
reference, here's my C++ method to return the number of rows from an
insert, update, or delete. Note that you need the statement handle,
so you have to use isc_dsql_execute() (and all its little friends)
instead of isc_dsql_execute_immediate() for these operations.

int FBStatement::rowCount()
{
ISC_STATUS_ARRAY status;
char type_item[] = { isc_info_sql_records };
char buffer[256];

isc_dsql_sql_info(status,
&m_stmtHandle,
sizeof(type_item),
type_item,
sizeof(buffer),
buffer);
CHECK_FB_STATUS(status, "isc_info_sql_records");

int insertCount = 0;
int updateCount = 0;
int deleteCount = 0;
int selectCount = 0;
int pos = 0;
int length = 0;
int type = 0;

while ((type = buffer[pos++]) != isc_info_end)
{
length = isc_vax_integer(&buffer[pos], 2);
pos += 2;
switch (type)
{
case (isc_info_sql_records):
{
int subLen;
int subType;
while ((subType = buffer[pos++]) != isc_info_end)
{
subLen = isc_vax_integer(&buffer[pos], 2);
pos += 2;
switch (subType)
{
case (isc_info_req_insert_count):
insertCount = isc_vax_integer(&buffer[pos], subLen);
break;

case (isc_info_req_update_count):
updateCount = isc_vax_integer(&buffer[pos], subLen);
break;

case (isc_info_req_delete_count):
deleteCount = isc_vax_integer(&buffer[pos], subLen);
break;

case (isc_info_req_select_count):
selectCount = isc_vax_integer(&buffer[pos], subLen);
break;
}
pos += subLen;
}
break;
}
default:
pos += length;
break;
}
}

return insertCount + updateCount + deleteCount;
}