summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/ecpglib')
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c28
-rw-r--r--src/interfaces/ecpg/ecpglib/data.c8
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c21
-rw-r--r--src/interfaces/ecpg/ecpglib/misc.c14
-rw-r--r--src/interfaces/ecpg/ecpglib/typename.c4
5 files changed, 57 insertions, 18 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 77505f1184..d7c721acd3 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.9 2003/06/26 11:37:05 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.10 2003/07/01 12:40:51 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -18,15 +18,11 @@ static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct connection *all_connections = NULL;
static struct connection *actual_connection = NULL;
-struct connection *
-ECPGget_connection(const char *connection_name)
+static struct connection *
+ecpg_get_connection_nr(const char *connection_name)
{
struct connection *ret = NULL;
-#ifdef USE_THREADS
- pthread_mutex_lock(&connections_mutex);
-#endif
-
if( (connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0) )
{
ret = actual_connection;
@@ -43,11 +39,25 @@ ECPGget_connection(const char *connection_name)
ret = con;
}
+ return( ret );
+}
+
+struct connection *
+ECPGget_connection(const char *connection_name)
+{
+ struct connection *ret = NULL;
+#ifdef USE_THREADS
+ pthread_mutex_lock(&connections_mutex);
+#endif
+
+ ret = ecpg_get_connection_nr(connection_name);
+
#ifdef USE_THREADS
pthread_mutex_unlock(&connections_mutex);
#endif
- return( ret );
+ return (ret);
+
}
static void
@@ -546,7 +556,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
}
else
{
- con = ECPGget_connection(connection_name);
+ con = ecpg_get_connection_nr(connection_name);
if (!ECPGinit(con, connection_name, lineno))
{
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 77f35e639e..c9da13794d 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.9 2003/06/26 11:37:05 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.10 2003/07/01 12:40:51 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -398,6 +398,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
break;
+ case ECPGt_decimal:
case ECPGt_numeric:
if (pval)
{
@@ -419,7 +420,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
- PGTYPESnumeric_copy(nres, (Numeric *)(var + offset * act_tuple));
+ if (type == ECPGt_numeric)
+ PGTYPESnumeric_copy(nres, (Numeric *)(var + offset * act_tuple));
+ else
+ PGTYPESnumeric_to_decimal(nres, (Decimal *)(var + offset * act_tuple));
break;
case ECPGt_interval:
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index ad5ab5d1f0..bc945a442c 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.13 2003/06/26 11:37:05 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.14 2003/07/01 12:40:51 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -820,16 +820,24 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
}
break;
+ case ECPGt_decimal:
case ECPGt_numeric:
{
char *str = NULL;
int slen;
+ Numeric *nval = PGTYPESnumeric_new();
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
- str = PGTYPESnumeric_to_asc((Numeric *)((var + var->offset * element)->value), 0);
+ if (var->type == ECPGt_numeric)
+ PGTYPESnumeric_copy((Numeric *)((var + var->offset * element)->value), nval);
+ else
+ PGTYPESnumeric_from_decimal((Decimal *)((var + var->offset * element)->value), nval);
+
+ str = PGTYPESnumeric_to_asc(nval, 0);
+ PGTYPESnumeric_free(nval);
slen = strlen (str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
@@ -845,7 +853,14 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
}
else
{
- str = PGTYPESnumeric_to_asc((Numeric *)(var->value), 0);
+ if (var->type == ECPGt_numeric)
+ PGTYPESnumeric_copy((Numeric *)(var->value), nval);
+ else
+ PGTYPESnumeric_from_decimal((Decimal *)(var->value), nval);
+
+ str = PGTYPESnumeric_to_asc(nval, 0);
+
+ PGTYPESnumeric_free(nval);
slen = strlen (str);
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index 33091e7d8c..6c9bd208c7 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.8 2003/06/26 01:45:04 momjian Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.9 2003/07/01 12:40:51 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -85,6 +85,7 @@ static struct sqlca_t sqlca =
#ifdef USE_THREADS
static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
static int simple_debug = 0;
static FILE *debugstream = NULL;
@@ -204,7 +205,7 @@ void
ECPGdebug(int n, FILE *dbgs)
{
#ifdef USE_THREADS
- pthread_mutex_lock(&debug_mutex);
+ pthread_mutex_lock(&debug_init_mutex);
#endif
simple_debug = n;
@@ -212,7 +213,7 @@ ECPGdebug(int n, FILE *dbgs)
ECPGlog("ECPGdebug: set to %d\n", simple_debug);
#ifdef USE_THREADS
- pthread_mutex_unlock(&debug_mutex);
+ pthread_mutex_unlock(&debug_init_mutex);
#endif
}
@@ -241,6 +242,7 @@ ECPGlog(const char *format,...)
va_start(ap, format);
vfprintf(debugstream, f, ap);
va_end(ap);
+ fflush(debugstream);
ECPGfree(f);
}
@@ -287,6 +289,9 @@ ECPGset_informix_null(enum ECPGttype type, void *ptr)
case ECPGt_varchar:
*(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
break;
+ case ECPGt_decimal:
+ ((Decimal *) ptr)->sign = NUMERIC_NAN;
+ break;
case ECPGt_numeric:
((Numeric *) ptr)->sign = NUMERIC_NAN;
break;
@@ -345,6 +350,9 @@ ECPGis_informix_null(enum ECPGttype type, void *ptr)
case ECPGt_varchar:
if (*(((struct ECPGgeneric_varchar *) ptr)->arr) == 0x00) return true;
break;
+ case ECPGt_decimal:
+ if (((Decimal *) ptr)->sign == NUMERIC_NAN) return true;
+ break;
case ECPGt_numeric:
if (((Numeric *) ptr)->sign == NUMERIC_NAN) return true;
break;
diff --git a/src/interfaces/ecpg/ecpglib/typename.c b/src/interfaces/ecpg/ecpglib/typename.c
index f8eb793ba3..752b4f6063 100644
--- a/src/interfaces/ecpg/ecpglib/typename.c
+++ b/src/interfaces/ecpg/ecpglib/typename.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.7 2003/06/20 12:01:46 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.8 2003/07/01 12:40:51 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -48,6 +48,8 @@ ECPGtype_name(enum ECPGttype typ)
return "varchar";
case ECPGt_char_variable:
return "char";
+ case ECPGt_decimal:
+ return "Decimal";
case ECPGt_numeric:
return "Numeric";
case ECPGt_date: