Skip site navigation (1) Skip section navigation (2)

Re: Function return number of affected rows

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "Francisco Figueiredo Jr(dot)" <fxjrlists(at)yahoo(dot)com(dot)br>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Function return number of affected rows
Date: 2005-02-10 22:15:05
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
On Thu, Feb 10, 2005 at 02:51:46PM -0200, Francisco Figueiredo Jr. wrote:
> Michael Fuhr wrote:
> >Does Npgsql use its own implemention of the PostgreSQL protocol?
> >If so, then that implementation will have to provide the desired
> >functionality itself.
> Yeap. Npgsql implements protocol itself. This is exactly the problem. 
> I'm not receiving the CompletedResponse protocol message when executing 
> the insert inside a function. It is through the CompletedResponse 
> postgresql server says how many rows were affected. But it seems that 
> when calling a function it doesn't return any.

I haven't used Npgsql, but the documentation has an example with
the following code:

  NpgsqlCommand command = new NpgsqlCommand("insert into table1 values(1, 1)", conn);
  Int32 rowsaffected;
      rowsaffected = command.ExecuteNonQuery();

Is that what you're trying to do?  Does it not work?

I downloaded the latest Npgsql source and found the following in

  // The number of rows affected is in the third token for insert queries
  // and in the second token for update and delete queries.
  // In other words, it is the last token in the 0-based array.

  return Int32.Parse(ret_string_tokens[ret_string_tokens.Length - 1]);

It looks like ExecuteNonQuery() is at least attempting to return
the number of rows affected.

Have I misunderstood what you're doing?

Michael Fuhr

In response to


pgsql-interfaces by date

Next:From: Seamus Thomas CarrollDate: 2005-02-10 23:17:11
Subject: Re: Help with adding C-Language Functions
Previous:From: Tom LaneDate: 2005-02-10 20:43:39
Subject: Re: Help with adding C-Language Functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group