diff -ur src/modules/Postgres.orig/pg_types.h src/modules/Postgres/pg_types.h --- src/modules/Postgres.orig/pg_types.h Thu Jan 19 18:05:57 2006 +++ src/modules/Postgres/pg_types.h Thu Jan 19 16:48:07 2006 @@ -25,6 +25,7 @@ int dofetch; int docommit; int lastcommit; + int last_rows; #ifdef PQ_THREADSAFE PIKE_MUTEX_T mutex; #endif diff -ur src/modules/Postgres.orig/postgres.c src/modules/Postgres/postgres.c --- src/modules/Postgres.orig/postgres.c Thu Jan 19 18:05:57 2006 +++ src/modules/Postgres/postgres.c Thu Jan 19 17:49:56 2006 @@ -90,6 +90,7 @@ THIS->docommit=0; THIS->dofetch=0; THIS->lastcommit=0; + THIS->last_rows=-1; #ifdef PQ_THREADSAFE mt_init(&THIS->mutex); #endif @@ -554,6 +555,7 @@ case PGRES_COMMAND_OK: pgdebug("\tOk.\n"); THIS->last_result=NULL; + THIS->last_rows=atoi(PQcmdTuples(res)); PQclear(res); push_int(0); return; @@ -571,13 +573,14 @@ case PGRES_TUPLES_OK: pgdebug("\tResult.\n"); THIS->last_result=res; + THIS->last_rows=PQntuples(res); push_object(this_object()); push_object(clone_object(pgresult_program,1)); return; default: Pike_error ("Unimplemented server feature.\n"); } - Pike_error ("Internal error in postgresmodule.\n"); + Pike_error ("Internal error in postgres module.\n"); } @@ -730,6 +733,17 @@ Pike_error ("Bad connection.\n"); } +/*! @decl int affected_rows() + *! + *! This function returns the number of rows affected by the last query. + */ + +static void f_affected_rows (INT32 args) +{ + check_all_args("Postgres->affected_rows",args,0); + push_int(THIS->last_rows); +} + /*! @endclass *! *! @endmodule @@ -764,6 +778,9 @@ /* function(void:string) */ ADD_FUNCTION("host_info", f_host_info,tFunc(tVoid,tStr), 0); + + /* function(void:int) */ + ADD_FUNCTION("affected_rows", f_affected_rows,tFunc(tVoid,tInt), 0); /* postgres-specific functions */ /* function(void:void) */