1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Started adding date and timestamp.

This commit is contained in:
Michael Meskes
2003-03-20 15:56:50 +00:00
parent 26a6378e84
commit 2e6f97560a
22 changed files with 3674 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */
#include "postgres_fe.h"
@@ -11,6 +11,8 @@
#include "extern.h"
#include "sqlca.h"
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
bool
ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
@@ -99,6 +101,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
double dres;
char *scan_length;
NumericVar *nres;
Date ddres;
Timestamp tres;
case ECPGt_short:
case ECPGt_int:
@@ -397,7 +401,51 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
PGTYPESnumeric_copy(nres, (NumericVar *)(var + offset * act_tuple));
break;
case ECPGt_date:
if (pval)
{
if (isarray && *pval == '"')
ddres = PGTYPESdate_atod(pval + 1, &scan_length);
else
ddres = PGTYPESdate_atod(pval, &scan_length);
if (isarray && *scan_length == '"')
scan_length++;
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
return (false);
}
*((Date *)(var + offset * act_tuple)) = ddres;
}
break;
case ECPGt_timestamp:
if (pval)
{
if (isarray && *pval == '"')
tres = PGTYPEStimestamp_atot(pval + 1, &scan_length);
else
tres = PGTYPEStimestamp_atot(pval, &scan_length);
if (isarray && *scan_length == '"')
scan_length++;
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
return (false);
}
*((Timestamp *)(var + offset * act_tuple)) = tres;
}
break;
default:
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type));
return (false);

View File

@@ -1,4 +1,4 @@
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.3 2003/03/19 16:05:41 petere Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.4 2003/03/20 15:56:50 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -27,6 +27,8 @@
#include "sqlca.h"
#include "sql3types.h"
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
/* variables visible to the programs */
struct sqlca sqlca =
@@ -59,8 +61,7 @@ struct sqlca sqlca =
/* This function returns a newly malloced string that has the \
in the argument quoted with \ and the ' quoted with ' as SQL92 says.
*/
static
char *
static char *
quote_postgres(char *arg, int lineno)
{
char *res = (char *) ECPGalloc(2 * strlen(arg) + 3, lineno);
@@ -876,6 +877,89 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
free(str);
}
break;
case ECPGt_date:
{
char *str = NULL;
int slen;
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
str = PGTYPESdate_dtoa(*(Date *)((var + var->offset * element)->value));
slen = strlen (str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
return false;
if (!element)
strcpy(mallocedval, "'{");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
}
else
{
str = PGTYPESdate_dtoa(*(Date *)(var->value));
slen = strlen (str);
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
return false;
strncpy(mallocedval, str , slen);
mallocedval[slen] = '\0';
}
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
}
break;
case ECPGt_timestamp:
{
char *str = NULL;
int slen;
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
str = PGTYPEStimestamp_ttoa(*(Timestamp *)((var + var->offset * element)->value));
slen = strlen (str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
return false;
if (!element)
strcpy(mallocedval, "'{");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
}
else
{
str = PGTYPEStimestamp_ttoa(*(Timestamp *)(var->value));
slen = strlen (str);
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
return false;
strncpy(mallocedval, str , slen);
mallocedval[slen] = '\0';
}
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
}
break;
default:
/* Not implemented yet */
ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type));

View File

@@ -1,4 +1,4 @@
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */
#include "postgres_fe.h"
@@ -49,6 +49,10 @@ ECPGtype_name(enum ECPGttype typ)
return "char";
case ECPGt_numeric:
return "numeric";
case ECPGt_date:
return "date";
case ECPGt_timestamp:
return "timestamp";
default:
abort();
}