From bd7c95f0c1a38becffceb3ea7234d57167f6d4bf Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Sat, 16 Feb 2019 10:55:17 +0100 Subject: Add DECLARE STATEMENT support to ECPG. DECLARE STATEMENT is a statement that lets users declare an identifier pointing at a connection. This identifier will be used in other embedded dynamic SQL statement such as PREPARE, EXECUTE, DECLARE CURSOR and so on. When connecting to a non-default connection, the AT clause can be used in a DECLARE STATEMENT once and is no longer needed in every dynamic SQL statement. This makes ECPG applications easier and more efficient. Moreover, writing code without designating connection explicitly improves portability. Authors: Ideriha-san ("Ideriha, Takeshi" ) Kuroda-san ("Kuroda, Hayato" ) Discussion: https://postgr.es/m4E72940DA2BF16479384A86D54D0988A565669DF@G01JPEXMBKW04 --- src/interfaces/ecpg/ecpglib/execute.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/interfaces/ecpg/ecpglib/execute.c') diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 4c499fb457d..2bdb558fabd 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -2074,9 +2074,32 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char { va_list args; bool ret; + const char *real_connection_name = NULL; + + real_connection_name = connection_name; + + if (!query) + { + ecpg_raise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL); + return false; + } + + /* Handle the EXEC SQL EXECUTE... statement */ + if (ECPGst_execute == st) + { + real_connection_name = ecpg_get_con_name_by_declared_name(query); + if (real_connection_name == NULL) + { + /* + * If can't get the connection name by declared name then using connection name + * coming from the parameter connection_name + */ + real_connection_name = connection_name; + } + } va_start(args, query); - ret = ecpg_do(lineno, compat, force_indicator, connection_name, + ret = ecpg_do(lineno, compat, force_indicator, real_connection_name, questionmarks, st, query, args); va_end(args); -- cgit v1.2.3