Page 1 of 1

how to get a stored proc return value in Ent lib provider

Posted: Tue 23 May 2006 17:05
by Guest
hello, this is a basic question. We have bought the 2.5 Pro version and I need to call a Postgres function using the Enterprise Library data access block. The function takes only input parameters, and returns a bool, such as:

IF devcount >= 1 THEN
RETURN TRUE;
ELSE
RAISE NOTICE '01';
RETURN FALSE;
END IF;

I can run the function and it workd fine in pgadmin. I've not been able to get a correct return value using ExecuteScalar, but I see this only works if you are doing a SELECT. What would the syntax look like to get a function value returned from a RETURN statement like this ? Thanks.

Posted: Wed 24 May 2006 07:37
by Alexey
Don't understand what the problem.
Choose CommandType=StoredProc for PgSqlCommand component.
And write the code:

Code: Select all

      pgSqlConnection1.Open();
      pgSqlCommand1.Parameters[0].Value = 1;
      MessageBox.Show(pgSqlCommand1.ExecuteScalar().ToString());
Should return "True".

Posted: Wed 24 May 2006 22:22
by Guest
Probably my lack of knowledge writing the plpgsql functions with return values. I ended up explicitly declaring an OUT param and using ExecuteNonQuery and it worked fine.

Posted: Thu 25 May 2006 06:35
by Alexey
Function declaration might look like the following:

Code: Select all

CREATE OR REPLACE FUNCTION test.devcount(count int4)
  RETURNS bool AS
$BODY$
BEGIN
  IF $1 >= 1 THEN 
  RETURN TRUE; 
  ELSE 
  RAISE NOTICE '01'; 
  RETURN FALSE; 
  END IF; 
END;
  $BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION test.devcount(count int4) OWNER TO postgres;