mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Cleaned up ecpglib and renamed functions that do not need to be exported.
Created export list for ecpglib.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.46 2007/10/03 08:55:22 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.47 2007/10/03 11:11:12 meskes Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@ -71,7 +71,7 @@ ecpg_get_connection_nr(const char *connection_name)
|
||||
}
|
||||
|
||||
struct connection *
|
||||
ECPGget_connection(const char *connection_name)
|
||||
ecpg_get_connection(const char *connection_name)
|
||||
{
|
||||
struct connection *ret = NULL;
|
||||
|
||||
@ -117,7 +117,7 @@ ecpg_finish(struct connection * act)
|
||||
struct ECPGtype_information_cache *cache,
|
||||
*ptr;
|
||||
|
||||
ECPGdeallocate_all_conn(0, ECPG_COMPAT_PGSQL, act);
|
||||
ecpg_deallocate_all_conn(0, ECPG_COMPAT_PGSQL, act);
|
||||
PQfinish(act->connection);
|
||||
|
||||
/*
|
||||
@ -144,33 +144,33 @@ ecpg_finish(struct connection * act)
|
||||
if (actual_connection == act)
|
||||
actual_connection = all_connections;
|
||||
|
||||
ECPGlog("ecpg_finish: Connection %s closed.\n", act->name);
|
||||
ecpg_log("ecpg_finish: Connection %s closed.\n", act->name);
|
||||
|
||||
for (cache = act->cache_head; cache; ptr = cache, cache = cache->next, ECPGfree(ptr));
|
||||
ECPGfree(act->name);
|
||||
ECPGfree(act);
|
||||
for (cache = act->cache_head; cache; ptr = cache, cache = cache->next, ecpg_free(ptr));
|
||||
ecpg_free(act->name);
|
||||
ecpg_free(act);
|
||||
}
|
||||
else
|
||||
ECPGlog("ecpg_finish: called an extra time.\n");
|
||||
ecpg_log("ecpg_finish: called an extra time.\n");
|
||||
}
|
||||
|
||||
bool
|
||||
ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
|
||||
{
|
||||
struct connection *con = ECPGget_connection(connection_name);
|
||||
struct connection *con = ecpg_get_connection(connection_name);
|
||||
PGresult *results;
|
||||
|
||||
if (!ECPGinit(con, connection_name, lineno))
|
||||
if (!ecpg_init(con, connection_name, lineno))
|
||||
return (false);
|
||||
|
||||
ECPGlog("ECPGsetcommit line %d action = %s connection = %s\n", lineno, mode, con->name);
|
||||
ecpg_log("ECPGsetcommit line %d action = %s connection = %s\n", lineno, mode, con->name);
|
||||
|
||||
if (con->autocommit == true && strncmp(mode, "off", strlen("off")) == 0)
|
||||
{
|
||||
if (con->committed)
|
||||
{
|
||||
results = PQexec(con->connection, "begin transaction");
|
||||
if (!ECPGcheck_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
|
||||
if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
|
||||
return false;
|
||||
PQclear(results);
|
||||
con->committed = false;
|
||||
@ -182,7 +182,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
|
||||
if (!con->committed)
|
||||
{
|
||||
results = PQexec(con->connection, "commit");
|
||||
if (!ECPGcheck_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
|
||||
if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
|
||||
return false;
|
||||
PQclear(results);
|
||||
con->committed = true;
|
||||
@ -196,9 +196,9 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
|
||||
bool
|
||||
ECPGsetconn(int lineno, const char *connection_name)
|
||||
{
|
||||
struct connection *con = ECPGget_connection(connection_name);
|
||||
struct connection *con = ecpg_get_connection(connection_name);
|
||||
|
||||
if (!ECPGinit(con, connection_name, lineno))
|
||||
if (!ecpg_init(con, connection_name, lineno))
|
||||
return (false);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
@ -229,7 +229,7 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
|
||||
if (strncmp(sqlstate, "00", 2) == 0)
|
||||
return;
|
||||
|
||||
ECPGlog("ECPGnoticeReceiver %s\n", message);
|
||||
ecpg_log("ECPGnoticeReceiver %s\n", message);
|
||||
|
||||
/* map to SQLCODE for backward compatibility */
|
||||
if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME) == 0)
|
||||
@ -252,7 +252,7 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
|
||||
sqlca->sqlerrm.sqlerrmc[sizeof(sqlca->sqlerrm.sqlerrmc) - 1] = 0;
|
||||
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
|
||||
|
||||
ECPGlog("raising sqlcode %d\n", sqlcode);
|
||||
ecpg_log("raising sqlcode %d\n", sqlcode);
|
||||
}
|
||||
|
||||
|
||||
@ -263,17 +263,17 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||
enum COMPAT_MODE compat = c;
|
||||
struct connection *this;
|
||||
char *dbname = name ? ECPGstrdup(name, lineno) : NULL,
|
||||
char *dbname = name ? ecpg_strdup(name, lineno) : NULL,
|
||||
*host = NULL,
|
||||
*tmp,
|
||||
*port = NULL,
|
||||
*realname = NULL,
|
||||
*options = NULL;
|
||||
|
||||
ECPGinit_sqlca(sqlca);
|
||||
ecpg_init_sqlca(sqlca);
|
||||
|
||||
/* clear auto_mem structure because some error handling functions might access it */
|
||||
ECPGclear_auto_mem();
|
||||
ecpg_clear_auto_mem();
|
||||
|
||||
if (INFORMIX_MODE(compat))
|
||||
{
|
||||
@ -287,8 +287,8 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
envname = getenv("PG_DBPATH");
|
||||
if (envname)
|
||||
{
|
||||
ECPGfree(dbname);
|
||||
dbname = ECPGstrdup(envname, lineno);
|
||||
ecpg_free(dbname);
|
||||
dbname = ecpg_strdup(envname, lineno);
|
||||
}
|
||||
|
||||
}
|
||||
@ -301,15 +301,15 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
#endif
|
||||
|
||||
/* check if the identifier is unique */
|
||||
if (ECPGget_connection(connection_name))
|
||||
if (ecpg_get_connection(connection_name))
|
||||
{
|
||||
ECPGfree(dbname);
|
||||
ECPGlog("connect: connection identifier %s is already in use\n",
|
||||
ecpg_free(dbname);
|
||||
ecpg_log("ECPGconnect: connection identifier %s is already in use\n",
|
||||
connection_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((this = (struct connection *) ECPGalloc(sizeof(struct connection), lineno)) == NULL)
|
||||
if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
|
||||
return false;
|
||||
|
||||
if (dbname != NULL)
|
||||
@ -341,14 +341,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
tmp = strrchr(dbname + offset, '?');
|
||||
if (tmp != NULL) /* options given */
|
||||
{
|
||||
options = ECPGstrdup(tmp + 1, lineno);
|
||||
options = ecpg_strdup(tmp + 1, lineno);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
tmp = last_dir_separator(dbname + offset);
|
||||
if (tmp != NULL) /* database name given */
|
||||
{
|
||||
realname = ECPGstrdup(tmp + 1, lineno);
|
||||
realname = ecpg_strdup(tmp + 1, lineno);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
@ -361,53 +361,53 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
if ((tmp2 = strchr(tmp + 1, ':')) != NULL)
|
||||
{
|
||||
*tmp2 = '\0';
|
||||
host = ECPGstrdup(tmp + 1, lineno);
|
||||
host = ecpg_strdup(tmp + 1, lineno);
|
||||
if (strncmp(dbname, "unix:", 5) != 0)
|
||||
{
|
||||
ECPGlog("connect: socketname %s given for TCP connection in line %d\n", host, lineno);
|
||||
ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, realname ? realname : "<DEFAULT>");
|
||||
ecpg_log("ECPGconnect: socketname %s given for TCP connection in line %d\n", host, lineno);
|
||||
ecpg_raise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, realname ? realname : "<DEFAULT>");
|
||||
if (host)
|
||||
ECPGfree(host);
|
||||
ecpg_free(host);
|
||||
|
||||
/*
|
||||
* port not set yet if (port) ECPGfree(port);
|
||||
* port not set yet if (port) ecpg_free(port);
|
||||
*/
|
||||
if (options)
|
||||
ECPGfree(options);
|
||||
ecpg_free(options);
|
||||
if (realname)
|
||||
ECPGfree(realname);
|
||||
ecpg_free(realname);
|
||||
if (dbname)
|
||||
ECPGfree(dbname);
|
||||
ecpg_free(dbname);
|
||||
free(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
port = ECPGstrdup(tmp + 1, lineno);
|
||||
port = ecpg_strdup(tmp + 1, lineno);
|
||||
}
|
||||
|
||||
if (strncmp(dbname, "unix:", 5) == 0)
|
||||
{
|
||||
if (strcmp(dbname + offset, "localhost") != 0 && strcmp(dbname + offset, "127.0.0.1") != 0)
|
||||
{
|
||||
ECPGlog("connect: non-localhost access via sockets in line %d\n", lineno);
|
||||
ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, realname ? realname : "<DEFAULT>");
|
||||
ecpg_log("ECPGconnect: non-localhost access via sockets in line %d\n", lineno);
|
||||
ecpg_raise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, realname ? realname : "<DEFAULT>");
|
||||
if (host)
|
||||
ECPGfree(host);
|
||||
ecpg_free(host);
|
||||
if (port)
|
||||
ECPGfree(port);
|
||||
ecpg_free(port);
|
||||
if (options)
|
||||
ECPGfree(options);
|
||||
ecpg_free(options);
|
||||
if (realname)
|
||||
ECPGfree(realname);
|
||||
ecpg_free(realname);
|
||||
if (dbname)
|
||||
ECPGfree(dbname);
|
||||
ecpg_free(dbname);
|
||||
free(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
host = ECPGstrdup(dbname + offset, lineno);
|
||||
host = ecpg_strdup(dbname + offset, lineno);
|
||||
|
||||
}
|
||||
}
|
||||
@ -417,18 +417,18 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
tmp = strrchr(dbname, ':');
|
||||
if (tmp != NULL) /* port number given */
|
||||
{
|
||||
port = ECPGstrdup(tmp + 1, lineno);
|
||||
port = ecpg_strdup(tmp + 1, lineno);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
tmp = strrchr(dbname, '@');
|
||||
if (tmp != NULL) /* host name given */
|
||||
{
|
||||
host = ECPGstrdup(tmp + 1, lineno);
|
||||
host = ecpg_strdup(tmp + 1, lineno);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
realname = (strlen(dbname) > 0) ? ECPGstrdup(dbname, lineno) : NULL;
|
||||
realname = (strlen(dbname) > 0) ? ecpg_strdup(dbname, lineno) : NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -439,9 +439,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
pthread_mutex_lock(&connections_mutex);
|
||||
#endif
|
||||
if (connection_name != NULL)
|
||||
this->name = ECPGstrdup(connection_name, lineno);
|
||||
this->name = ecpg_strdup(connection_name, lineno);
|
||||
else
|
||||
this->name = ECPGstrdup(realname, lineno);
|
||||
this->name = ecpg_strdup(realname, lineno);
|
||||
|
||||
this->cache_head = NULL;
|
||||
this->prep_stmts = NULL;
|
||||
@ -457,7 +457,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
#endif
|
||||
actual_connection = all_connections;
|
||||
|
||||
ECPGlog("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n",
|
||||
ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n",
|
||||
realname ? realname : "<DEFAULT>",
|
||||
host ? host : "<DEFAULT>",
|
||||
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
|
||||
@ -471,7 +471,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
const char *errmsg = PQerrorMessage(this->connection);
|
||||
const char *db = realname ? realname : "<DEFAULT>";
|
||||
|
||||
ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
|
||||
ecpg_log("ECPGconnect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
|
||||
db,
|
||||
host ? host : "<DEFAULT>",
|
||||
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
|
||||
@ -484,17 +484,17 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db);
|
||||
ecpg_raise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db);
|
||||
if (host)
|
||||
ECPGfree(host);
|
||||
ecpg_free(host);
|
||||
if (port)
|
||||
ECPGfree(port);
|
||||
ecpg_free(port);
|
||||
if (options)
|
||||
ECPGfree(options);
|
||||
ecpg_free(options);
|
||||
if (realname)
|
||||
ECPGfree(realname);
|
||||
ecpg_free(realname);
|
||||
if (dbname)
|
||||
ECPGfree(dbname);
|
||||
ecpg_free(dbname);
|
||||
return false;
|
||||
}
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
@ -502,15 +502,15 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
#endif
|
||||
|
||||
if (host)
|
||||
ECPGfree(host);
|
||||
ecpg_free(host);
|
||||
if (port)
|
||||
ECPGfree(port);
|
||||
ecpg_free(port);
|
||||
if (options)
|
||||
ECPGfree(options);
|
||||
ecpg_free(options);
|
||||
if (realname)
|
||||
ECPGfree(realname);
|
||||
ecpg_free(realname);
|
||||
if (dbname)
|
||||
ECPGfree(dbname);
|
||||
ecpg_free(dbname);
|
||||
|
||||
this->committed = true;
|
||||
this->autocommit = autocommit;
|
||||
@ -532,7 +532,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
|
||||
|
||||
if (strcmp(connection_name, "ALL") == 0)
|
||||
{
|
||||
ECPGinit_sqlca(sqlca);
|
||||
ecpg_init_sqlca(sqlca);
|
||||
for (con = all_connections; con;)
|
||||
{
|
||||
struct connection *f = con;
|
||||
@ -545,7 +545,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
|
||||
{
|
||||
con = ecpg_get_connection_nr(connection_name);
|
||||
|
||||
if (!ECPGinit(con, connection_name, lineno))
|
||||
if (!ecpg_init(con, connection_name, lineno))
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
|
Reference in New Issue
Block a user