diff -u ruby-interbase-0.07/interbase.c ruby-interbase/interbase.c --- ruby-interbase-0.07/interbase.c Thu Nov 4 04:01:52 2004 +++ ruby-interbase/interbase.c Tue Apr 19 18:15:48 2005 @@ -194,6 +194,7 @@ static VALUE ibcurs_close _((VALUE)); static VALUE ibcurs_drop _((VALUE)); static VALUE ibcurs_execute _((int, VALUE*, VALUE)); +static VALUE ibcurs_rows_affected _((VALUE)); static void curs_mark(); static void curs_free(); @@ -876,7 +877,7 @@ return curs; } } - return Qnil; + return ibcurs_rows_affected(curs); } static VALUE @@ -1690,6 +1691,70 @@ return INT2NUM(STATEMENT_DML); } +static long +curs_rows_affected(curs) + struct IBcurs *curs; + +{ + int insertCount = 0; + int updateCount = 0; + int deleteCount = 0; + int selectCount = 0; + int l = 0; + int count = 0; + char *ptr; + char count_type; + char strBuffer[64] = ""; + char itemsReq[] = { isc_info_sql_records }; + + (void) isc_dsql_sql_info(isc_status, &curs->stmt, 1, itemsReq, sizeof(strBuffer), strBuffer); + ib_error_check(); + + if (strBuffer[0] != isc_info_sql_records) { + return -1; + } + + for (ptr = strBuffer + 3; *ptr != isc_info_end; ) + { + count_type = *ptr++; + l = isc_vax_integer (ptr, 2); + ptr += 2; + count = isc_vax_integer (ptr, (short)l); + ptr += l; + switch (count_type) { + + case isc_info_req_update_count: + updateCount = count; + break; + + case isc_info_req_delete_count: + deleteCount = count; + break; + + case isc_info_req_select_count: + selectCount = count; + break; + + case isc_info_req_insert_count: + insertCount = count; + break; + } + } + + return insertCount + updateCount + deleteCount; +} + +static VALUE +ibcurs_rows_affected(self) + VALUE self; +{ + struct IBcurs *curs; + + Data_Get_Struct(self, struct IBcurs, curs); + + return INT2NUM(curs_rows_affected(curs)); +} + static VALUE ibcurs_fetch(self) VALUE self; @@ -1827,6 +1892,7 @@ rb_cIBcursor = rb_define_class_under(rb_mInterBase, "Cursor", rb_cData); rb_define_method(rb_cIBcursor, "execute", ibcurs_execute, -1); + rb_define_method(rb_cIBcursor, "rows_affected", ibcurs_rows_affected, 0); rb_define_method(rb_cIBcursor, "description", ibcurs_description, 0); rb_define_method(rb_cIBcursor, "fetch", ibcurs_fetch, 0); rb_define_method(rb_cIBcursor, "fetchall", ibcurs_fetchall, 0);