parent
ffa3bfbc30
commit
4f70680177
|
@ -1,5 +1,5 @@
|
||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
dnl $Header: /cvsroot/pgsql/configure.in,v 1.264 2003/06/14 19:21:42 momjian Exp $
|
dnl $Header: /cvsroot/pgsql/configure.in,v 1.265 2003/06/15 04:07:58 momjian Exp $
|
||||||
dnl
|
dnl
|
||||||
dnl Developers, please strive to achieve this order:
|
dnl Developers, please strive to achieve this order:
|
||||||
dnl
|
dnl
|
||||||
|
@ -323,8 +323,8 @@ IFS=$ac_save_IFS
|
||||||
# Enable libpq to be thread-safe
|
# Enable libpq to be thread-safe
|
||||||
#
|
#
|
||||||
AC_MSG_CHECKING([allow threaded libpq])
|
AC_MSG_CHECKING([allow threaded libpq])
|
||||||
PGAC_ARG_BOOL(with, threads, no, [ --with-threads allow libpq to be thread-safe],
|
PGAC_ARG_BOOL(with, threads, no, [ --with-threads allow libpq and ecpg to be thread-safe],
|
||||||
[AC_DEFINE([USE_THREADS], 1, [Define to 1 to build libpq with threads. (--with-threads)])])
|
[AC_DEFINE([USE_THREADS], 1, [Define to 1 to build libpq and ecpg to be thread-safe. (--with-threads)])])
|
||||||
|
|
||||||
AC_MSG_RESULT([$with_threads])
|
AC_MSG_RESULT([$with_threads])
|
||||||
AC_SUBST(with_threads)
|
AC_SUBST(with_threads)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ecpg.sgml,v 1.43 2003/03/25 16:15:35 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ecpg.sgml,v 1.44 2003/06/15 04:07:58 momjian Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<chapter id="ecpg">
|
<chapter id="ecpg">
|
||||||
|
@ -749,6 +749,13 @@ EXEC SQL INCLUDE <replaceable>filename</replaceable>;
|
||||||
in the arguments specified for output.
|
in the arguments specified for output.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
<application>ecpg</application> is thread-safe if it is compiled using
|
||||||
|
the <literal>--with-threads</> <filename>configure</filename>
|
||||||
|
command-line option. (You might need to use other threading
|
||||||
|
command-line options to compile your client code.)
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The preprocessor program is called <filename>ecpg</filename> and is
|
The preprocessor program is called <filename>ecpg</filename> and is
|
||||||
included in a normal <productname>PostgreSQL</> installation.
|
included in a normal <productname>PostgreSQL</> installation.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/installation.sgml,v 1.134 2003/06/13 23:10:07 momjian Exp $ -->
|
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/installation.sgml,v 1.135 2003/06/15 04:07:58 momjian Exp $ -->
|
||||||
|
|
||||||
<chapter id="installation">
|
<chapter id="installation">
|
||||||
<title><![%standalone-include[<productname>PostgreSQL</>]]>
|
<title><![%standalone-include[<productname>PostgreSQL</>]]>
|
||||||
|
@ -918,7 +918,8 @@ JAVACMD=$JAVA_HOME/bin/java
|
||||||
<term><option>--with-threads</option></term>
|
<term><option>--with-threads</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Allow separate libpq threads to safely control their private connection handles.
|
Allow separate libpq and ecpg threads to safely control their
|
||||||
|
private connection handles.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 1994, Regents of the University of California
|
# Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.3 2003/05/22 17:20:44 petere Exp $
|
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.4 2003/06/15 04:07:58 momjian Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -13,15 +13,15 @@ top_builddir = ../../../..
|
||||||
include $(top_builddir)/src/Makefile.global
|
include $(top_builddir)/src/Makefile.global
|
||||||
|
|
||||||
NAME= ecpg
|
NAME= ecpg
|
||||||
SO_MAJOR_VERSION= 3
|
SO_MAJOR_VERSION= 4
|
||||||
SO_MINOR_VERSION= 4.2
|
SO_MINOR_VERSION= 1.1
|
||||||
|
|
||||||
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS)
|
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CFLAGS)
|
||||||
|
|
||||||
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
|
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
|
||||||
connect.o misc.o
|
connect.o misc.o
|
||||||
|
|
||||||
SHLIB_LINK = -L../pgtypeslib -lpgtypes $(libpq)
|
SHLIB_LINK = -L../pgtypeslib -lpgtypes $(libpq) $(THREAD_LIBS)
|
||||||
|
|
||||||
all: all-lib
|
all: all-lib
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,53 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.6 2003/06/13 10:50:57 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.7 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
#include "ecpgtype.h"
|
#include "ecpgtype.h"
|
||||||
#include "ecpglib.h"
|
#include "ecpglib.h"
|
||||||
#include "ecpgerrno.h"
|
#include "ecpgerrno.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
#include "sqlca.h"
|
#include "sqlca.h"
|
||||||
|
|
||||||
static struct connection *all_connections = NULL,
|
#ifdef USE_THREADS
|
||||||
*actual_connection = NULL;
|
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
#endif
|
||||||
|
static struct connection *all_connections = NULL;
|
||||||
|
static struct connection *actual_connection = NULL;
|
||||||
|
|
||||||
struct connection *
|
struct connection *
|
||||||
ECPGget_connection(const char *connection_name)
|
ECPGget_connection(const char *connection_name)
|
||||||
{
|
{
|
||||||
struct connection *con = all_connections;
|
struct connection *ret = NULL;
|
||||||
|
|
||||||
if (connection_name == NULL || strcmp(connection_name, "CURRENT") == 0)
|
#ifdef USE_THREADS
|
||||||
return actual_connection;
|
pthread_mutex_lock(&connections_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (; con && strcmp(connection_name, con->name) != 0; con = con->next);
|
if( (connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0) )
|
||||||
if (con)
|
{
|
||||||
return con;
|
ret = actual_connection;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return NULL;
|
{
|
||||||
|
struct connection *con;
|
||||||
|
|
||||||
|
for( con = all_connections; con != NULL; con = con->next)
|
||||||
|
{
|
||||||
|
if( strcmp(connection_name, con->name) == 0 )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = con;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&connections_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -37,6 +61,10 @@ ecpg_finish(struct connection * act)
|
||||||
ECPGlog("ecpg_finish: finishing %s.\n", act->name);
|
ECPGlog("ecpg_finish: finishing %s.\n", act->name);
|
||||||
PQfinish(act->connection);
|
PQfinish(act->connection);
|
||||||
|
|
||||||
|
/* no need to lock connections_mutex - we're always called
|
||||||
|
by ECPGdisconnect or ECPGconnect, which are holding
|
||||||
|
the lock */
|
||||||
|
|
||||||
/* remove act from the list */
|
/* remove act from the list */
|
||||||
if (act == all_connections)
|
if (act == all_connections)
|
||||||
all_connections = act->next;
|
all_connections = act->next;
|
||||||
|
@ -118,17 +146,18 @@ ECPGsetconn(int lineno, const char *connection_name)
|
||||||
static void
|
static void
|
||||||
ECPGnoticeProcessor_raise(int code, const char *message)
|
ECPGnoticeProcessor_raise(int code, const char *message)
|
||||||
{
|
{
|
||||||
sqlca.sqlcode = code;
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
strncpy(sqlca.sqlerrm.sqlerrmc, message, sizeof(sqlca.sqlerrm.sqlerrmc));
|
sqlca->sqlcode = code;
|
||||||
sqlca.sqlerrm.sqlerrmc[sizeof(sqlca.sqlerrm.sqlerrmc) - 1] = 0;
|
strncpy(sqlca->sqlerrm.sqlerrmc, message, sizeof(sqlca->sqlerrm.sqlerrmc));
|
||||||
sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc);
|
sqlca->sqlerrm.sqlerrmc[sizeof(sqlca->sqlerrm.sqlerrmc) - 1] = 0;
|
||||||
|
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
|
||||||
|
|
||||||
/* remove trailing newline */
|
/* remove trailing newline */
|
||||||
if (sqlca.sqlerrm.sqlerrml
|
if (sqlca->sqlerrm.sqlerrml
|
||||||
&& sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml - 1] == '\n')
|
&& sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml - 1] == '\n')
|
||||||
{
|
{
|
||||||
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml - 1] = 0;
|
sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml - 1] = 0;
|
||||||
sqlca.sqlerrm.sqlerrml--;
|
sqlca->sqlerrm.sqlerrml--;
|
||||||
}
|
}
|
||||||
|
|
||||||
ECPGlog("raising sqlcode %d\n", code);
|
ECPGlog("raising sqlcode %d\n", code);
|
||||||
|
@ -141,6 +170,8 @@ ECPGnoticeProcessor_raise(int code, const char *message)
|
||||||
static void
|
static void
|
||||||
ECPGnoticeProcessor(void *arg, const char *message)
|
ECPGnoticeProcessor(void *arg, const char *message)
|
||||||
{
|
{
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
/* these notices raise an error */
|
/* these notices raise an error */
|
||||||
if (strncmp(message, "WARNING: ", 9))
|
if (strncmp(message, "WARNING: ", 9))
|
||||||
{
|
{
|
||||||
|
@ -245,7 +276,7 @@ ECPGnoticeProcessor(void *arg, const char *message)
|
||||||
if (strstr(message, "cannot be rolled back"))
|
if (strstr(message, "cannot be rolled back"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* these and other unmentioned should set sqlca.sqlwarn[2] */
|
/* these and other unmentioned should set sqlca->sqlwarn[2] */
|
||||||
/* WARNING: The ':' operator is deprecated. Use exp(x) instead. */
|
/* WARNING: The ':' operator is deprecated. Use exp(x) instead. */
|
||||||
/* WARNING: Rel *: Uninitialized page 0 - fixing */
|
/* WARNING: Rel *: Uninitialized page 0 - fixing */
|
||||||
/* WARNING: PortalHeapMemoryFree: * not in alloc set! */
|
/* WARNING: PortalHeapMemoryFree: * not in alloc set! */
|
||||||
|
@ -253,14 +284,15 @@ ECPGnoticeProcessor(void *arg, const char *message)
|
||||||
/* WARNING: identifier "*" will be truncated to "*" */
|
/* WARNING: identifier "*" will be truncated to "*" */
|
||||||
/* WARNING: InvalidateSharedInvalid: cache state reset */
|
/* WARNING: InvalidateSharedInvalid: cache state reset */
|
||||||
/* WARNING: RegisterSharedInvalid: SI buffer overflow */
|
/* WARNING: RegisterSharedInvalid: SI buffer overflow */
|
||||||
sqlca.sqlwarn[2] = 'W';
|
sqlca->sqlwarn[2] = 'W';
|
||||||
sqlca.sqlwarn[0] = 'W';
|
sqlca->sqlwarn[0] = 'W';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this contains some quick hacks, needs to be cleaned up, but it works */
|
/* this contains some quick hacks, needs to be cleaned up, but it works */
|
||||||
bool
|
bool
|
||||||
ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
|
ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
|
||||||
{
|
{
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
struct connection *this;
|
struct connection *this;
|
||||||
char *dbname = strdup(name),
|
char *dbname = strdup(name),
|
||||||
*host = NULL,
|
*host = NULL,
|
||||||
|
@ -269,7 +301,7 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
|
||||||
*realname = NULL,
|
*realname = NULL,
|
||||||
*options = NULL;
|
*options = NULL;
|
||||||
|
|
||||||
ECPGinit_sqlca();
|
ECPGinit_sqlca(sqlca);
|
||||||
|
|
||||||
if ((this = (struct connection *) ECPGalloc(sizeof(struct connection), lineno)) == NULL)
|
if ((this = (struct connection *) ECPGalloc(sizeof(struct connection), lineno)) == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
@ -394,6 +426,9 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
|
||||||
realname = strdup(dbname);
|
realname = strdup(dbname);
|
||||||
|
|
||||||
/* add connection to our list */
|
/* add connection to our list */
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_lock(&connections_mutex);
|
||||||
|
#endif
|
||||||
if (connection_name != NULL)
|
if (connection_name != NULL)
|
||||||
this->name = ECPGstrdup(connection_name, lineno);
|
this->name = ECPGstrdup(connection_name, lineno);
|
||||||
else
|
else
|
||||||
|
@ -424,6 +459,9 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
|
||||||
|
|
||||||
set_backend_err(errmsg, lineno);
|
set_backend_err(errmsg, lineno);
|
||||||
ecpg_finish(this);
|
ecpg_finish(this);
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&connections_mutex);
|
||||||
|
#endif
|
||||||
ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
|
ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
|
||||||
db,
|
db,
|
||||||
host ? host : "<DEFAULT>",
|
host ? host : "<DEFAULT>",
|
||||||
|
@ -445,6 +483,9 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
|
||||||
ECPGfree(dbname);
|
ECPGfree(dbname);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&connections_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (host)
|
if (host)
|
||||||
ECPGfree(host);
|
ECPGfree(host);
|
||||||
|
@ -468,11 +509,16 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
|
||||||
bool
|
bool
|
||||||
ECPGdisconnect(int lineno, const char *connection_name)
|
ECPGdisconnect(int lineno, const char *connection_name)
|
||||||
{
|
{
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
struct connection *con;
|
struct connection *con;
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_lock(&connections_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (strcmp(connection_name, "ALL") == 0)
|
if (strcmp(connection_name, "ALL") == 0)
|
||||||
{
|
{
|
||||||
ECPGinit_sqlca();
|
ECPGinit_sqlca(sqlca);
|
||||||
for (con = all_connections; con;)
|
for (con = all_connections; con;)
|
||||||
{
|
{
|
||||||
struct connection *f = con;
|
struct connection *f = con;
|
||||||
|
@ -486,10 +532,19 @@ ECPGdisconnect(int lineno, const char *connection_name)
|
||||||
con = ECPGget_connection(connection_name);
|
con = ECPGget_connection(connection_name);
|
||||||
|
|
||||||
if (!ECPGinit(con, connection_name, lineno))
|
if (!ECPGinit(con, connection_name, lineno))
|
||||||
|
{
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&connections_mutex);
|
||||||
|
#endif
|
||||||
return (false);
|
return (false);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ecpg_finish(con);
|
ecpg_finish(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&connections_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.4 2003/04/01 14:37:25 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.5 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -21,6 +22,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||||
char *var, char *ind, long varcharsize, long offset,
|
char *var, char *ind, long varcharsize, long offset,
|
||||||
long ind_offset, bool isarray)
|
long ind_offset, bool isarray)
|
||||||
{
|
{
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
|
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
|
||||||
|
|
||||||
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld\n", lineno, pval ? pval : "", offset);
|
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld\n", lineno, pval ? pval : "", offset);
|
||||||
|
@ -328,7 +330,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
|
sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -373,7 +375,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
|
sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
|
||||||
|
|
||||||
variable->len = varcharsize;
|
variable->len = varcharsize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
/* dynamic SQL support routines
|
/* dynamic SQL support routines
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.2 2003/05/30 13:22:02 meskes Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.3 2003/06/15 04:07:58 momjian Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "pg_type.h"
|
#include "pg_type.h"
|
||||||
|
|
||||||
|
@ -51,14 +52,15 @@ bool
|
||||||
ECPGget_desc_header(int lineno, char *desc_name, int *count)
|
ECPGget_desc_header(int lineno, char *desc_name, int *count)
|
||||||
{
|
{
|
||||||
PGresult *ECPGresult;
|
PGresult *ECPGresult;
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
ECPGinit_sqlca();
|
ECPGinit_sqlca(sqlca);
|
||||||
ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
|
ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
|
||||||
if (!ECPGresult)
|
if (!ECPGresult)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*count = PQnfields(ECPGresult);
|
*count = PQnfields(ECPGresult);
|
||||||
sqlca.sqlerrd[2] = 1;
|
sqlca->sqlerrd[2] = 1;
|
||||||
ECPGlog("ECPGget_desc_header: found %d attributes.\n", *count);
|
ECPGlog("ECPGget_desc_header: found %d attributes.\n", *count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -149,9 +151,10 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
|
||||||
int ntuples,
|
int ntuples,
|
||||||
act_tuple;
|
act_tuple;
|
||||||
struct variable data_var;
|
struct variable data_var;
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
va_start(args, index);
|
va_start(args, index);
|
||||||
ECPGinit_sqlca();
|
ECPGinit_sqlca(sqlca);
|
||||||
ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
|
ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
|
||||||
if (!ECPGresult)
|
if (!ECPGresult)
|
||||||
return (false);
|
return (false);
|
||||||
|
@ -378,7 +381,7 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
|
||||||
ECPGlog("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
|
ECPGlog("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sqlca.sqlerrd[2] = ntuples;
|
sqlca->sqlerrd[2] = ntuples;
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,8 +390,9 @@ ECPGdeallocate_desc(int line, const char *name)
|
||||||
{
|
{
|
||||||
struct descriptor *i;
|
struct descriptor *i;
|
||||||
struct descriptor **lastptr = &all_descriptors;
|
struct descriptor **lastptr = &all_descriptors;
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
ECPGinit_sqlca();
|
ECPGinit_sqlca(sqlca);
|
||||||
for (i = all_descriptors; i; lastptr = &i->next, i = i->next)
|
for (i = all_descriptors; i; lastptr = &i->next, i = i->next)
|
||||||
{
|
{
|
||||||
if (!strcmp(name, i->name))
|
if (!strcmp(name, i->name))
|
||||||
|
@ -408,8 +412,9 @@ bool
|
||||||
ECPGallocate_desc(int line, const char *name)
|
ECPGallocate_desc(int line, const char *name)
|
||||||
{
|
{
|
||||||
struct descriptor *new;
|
struct descriptor *new;
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
ECPGinit_sqlca();
|
ECPGinit_sqlca(sqlca);
|
||||||
new = (struct descriptor *) ECPGalloc(sizeof(struct descriptor), line);
|
new = (struct descriptor *) ECPGalloc(sizeof(struct descriptor), line);
|
||||||
if (!new)
|
if (!new)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.2 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -17,117 +18,118 @@ static char *ECPGerr;
|
||||||
void
|
void
|
||||||
ECPGraise(int line, int code, const char *str)
|
ECPGraise(int line, int code, const char *str)
|
||||||
{
|
{
|
||||||
sqlca.sqlcode = code;
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
sqlca->sqlcode = code;
|
||||||
|
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case ECPG_NOT_FOUND:
|
case ECPG_NOT_FOUND:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"No data found in line %d.", line);
|
"No data found in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_OUT_OF_MEMORY:
|
case ECPG_OUT_OF_MEMORY:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Out of memory in line %d.", line);
|
"Out of memory in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_UNSUPPORTED:
|
case ECPG_UNSUPPORTED:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Unsupported type %s in line %d.", str, line);
|
"Unsupported type %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_TOO_MANY_ARGUMENTS:
|
case ECPG_TOO_MANY_ARGUMENTS:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Too many arguments in line %d.", line);
|
"Too many arguments in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_TOO_FEW_ARGUMENTS:
|
case ECPG_TOO_FEW_ARGUMENTS:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Too few arguments in line %d.", line);
|
"Too few arguments in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_INT_FORMAT:
|
case ECPG_INT_FORMAT:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Not correctly formatted int type: %s line %d.", str, line);
|
"Not correctly formatted int type: %s line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_UINT_FORMAT:
|
case ECPG_UINT_FORMAT:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Not correctly formatted unsigned type: %s in line %d.", str, line);
|
"Not correctly formatted unsigned type: %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_FLOAT_FORMAT:
|
case ECPG_FLOAT_FORMAT:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Not correctly formatted floating-point type: %s in line %d.", str, line);
|
"Not correctly formatted floating-point type: %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_CONVERT_BOOL:
|
case ECPG_CONVERT_BOOL:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Unable to convert %s to bool on line %d.", str, line);
|
"Unable to convert %s to bool on line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_EMPTY:
|
case ECPG_EMPTY:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Empty query in line %d.", line);
|
"Empty query in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_MISSING_INDICATOR:
|
case ECPG_MISSING_INDICATOR:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"NULL value without indicator in line %d.", line);
|
"NULL value without indicator in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_NO_ARRAY:
|
case ECPG_NO_ARRAY:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Variable is not an array in line %d.", line);
|
"Variable is not an array in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_DATA_NOT_ARRAY:
|
case ECPG_DATA_NOT_ARRAY:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Data read from backend is not an array in line %d.", line);
|
"Data read from backend is not an array in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_ARRAY_INSERT:
|
case ECPG_ARRAY_INSERT:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Trying to insert an array of variables in line %d.", line);
|
"Trying to insert an array of variables in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_NO_CONN:
|
case ECPG_NO_CONN:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"No such connection %s in line %d.", str, line);
|
"No such connection %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_NOT_CONN:
|
case ECPG_NOT_CONN:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Not connected to '%s' in line %d.", str, line);
|
"Not connected to '%s' in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_INVALID_STMT:
|
case ECPG_INVALID_STMT:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Invalid statement name %s in line %d.", str, line);
|
"Invalid statement name %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_UNKNOWN_DESCRIPTOR:
|
case ECPG_UNKNOWN_DESCRIPTOR:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Descriptor %s not found in line %d.", str, line);
|
"Descriptor %s not found in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_INVALID_DESCRIPTOR_INDEX:
|
case ECPG_INVALID_DESCRIPTOR_INDEX:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Descriptor index out of range in line %d.", line);
|
"Descriptor index out of range in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_UNKNOWN_DESCRIPTOR_ITEM:
|
case ECPG_UNKNOWN_DESCRIPTOR_ITEM:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Unknown descriptor item %s in line %d.", str, line);
|
"Unknown descriptor item %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_VAR_NOT_NUMERIC:
|
case ECPG_VAR_NOT_NUMERIC:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Variable is not a numeric type in line %d.", line);
|
"Variable is not a numeric type in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_VAR_NOT_CHAR:
|
case ECPG_VAR_NOT_CHAR:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Variable is not a character type in line %d.", line);
|
"Variable is not a character type in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -138,29 +140,29 @@ ECPGraise(int line, int code, const char *str)
|
||||||
/* strip trailing newline */
|
/* strip trailing newline */
|
||||||
if (slen > 0 && str[slen - 1] == '\n')
|
if (slen > 0 && str[slen - 1] == '\n')
|
||||||
slen--;
|
slen--;
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"'%.*s' in line %d.", slen, str, line);
|
"'%.*s' in line %d.", slen, str, line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ECPG_TRANS:
|
case ECPG_TRANS:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Error in transaction processing in line %d.", line);
|
"Error in transaction processing in line %d.", line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPG_CONNECT:
|
case ECPG_CONNECT:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"Could not connect to database %s in line %d.", str, line);
|
"Could not connect to database %s in line %d.", str, line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"SQL error #%d in line %d.", code, line);
|
"SQL error #%d in line %d.", code, line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc);
|
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
|
||||||
ECPGlog("raising sqlcode %d in line %d, '%s'.\n", code, line, sqlca.sqlerrm.sqlerrmc);
|
ECPGlog("raising sqlcode %d in line %d, '%s'.\n", code, line, sqlca->sqlerrm.sqlerrmc);
|
||||||
|
|
||||||
/* free all memory we have allocated for the user */
|
/* free all memory we have allocated for the user */
|
||||||
ECPGfree_auto_mem();
|
ECPGfree_auto_mem();
|
||||||
|
@ -193,6 +195,8 @@ ECPGerrmsg(void)
|
||||||
void
|
void
|
||||||
sqlprint(void)
|
sqlprint(void)
|
||||||
{
|
{
|
||||||
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
fprintf(stderr, "sql error %s\n", sqlca.sqlerrm.sqlerrmc);
|
|
||||||
|
sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml] = '\0';
|
||||||
|
fprintf(stderr, "sql error %s\n", sqlca->sqlerrm.sqlerrmc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.9 2003/06/13 10:50:57 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.10 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The aim is to get a simpler inteface to the database routines.
|
* The aim is to get a simpler inteface to the database routines.
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
/* Taken over as part of PostgreSQL by Michael Meskes <meskes@postgresql.org>
|
/* Taken over as part of PostgreSQL by Michael Meskes <meskes@postgresql.org>
|
||||||
on Feb. 5th, 1998 */
|
on Feb. 5th, 1998 */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -31,34 +32,6 @@
|
||||||
#include "pgtypes_timestamp.h"
|
#include "pgtypes_timestamp.h"
|
||||||
#include "pgtypes_interval.h"
|
#include "pgtypes_interval.h"
|
||||||
|
|
||||||
/* variables visible to the programs */
|
|
||||||
struct sqlca sqlca =
|
|
||||||
{
|
|
||||||
{
|
|
||||||
'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
|
|
||||||
},
|
|
||||||
sizeof(struct sqlca),
|
|
||||||
0,
|
|
||||||
{
|
|
||||||
0,
|
|
||||||
{
|
|
||||||
0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0, 0, 0, 0, 0, 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* This function returns a newly malloced string that has the \
|
/* This function returns a newly malloced string that has the \
|
||||||
in the argument quoted with \ and the ' quoted with ' as SQL92 says.
|
in the argument quoted with \ and the ' quoted with ' as SQL92 says.
|
||||||
*/
|
*/
|
||||||
|
@ -1130,6 +1103,8 @@ ECPGexecute(struct statement * stmt)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
bool clear_result = TRUE;
|
bool clear_result = TRUE;
|
||||||
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
errmsg = PQresultErrorMessage(results);
|
errmsg = PQresultErrorMessage(results);
|
||||||
set_backend_err(errmsg, stmt->lineno);
|
set_backend_err(errmsg, stmt->lineno);
|
||||||
|
|
||||||
|
@ -1142,7 +1117,7 @@ ECPGexecute(struct statement * stmt)
|
||||||
|
|
||||||
case PGRES_TUPLES_OK:
|
case PGRES_TUPLES_OK:
|
||||||
nfields = PQnfields(results);
|
nfields = PQnfields(results);
|
||||||
sqlca.sqlerrd[2] = ntuples = PQntuples(results);
|
sqlca->sqlerrd[2] = ntuples = PQntuples(results);
|
||||||
status = true;
|
status = true;
|
||||||
|
|
||||||
if (ntuples < 1)
|
if (ntuples < 1)
|
||||||
|
@ -1199,10 +1174,10 @@ ECPGexecute(struct statement * stmt)
|
||||||
case PGRES_COMMAND_OK:
|
case PGRES_COMMAND_OK:
|
||||||
status = true;
|
status = true;
|
||||||
cmdstat = PQcmdStatus(results);
|
cmdstat = PQcmdStatus(results);
|
||||||
sqlca.sqlerrd[1] = PQoidValue(results);
|
sqlca->sqlerrd[1] = PQoidValue(results);
|
||||||
sqlca.sqlerrd[2] = atol(PQcmdTuples(results));
|
sqlca->sqlerrd[2] = atol(PQcmdTuples(results));
|
||||||
ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
|
ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
|
||||||
if (!sqlca.sqlerrd[2] && ( !strncmp(cmdstat, "UPDATE", 6)
|
if (!sqlca->sqlerrd[2] && ( !strncmp(cmdstat, "UPDATE", 6)
|
||||||
|| !strncmp(cmdstat, "INSERT", 6)
|
|| !strncmp(cmdstat, "INSERT", 6)
|
||||||
|| !strncmp(cmdstat, "DELETE", 6)))
|
|| !strncmp(cmdstat, "DELETE", 6)))
|
||||||
ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL);
|
ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
|
#include "sqlca.h"
|
||||||
|
|
||||||
/* Here are some methods used by the lib. */
|
/* Here are some methods used by the lib. */
|
||||||
|
|
||||||
|
@ -19,7 +20,6 @@ void ECPGadd_mem(void *ptr, int lineno);
|
||||||
bool ECPGget_data(const PGresult *, int, int, int, enum ECPGttype type,
|
bool ECPGget_data(const PGresult *, int, int, int, enum ECPGttype type,
|
||||||
enum ECPGttype, char *, char *, long, long, long, bool);
|
enum ECPGttype, char *, char *, long, long, long, bool);
|
||||||
struct connection *ECPGget_connection(const char *);
|
struct connection *ECPGget_connection(const char *);
|
||||||
void ECPGinit_sqlca(void);
|
|
||||||
char *ECPGalloc(long, int);
|
char *ECPGalloc(long, int);
|
||||||
char *ECPGrealloc(void *, long, int);
|
char *ECPGrealloc(void *, long, int);
|
||||||
void ECPGfree(void *);
|
void ECPGfree(void *);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.2 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include "ecpgtype.h"
|
#include "ecpgtype.h"
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.2 2003/03/21 15:31:04 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.3 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
#include "ecpgtype.h"
|
#include "ecpgtype.h"
|
||||||
#include "ecpglib.h"
|
#include "ecpglib.h"
|
||||||
#include "ecpgerrno.h"
|
#include "ecpgerrno.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
#include "sqlca.h"
|
#include "sqlca.h"
|
||||||
|
|
||||||
static struct sqlca sqlca_init =
|
static struct sqlca_t sqlca_init =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
|
'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
|
||||||
},
|
},
|
||||||
sizeof(struct sqlca),
|
sizeof(struct sqlca_t),
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
|
@ -36,19 +40,54 @@ static struct sqlca sqlca_init =
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
static pthread_key_t sqlca_key;
|
||||||
|
static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
|
||||||
|
#else
|
||||||
|
static struct sqlca_t sqlca =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
|
||||||
|
},
|
||||||
|
sizeof(struct sqlca_t),
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0, 0, 0, 0, 0, 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
#endif
|
||||||
static int simple_debug = 0;
|
static int simple_debug = 0;
|
||||||
static FILE *debugstream = NULL;
|
static FILE *debugstream = NULL;
|
||||||
|
|
||||||
void
|
void ECPGinit_sqlca(struct sqlca_t *sqlca)
|
||||||
ECPGinit_sqlca(void)
|
|
||||||
{
|
{
|
||||||
memcpy((char *) &sqlca, (char *) &sqlca_init, sizeof(sqlca));
|
memcpy((char *)sqlca, (char *)&sqlca_init, sizeof(struct sqlca_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ECPGinit(const struct connection * con, const char *connection_name, const int lineno)
|
ECPGinit(const struct connection * con, const char *connection_name, const int lineno)
|
||||||
{
|
{
|
||||||
ECPGinit_sqlca();
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
ECPGinit_sqlca(sqlca);
|
||||||
if (con == NULL)
|
if (con == NULL)
|
||||||
{
|
{
|
||||||
ECPGraise(lineno, ECPG_NO_CONN, connection_name ? connection_name : "NULL");
|
ECPGraise(lineno, ECPG_NO_CONN, connection_name ? connection_name : "NULL");
|
||||||
|
@ -58,6 +97,33 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
static void ecpg_sqlca_key_init(void)
|
||||||
|
{
|
||||||
|
pthread_key_create(&sqlca_key, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct sqlca_t *ECPGget_sqlca(void)
|
||||||
|
{
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
struct sqlca_t *sqlca;
|
||||||
|
|
||||||
|
pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
|
||||||
|
|
||||||
|
sqlca = pthread_getspecific(&sqlca_key);
|
||||||
|
if( sqlca == NULL )
|
||||||
|
{
|
||||||
|
sqlca = malloc(sizeof(struct sqlca_t));
|
||||||
|
ECPGinit_sqlca(sqlca);
|
||||||
|
pthread_setspecific(&sqlca_key, sqlca);
|
||||||
|
}
|
||||||
|
return( sqlca );
|
||||||
|
#else
|
||||||
|
return( &sqlca );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ECPGstatus(int lineno, const char *connection_name)
|
ECPGstatus(int lineno, const char *connection_name)
|
||||||
{
|
{
|
||||||
|
@ -123,9 +189,17 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
|
||||||
void
|
void
|
||||||
ECPGdebug(int n, FILE *dbgs)
|
ECPGdebug(int n, FILE *dbgs)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_lock(&debug_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
simple_debug = n;
|
simple_debug = n;
|
||||||
debugstream = dbgs;
|
debugstream = dbgs;
|
||||||
ECPGlog("ECPGdebug: set to %d\n", simple_debug);
|
ECPGlog("ECPGdebug: set to %d\n", simple_debug);
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&debug_mutex);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -133,12 +207,20 @@ ECPGlog(const char *format,...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
if (simple_debug)
|
#ifdef USE_THREADS
|
||||||
{
|
pthread_mutex_lock(&debug_mutex);
|
||||||
char *f = (char *) malloc(strlen(format) + 100);
|
#endif
|
||||||
|
|
||||||
if (!f)
|
if( simple_debug )
|
||||||
|
{
|
||||||
|
char *f = (char *)malloc(strlen(format) + 100);
|
||||||
|
if( f == NULL )
|
||||||
|
{
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&debug_mutex);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(f, "[%d]: %s", (int) getpid(), format);
|
sprintf(f, "[%d]: %s", (int) getpid(), format);
|
||||||
|
|
||||||
|
@ -148,4 +230,8 @@ ECPGlog(const char *format,...)
|
||||||
|
|
||||||
ECPGfree(f);
|
ECPGfree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_THREADS
|
||||||
|
pthread_mutex_unlock(&debug_mutex);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.2 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.3 2003/03/27 14:29:17 meskes Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.4 2003/06/15 04:07:58 momjian Exp $ */
|
||||||
|
|
||||||
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -16,7 +16,7 @@ extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct sqlca
|
struct sqlca_t
|
||||||
{
|
{
|
||||||
char sqlcaid[8];
|
char sqlcaid[8];
|
||||||
long sqlabc;
|
long sqlabc;
|
||||||
|
@ -53,8 +53,11 @@ struct sqlca
|
||||||
char sqlext[8];
|
char sqlext[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern DLLIMPORT struct sqlca sqlca;
|
struct sqlca_t *ECPGget_sqlca(void);
|
||||||
|
|
||||||
|
#ifndef POSTGRES_ECPG_INTERNAL
|
||||||
|
# define sqlca (*ECPGget_sqlca())
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.91 2003/03/18 10:46:39 meskes Exp $
|
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.92 2003/06/15 04:07:58 momjian Exp $
|
||||||
|
|
||||||
subdir = src/interfaces/ecpg/preproc
|
subdir = src/interfaces/ecpg/preproc
|
||||||
top_builddir = ../../../..
|
top_builddir = ../../../..
|
||||||
include $(top_builddir)/src/Makefile.global
|
include $(top_builddir)/src/Makefile.global
|
||||||
|
|
||||||
MAJOR_VERSION=2
|
MAJOR_VERSION=3
|
||||||
MINOR_VERSION=12
|
MINOR_VERSION=0
|
||||||
PATCHLEVEL=0
|
PATCHLEVEL=0
|
||||||
|
|
||||||
override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \
|
override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \
|
||||||
|
|
Loading…
Reference in New Issue