PGDAC - Postgres - Create Function

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Lacmane
Posts: 5
Joined: Thu 30 Aug 2012 08:47

PGDAC - Postgres - Create Function

Post by Lacmane » Thu 28 Nov 2013 15:37

Hi,
I am trying to create a function with pgdac itself instead of running the script directly in sql (for example with pgAdmin). I need to do this because, I need to do data base version control, so for example when my software starts, it looks to the da base the version number and creates the new objects if has an old version.
But the following code gives me an error,
“Cannot insert multiple commands into a prepare statement”.
I can create/change tables, but cannot create/change functions. Is there a way I can do that?

/////////////////////////////////////////////////////////////////////
String sScript;

sScript = " CREATE OR REPLACE FUNCTION Test1(p_site_id integer, p_master_id integer, p_master_desc text, p_host_con_string text, p_port_con_string text, p_type text, p_export_type text, p_file_name text, b_down_cons boolean)";
sScript = sScript + " RETURNS boolean AS $BODY$ declare v_count integer; begin";
sScript = sScript + " BEGIN";
sScript = sScript + " select count(*) into v_count from masters where site_id = p_site_id and master_ids = p_master_id;";
sScript = sScript + " if(v_count>0) then";
sScript = sScript + " update masters set master_desc = p_master_desc, host_con_string = p_host_con_string, port_con_string = p_port_con_string, type = p_type, down_cons_enabled = b_down_cons, default_export_type = p_export_type, file_name = p_file_name, change_date = current_date+current_time";
sScript = sScript + " where site_id = p_site_id and master_ids = p_master_id;";
sScript = sScript + " end if;";
sScript = sScript + " exception when others then return false; END;";
sScript = sScript + " return true; end;";
sScript = sScript + " $BODY$ LANGUAGE plpgsql VOLATILE COST 100;";
sScript = sScript + " ALTER FUNCTION Test1(integer, integer, text, text, text, text, text, text, boolean)";
sScript = sScript + " OWNER TO postgres;";


pgTable->SQL->SetText(sScript.c_str());

pgTable->Execute();
/////////////////////////////////////////////////////////////////////////

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: PGDAC - Postgres - Create Function

Post by AlexP » Fri 29 Nov 2013 13:26

hello,

The TPgTable component is not designed for script execution, this component is designed for work with single tables and views. For script execution, there is a specialized component - TPgScript.

Ahsan12
Posts: 1
Joined: Thu 16 Oct 2014 11:04

Re: PGDAC - Postgres - Create Function

Post by Ahsan12 » Thu 16 Oct 2014 11:06

Hi,

I have installed Enterprise database on server machine with localhost as host.
www.vceplayer.com


For same machine we got public IP Address from internet which is configured on router.

When any request come from another machine to this IP, than this request redirect to local server machine IP.

Actually I want to access database using this public IP.

So, is it possible?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: PGDAC - Postgres - Create Function

Post by azyk » Fri 17 Oct 2014 08:33

We can't quite understand the point of your question. Try to describe the issue in more details.

Post Reply