Page 1 of 1

PGDAC - Postgres - Create Function

Posted: Thu 28 Nov 2013 15:37
by Lacmane
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();
/////////////////////////////////////////////////////////////////////////

Re: PGDAC - Postgres - Create Function

Posted: Fri 29 Nov 2013 13:26
by AlexP
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.

Re: PGDAC - Postgres - Create Function

Posted: Thu 16 Oct 2014 11:06
by Ahsan12
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?

Re: PGDAC - Postgres - Create Function

Posted: Fri 17 Oct 2014 08:33
by azyk
We can't quite understand the point of your question. Try to describe the issue in more details.