1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-22 14:32:25 +03:00

Implement PREPARE AS statement for ECPG.

Besides implementing the new statement this change fix some issues with the
parsing of PREPARE and EXECUTE statements. The different forms of these
statements are now all handled in a ujnified way.

Author: Matsumura-san <matsumura.ryo@jp.fujitsu.com>
This commit is contained in:
Michael Meskes
2019-05-22 04:58:29 +02:00
parent 5af2e976d7
commit a1dc6ab465
16 changed files with 1164 additions and 24 deletions

View File

@@ -56,6 +56,60 @@ isvarchar(unsigned char c)
return false;
}
bool
ecpg_register_prepared_stmt(struct statement *stmt)
{
struct statement *prep_stmt;
struct prepared_statement *this;
struct connection *con = NULL;
struct prepared_statement *prev = NULL;
char *real_connection_name;
int lineno = stmt->lineno;
real_connection_name = ecpg_get_con_name_by_declared_name(stmt->name);
if (real_connection_name == NULL)
real_connection_name = stmt->connection->name;
con = ecpg_get_connection(real_connection_name);
if (!ecpg_init(con, real_connection_name, stmt->lineno))
return false;
/* check if we already have prepared this statement */
this = ecpg_find_prepared_statement(stmt->name, con, &prev);
if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
return false;
/* allocate new statement */
this = (struct prepared_statement *) ecpg_alloc(sizeof(struct prepared_statement), lineno);
if (!this)
return false;
prep_stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno);
if (!stmt)
{
ecpg_free(this);
return false;
}
memset(prep_stmt, 0, sizeof(struct statement));
/* create statement */
prep_stmt->lineno = lineno;
prep_stmt->connection = con;
prep_stmt->command = ecpg_strdup(stmt->command, lineno);
prep_stmt->inlist = prep_stmt->outlist = NULL;
this->name = ecpg_strdup(stmt->name, lineno);
this->stmt = prep_stmt;
this->prepared = true;
if (con->prep_stmts == NULL)
this->next = NULL;
else
this->next = con->prep_stmts;
con->prep_stmts = this;
return true;
}
static bool
replace_variables(char **text, int lineno)
{