mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Use ISO dates in pgtypeslib by default.
Applied patch by Philip Yarra to fix some thread issues. Added a new data type "decimal" which is mostly the same as our "numeric" but uses a fixed length array to store the digits. This is for compatibility with Informix and maybe others.
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
@@ -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:
|
||||
|
@@ -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)))
|
||||
|
@@ -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;
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user