summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/descriptor.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2019-02-16 10:55:17 +0100
committerMichael Meskes <meskes@postgresql.org>2019-02-16 11:05:54 +0100
commitbd7c95f0c1a38becffceb3ea7234d57167f6d4bf (patch)
tree8ab862d314ec1e241ef0b90fc42edf3f6f5e4be8 /src/interfaces/ecpg/ecpglib/descriptor.c
parent02a6a54ecd6632f974b1b4eebfb2373363431084 (diff)
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" <ideriha.takeshi@jp.fujitsu.com>) Kuroda-san ("Kuroda, Hayato" <kuroda.hayato@jp.fujitsu.com>) Discussion: https://postgr.es/m4E72940DA2BF16479384A86D54D0988A565669DF@G01JPEXMBKW04
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/descriptor.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/descriptor.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index 5fca4dde20d..d19dce21108 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -842,6 +842,7 @@ ECPGdescribe(int line, int compat, bool input, const char *connection_name, cons
struct prepared_statement *prep;
PGresult *res;
va_list args;
+ const char *real_connection_name = NULL;
/* DESCRIBE INPUT is not yet supported */
if (input)
@@ -850,11 +851,21 @@ ECPGdescribe(int line, int compat, bool input, const char *connection_name, cons
return ret;
}
- con = ecpg_get_connection(connection_name);
+ real_connection_name = ecpg_get_con_name_by_declared_name(stmt_name);
+ 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;
+ }
+
+ con = ecpg_get_connection(real_connection_name);
if (!con)
{
ecpg_raise(line, ECPG_NO_CONN, ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST,
- connection_name ? connection_name : ecpg_gettext("NULL"));
+ real_connection_name ? real_connection_name : ecpg_gettext("NULL"));
return ret;
}
prep = ecpg_find_prepared_statement(stmt_name, con, NULL);