3 #define POSTGRES_ECPG_INTERNAL
40 if ((connection_name == NULL) || (strcmp(connection_name,
"CURRENT") == 0))
61 if (strcmp(connection_name, con->
name) == 0)
75 if ((connection_name == NULL) || (strcmp(connection_name,
"CURRENT") == 0))
135 ecpg_log(
"ecpg_finish: connection %s closed\n", act->
name ? act->
name :
"(null)");
149 ecpg_log(
"ecpg_finish: called an extra time\n");
158 if (!
ecpg_init(con, connection_name, lineno))
161 ecpg_log(
"ECPGsetcommit on line %d: action \"%s\"; connection \"%s\"\n", lineno,
mode, con->
name);
174 else if (!con->
autocommit && strncmp(
mode,
"on", strlen(
"on")) == 0)
194 if (!
ecpg_init(con, connection_name, lineno))
224 if (strncmp(
sqlstate,
"00", 2) == 0)
227 ecpg_log(
"ECPGnoticeReceiver: %s\n", message);
243 sqlca->sqlwarn[2] =
'W';
244 sqlca->sqlwarn[0] =
'W';
246 strncpy(
sqlca->sqlerrm.sqlerrmc, message,
sizeof(
sqlca->sqlerrm.sqlerrmc));
247 sqlca->sqlerrm.sqlerrmc[
sizeof(
sqlca->sqlerrm.sqlerrmc) - 1] = 0;
248 sqlca->sqlerrm.sqlerrml = strlen(
sqlca->sqlerrm.sqlerrmc);
268 const char **conn_keywords;
269 const char **conn_values;
296 envname = getenv(
"PG_DBPATH");
304 if (
dbname == NULL && connection_name == NULL)
305 connection_name =
"DEFAULT";
313 ecpg_log(
"ECPGconnect: connection identifier %s is already in use\n",
327 if (strncmp(
dbname,
"tcp:", 4) == 0 || strncmp(
dbname,
"unix:", 5) == 0)
334 if (strncmp(
dbname,
"tcp:", 4) == 0)
336 else if (strncmp(
dbname,
"unix:", 5) == 0)
339 if (strncmp(
dbname + offset,
"postgresql://", strlen(
"postgresql://")) == 0)
347 offset += strlen(
"postgresql://");
349 tmp = strrchr(
dbname + offset,
'?');
367 tmp = strrchr(
dbname + offset,
':');
375 if (strncmp(
dbname,
"unix:", 5) == 0)
382 if (strcmp(
dbname + offset,
"localhost") != 0 &&
383 strcmp(
dbname + offset,
"127.0.0.1") != 0)
385 ecpg_log(
"ECPGconnect: non-localhost access via sockets on line %d\n", lineno);
403 if (*(
dbname + offset) !=
'\0')
414 tmp = strrchr(
dbname,
':');
422 tmp = strrchr(
dbname,
'@');
453 if (passwd && strlen(passwd) > 0)
461 conn_keywords = (
const char **)
ecpg_alloc((connect_params + 1) *
sizeof(
char *), lineno);
462 conn_values = (
const char **)
ecpg_alloc(connect_params *
sizeof(
char *), lineno);
463 if (conn_keywords == NULL || conn_values == NULL)
490 #ifdef HAVE_USELOCALE
493 ecpg_clocale = newlocale(LC_NUMERIC_MASK,
"C", (
locale_t) 0);
519 if (connection_name != NULL)
532 all_connections =
this;
536 ecpg_log(
"ECPGconnect: opening database %s on %s port %s %s%s %s%s\n",
537 realname ? realname :
"<DEFAULT>",
538 host ? host :
"<DEFAULT>",
546 conn_keywords[
i] =
"dbname";
547 conn_values[
i] = realname;
552 conn_keywords[
i] =
"host";
553 conn_values[
i] = host;
558 conn_keywords[
i] =
"port";
559 conn_values[
i] =
port;
564 conn_keywords[
i] =
"user";
565 conn_values[
i] =
user;
568 if (passwd && strlen(passwd) > 0)
570 conn_keywords[
i] =
"password";
571 conn_values[
i] = passwd;
595 for (token1 =
str; *token1 ==
' '; token1++)
598 for (
e = 0; token1[
e] && token1[
e] !=
'=';
e++)
604 for (token2 = token1 +
e + 1; *token2 ==
' '; token2++)
607 for (
a = 0; token2[
a] && token2[
a] !=
'&';
a++)
612 str = token2 +
a + 1;
617 conn_keywords[
i] = token1;
618 conn_values[
i] = token2;
630 conn_keywords[
i] = NULL;
648 const char *db = realname ? realname :
ecpg_gettext(
"<DEFAULT>");
690 if (strcmp(connection_name,
"ALL") == 0)
705 if (!
ecpg_init(con, connection_name, lineno))
#define Assert(condition)
static void ecpg_finish(struct connection *act)
static pthread_mutex_t connections_mutex
void ecpg_pthreads_init(void)
static struct connection * ecpg_get_connection_nr(const char *connection_name)
static pthread_key_t actual_connection_key
static struct connection * all_connections
bool ECPGsetconn(int lineno, const char *connection_name)
PGconn * ECPGget_PGconn(const char *connection_name)
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
struct connection * ecpg_get_connection(const char *connection_name)
bool ECPGdisconnect(int lineno, const char *connection_name)
static void ECPGnoticeReceiver(void *arg, const PGresult *result)
static pthread_once_t actual_connection_key_once
static struct connection * actual_connection
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
static void ecpg_actual_connection_init(void)
#define ECPG_WARNING_IN_TRANSACTION
#define ECPG_WARNING_UNKNOWN_PORTAL
#define ECPG_WARNING_PORTAL_EXISTS
#define ECPG_WARNING_NO_TRANSACTION
#define ECPG_OUT_OF_MEMORY
#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
#define ECPG_SQLSTATE_INVALID_CURSOR_NAME
void ecpg_log(const char *format,...) pg_attribute_printf(1
void ecpg_clear_auto_mem(void)
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION
char * ecpg_alloc(long size, int lineno)
char * ecpg_strdup(const char *string, int lineno)
#define ECPG_SQLSTATE_DUPLICATE_CURSOR
void ecpg_init_sqlca(struct sqlca_t *sqlca)
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
bool ecpg_internal_regression_mode
void ecpg_free(void *ptr)
int errmsg(const char *fmt,...)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
void PQfinish(PGconn *conn)
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
PGresult * PQexec(PGconn *conn, const char *query)
char * PQresultErrorField(const PGresult *res, int fieldcode)
struct sqlca_t * ECPGget_sqlca(void)
static PgChecksumMode mode
char * last_dir_separator(const char *filename)
#define PG_DIAG_MESSAGE_PRIMARY
int pthread_mutex_unlock(pthread_mutex_t *mp)
void * pthread_getspecific(pthread_key_t key)
int pthread_mutex_lock(pthread_mutex_t *mp)
void pthread_setspecific(pthread_key_t key, void *val)
#define PTHREAD_MUTEX_INITIALIZER
struct ECPGtype_information_cache * cache_head
struct prepared_statement * prep_stmts