Added connection function to get the connection string to the server database

This commit is contained in:
Mario de Frutos 2015-11-11 17:50:22 +01:00
parent 55337efc3a
commit 22239d2da6
2 changed files with 19 additions and 6 deletions

View File

@ -0,0 +1,16 @@
--
-- Geocoder server connection config
--
-- The purpose of this function is provide to the PL/Proxy functions
-- the connection string needed to connect with the server
CREATE OR REPLACE FUNCTION cdb_geocoder_client._server_conn_str()
RETURNS text AS $$
DECLARE
db_connection_str text;
BEGIN
SELECT cdb_geocoder_client._config_get('db_server_config')->'connection_str' INTO db_connection_str;
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
RETURN db_connection_str;
END;
$$ LANGUAGE 'plpgsql';

View File

@ -7,12 +7,9 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin0_polygons(country_name text) CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin0_polygons(country_name text)
RETURNS Geometry AS $$ RETURNS Geometry AS $$
DECLARE DECLARE
db_connection_str text;
ret Geometry; ret Geometry;
BEGIN BEGIN
SELECT cdb_geocoder_client._config_get('db_server_config')->'connection_str' INTO db_connection_str; SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), country_name) INTO ret;
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), db_connection_str, country_name) INTO ret;
RETURN ret; RETURN ret;
END; END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER; $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
@ -22,9 +19,9 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin0_polygons(user_id name, tx_id bigint, db_connection_str text, country_name text) CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin0_polygons(user_id name, tx_id bigint, country_name text)
RETURNS Geometry AS $$ RETURNS Geometry AS $$
-- TODO check if we can move the config to its own function -- TODO check if we can move the config to its own function
CONNECT db_connection_str; CONNECT cdb_geocoder_client._server_conn_str();
SELECT cdb_geocoder_server.geocode_admin0_polygons(user_id, tx_id, country_name); SELECT cdb_geocoder_server.geocode_admin0_polygons(user_id, tx_id, country_name);
$$ LANGUAGE plproxy; $$ LANGUAGE plproxy;