Commit a829da15 authored by Michael Meskes's avatar Michael Meskes

Added fixed from the coverity report send in by Joachim Wieland <joe@mcknight.de>

Added missing error handling in a few functions in ecpglib
parent 27c3e3de
......@@ -2014,6 +2014,12 @@ Tu Jun 6 12:09:56 CEST 2006
Mo Jun 19 11:15:50 CEST 2006
- Do not use already free'ed errmsg, bug found by Joachim Wieland
<joachim.wieland@credativ.de>
<joe@mcknight.de>
We Jun 21 09:24:53 CEST 2006
- Added fixed from the coverity report send in by Joachim Wieland
<joe@mcknight.de>
- Added missing error handling in a few functions in ecpglib.
- Set ecpg library version to 5.2.
- Set ecpg version to 4.2.1.
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.42 2006/04/24 09:45:22 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.43 2006/06/21 10:24:40 meskes Exp $ */
#include <stdlib.h>
#include <string.h>
......@@ -211,13 +211,14 @@ deccvasc(char *cp, int len, decimal *np)
int
deccvdbl(double dbl, decimal *np)
{
numeric *nres = PGTYPESnumeric_new();
numeric *nres;
int result = 1;
rsetnull(CDECIMALTYPE, (char *) np);
if (risnull(CDOUBLETYPE, (char *) &dbl))
return 0;
nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
......@@ -232,13 +233,14 @@ deccvdbl(double dbl, decimal *np)
int
deccvint(int in, decimal *np)
{
numeric *nres = PGTYPESnumeric_new();
numeric *nres;
int result = 1;
rsetnull(CDECIMALTYPE, (char *) np);
if (risnull(CINTTYPE, (char *) &in))
return 0;
nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
......@@ -253,13 +255,14 @@ deccvint(int in, decimal *np)
int
deccvlong(long lng, decimal *np)
{
numeric *nres = PGTYPESnumeric_new();
numeric *nres;
int result = 1;
rsetnull(CDECIMALTYPE, (char *) np);
if (risnull(CLONGTYPE, (char *) &lng))
return 0;
nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
......@@ -342,17 +345,21 @@ int
dectoasc(decimal *np, char *cp, int len, int right)
{
char *str;
numeric *nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
numeric *nres;
rsetnull(CSTRINGTYPE, (char *) cp);
if (risnull(CDECIMALTYPE, (char *) np))
return 0;
nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
{
PGTYPESnumeric_free(nres);
return ECPG_INFORMIX_OUT_OF_MEMORY;
}
if (right >= 0)
str = PGTYPESnumeric_to_asc(nres, right);
......@@ -376,14 +383,17 @@ dectoasc(decimal *np, char *cp, int len, int right)
int
dectodbl(decimal *np, double *dblp)
{
numeric *nres = PGTYPESnumeric_new();
int i;
numeric *nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
{
PGTYPESnumeric_free(nres);
return ECPG_INFORMIX_OUT_OF_MEMORY;
}
i = PGTYPESnumeric_to_double(nres, dblp);
PGTYPESnumeric_free(nres);
......@@ -401,7 +411,10 @@ dectoint(decimal *np, int *ip)
return ECPG_INFORMIX_OUT_OF_MEMORY;
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
{
PGTYPESnumeric_free(nres);
return ECPG_INFORMIX_OUT_OF_MEMORY;
}
ret = PGTYPESnumeric_to_int(nres, ip);
......@@ -415,15 +428,19 @@ int
dectolong(decimal *np, long *lngp)
{
int ret;
numeric *nres = PGTYPESnumeric_new();;
numeric *nres = PGTYPESnumeric_new();
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
{
PGTYPESnumeric_free(nres);
return ECPG_INFORMIX_OUT_OF_MEMORY;
}
ret = PGTYPESnumeric_to_long(nres, lngp);
PGTYPESnumeric_free(nres);
if (ret == PGTYPES_NUM_OVERFLOW)
ret = ECPG_INFORMIX_NUM_OVERFLOW;
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.28 2006/06/19 09:19:49 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.29 2006/06/21 10:24:40 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
......@@ -403,6 +403,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
ECPGfree(realname);
if (dbname)
ECPGfree(dbname);
ecpg_finish(this);
return false;
}
}
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.31 2006/06/06 11:31:55 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.32 2006/06/21 10:24:40 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
......@@ -93,13 +93,17 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
ECPGraise(lineno, ECPG_MISSING_INDICATOR, ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, NULL);
ECPGraise(lineno, ECPG_MISSING_INDICATOR,
ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER,
NULL);
return (false);
}
}
break;
default:
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(ind_type));
ECPGraise(lineno, ECPG_UNSUPPORTED,
ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
ECPGtype_name(ind_type));
return (false);
break;
}
......@@ -111,9 +115,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
/* let's check if it really is an array if it should be one */
if (isarray == ECPG_ARRAY_ARRAY)
{
if (*pval != '{')
if (!pval || *pval != '{')
{
ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
ECPGraise(lineno, ECPG_DATA_NOT_ARRAY,
ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
return (false);
}
......@@ -134,13 +139,15 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
if (binary)
{
if (pval)
{
if (varcharsize == 0 || varcharsize*offset >= size)
memcpy((char *) ((long) var + offset * act_tuple), pval, size);
if (pval)
{
if (varcharsize == 0 || varcharsize*offset >= size)
memcpy((char *) ((long) var + offset * act_tuple),
pval, size);
else
{
memcpy((char *) ((long) var + offset * act_tuple), pval, varcharsize*offset);
memcpy((char *) ((long) var + offset * act_tuple),
pval, varcharsize*offset);
if (varcharsize*offset < size)
{
......@@ -195,7 +202,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
res = strtol(pval, &scan_length, 10);
if (garbage_left(isarray, scan_length, compat))
{
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_INT_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
......@@ -228,7 +236,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ures = strtoul(pval, &scan_length, 10);
if (garbage_left(isarray, scan_length, compat))
{
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_UINT_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
......@@ -305,7 +314,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
ECPGraise(lineno, ECPG_FLOAT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_FLOAT_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
......@@ -337,7 +347,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else if (offset == sizeof(int))
*((int *) (var + offset * act_tuple)) = false;
else
ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
ECPGraise(lineno, ECPG_CONVERT_BOOL,
ECPG_SQLSTATE_DATATYPE_MISMATCH,
"different size");
break;
}
else if (pval[0] == 't' && pval[1] == '\0')
......@@ -347,7 +359,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else if (offset == sizeof(int))
*((int *) (var + offset * act_tuple)) = true;
else
ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
ECPGraise(lineno, ECPG_CONVERT_BOOL,
ECPG_SQLSTATE_DATATYPE_MISMATCH,
"different size");
break;
}
else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
......@@ -357,7 +371,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
}
ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_CONVERT_BOOL,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
break;
......@@ -464,7 +479,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
/* did we get an error? */
if (nres == NULL)
{
ECPGlog("ECPGget_data line %d: RESULT: %s errno %d\n", lineno, pval ? pval : "", errno);
ECPGlog("ECPGget_data line %d: RESULT: %s errno %d\n",
lineno, pval ? pval : "", errno);
if (INFORMIX_MODE(compat))
{
......@@ -472,11 +488,20 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* Informix wants its own NULL value here instead
* of an error
*/
ECPGset_noind_null(ECPGt_numeric, nres);
nres = PGTYPESnumeric_new();
if (nres)
ECPGset_noind_null(ECPGt_numeric, nres);
else
{
ECPGraise(lineno, ECPG_OUT_OF_MEMORY,
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
return (false);
}
}
else
{
ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_NUMERIC_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -488,7 +513,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
free(nres);
ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_NUMERIC_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -522,11 +548,16 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* Informix wants its own NULL value here instead
* of an error
*/
ires = (interval *) ECPGalloc(sizeof(interval), lineno);
if (!ires)
return (false);
ECPGset_noind_null(ECPGt_interval, ires);
}
else
{
ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_INTERVAL_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -538,7 +569,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
free(ires);
ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_INTERVAL_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -571,7 +603,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_DATE_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -582,7 +615,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_DATE_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -613,7 +647,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -624,7 +659,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
......@@ -635,7 +671,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break;
default:
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(type));
ECPGraise(lineno, ECPG_UNSUPPORTED,
ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
ECPGtype_name(type));
return (false);
break;
}
......
/* dynamic SQL support routines
*
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.14 2006/01/15 22:46:53 neilc Exp $
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.15 2006/06/21 10:24:40 meskes Exp $
*/
#define POSTGRES_ECPG_INTERNAL
......@@ -351,8 +351,9 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
/* allocate storage if needed */
if (arrsize == 0 && var != NULL && *(void **) var == NULL)
{
void *mem = (void *) ECPGalloc(offset * ntuples, lineno);
void *mem = (void *) ECPGalloc(offset * ntuples, lineno);
if (!mem)
return false;
*(void **) var = mem;
ECPGadd_mem(mem, lineno);
var = mem;
......@@ -412,8 +413,9 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
/* allocate storage if needed */
if (data_var.ind_arrsize == 0 && data_var.ind_pointer != NULL && data_var.ind_value == NULL)
{
void *mem = (void *) ECPGalloc(data_var.ind_offset * ntuples, lineno);
void *mem = (void *) ECPGalloc(data_var.ind_offset * ntuples, lineno);
if (!mem)
return false;
*(void **) data_var.ind_pointer = mem;
ECPGadd_mem(mem, lineno);
data_var.ind_value = mem;
......@@ -480,6 +482,8 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
if (desc_item == NULL)
{
desc_item = (struct descriptor_item *) ECPGalloc(sizeof(*desc_item), lineno);
if (!desc_item)
return false;
desc_item->num = index;
desc_item->next = desc->items;
desc->items = desc_item;
......
This diff is collapsed.
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.16 2006/03/11 04:38:39 momjian Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.17 2006/06/21 10:24:41 meskes Exp $ */
#ifndef _ECPG_LIB_EXTERN_H
#define _ECPG_LIB_EXTERN_H
......@@ -16,7 +16,7 @@ enum COMPAT_MODE
enum ARRAY_TYPE
{
ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
};
/* Here are some methods used by the lib. */
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.28 2006/05/31 08:12:48 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.29 2006/06/21 10:24:41 meskes Exp $ */
#include "postgres_fe.h"
......@@ -196,7 +196,6 @@ PGTYPESdate_fmt_asc(date dDate, char *fmtstring, char *outbuf)
char *start_pattern;
struct tm tm;
/* XXX error handling ? */
/* copy the string over */
strcpy(outbuf, fmtstring);
......@@ -696,8 +695,6 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
return -1;
}
/* XXX: DBCENTURY ? */
*d = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) - date2j(2000, 1, 1);
return 0;
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.34 2006/03/11 04:38:39 momjian Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.35 2006/06/21 10:24:41 meskes Exp $ */
#include "postgres_fe.h"
......@@ -1035,7 +1035,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
/*
* XXX FreeBSD man pages indicate that this should work - tgl 97/04/23
* FreeBSD man pages indicate that this should work - tgl 97/04/23
*/
if (tzn != NULL)
{
......@@ -2739,7 +2739,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
}
else
{
/* XXX Error: no match */
/* Error: no match */
err = 1;
return err;
}
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.26 2006/04/24 09:45:22 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.27 2006/06/21 10:24:41 meskes Exp $ */
#include "postgres_fe.h"
#include <ctype.h>
......@@ -131,7 +131,10 @@ PGTYPESnumeric_new(void)
return NULL;
if (alloc_var(var, 0) < 0)
{
free(var);
return NULL;
}
return var;
}
......
......@@ -479,8 +479,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
if (*p == '\0')
return -1;
tmp[2] = *p;
/* XXX: fall back to strftime */
/*
* strftime's month is 0 based, ours is 1 based
*/
......@@ -498,7 +497,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
break;
}
case 'G':
/* XXX: fall back to strftime */
tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%G", tm);
if (i == 0)
......@@ -512,7 +510,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING;
break;
case 'g':
/* XXX: fall back to strftime */
{
char *fmt = "%g"; /* Keep compiler quiet about
* 2-digit year */
......@@ -621,7 +618,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_UINT;
break;
case 'U':
/* XXX: fall back to strftime */
tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%U", tm);
if (i == 0)
......@@ -635,7 +631,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING;
break;
case 'V':
/* XXX: fall back to strftime */
i = strftime(q, *pstr_len, "%V", tm);
if (i == 0)
return -1;
......@@ -651,7 +646,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_UINT;
break;
case 'W':
/* XXX: fall back to strftime */
tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%U", tm);
if (i == 0)
......@@ -665,7 +659,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING;
break;
case 'x':
/* XXX: fall back to strftime */
{
char *fmt = "%x"; /* Keep compiler quiet about
* 2-digit year */
......@@ -684,7 +677,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
}
break;
case 'X':
/* XXX: fall back to strftime */
tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%X", tm);
if (i == 0)
......@@ -706,7 +698,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_UINT;
break;
case 'z':
/* XXX: fall back to strftime */
tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%z", tm);
if (i == 0)
......@@ -720,7 +711,6 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING;
break;
case 'Z':
/* XXX: fall back to strftime */
tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%Z", tm);
if (i == 0)
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/test/dt_test.pgc,v 1.9 2006/03/11 04:38:40 momjian Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/test/dt_test.pgc,v 1.10 2006/06/21 10:24:41 meskes Exp $ */
#include <stdio.h>
#include <string.h>
......@@ -40,12 +40,15 @@ main(void)
text = PGTYPESdate_to_asc(date1);
printf ("Date: %s\n", text);
free(text);
text = PGTYPEStimestamp_to_asc(ts1);
printf ("timestamp: %s\n", text);
free(text);
text = PGTYPESinterval_to_asc(&iv1);
printf ("interval: %s\n", text);
free(text);
PGTYPESdate_mdyjul(mdy, &date2);
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
......@@ -61,10 +64,12 @@ main(void)
text = PGTYPEStimestamp_to_asc(ts1);
printf("date_day of %s is %d\n", text, PGTYPESdate_dayofweek(ts1));
free(text);
PGTYPESdate_today(&date1);
text = PGTYPESdate_to_asc(date1);
printf("today is %s\n", text);
free(text);
fmt = "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end";
out = (char*) malloc(strlen(fmt) + 1);
......@@ -84,6 +89,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc1: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "mmmm. dd. yyyy";
......@@ -91,6 +97,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc2: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "yy/mm/dd";
......@@ -98,6 +105,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc3: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "yy/mm/dd";
......@@ -105,6 +113,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc4: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "dd-mm-yy";
......@@ -112,6 +121,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc5: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "mmddyy";
......@@ -119,6 +129,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc6: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "mmm. dd. yyyy";
......@@ -126,6 +137,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc7: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "mmm. dd. yyyy";
......@@ -133,6 +145,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc8: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "mm yy dd.";
......@@ -140,6 +153,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc9: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "yyyy fierj mm dd.";
......@@ -147,6 +161,7 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc10: %s\n", text);
free(text);
date1 = 0; text = "";
fmt = "mm/dd/yy";
......@@ -154,22 +169,27 @@ main(void)
PGTYPESdate_defmt_asc(&date1, fmt, in);
text = PGTYPESdate_to_asc(date1);
printf("date_defmt_asc12: %s\n", text);
free(text);
PGTYPEStimestamp_current(&ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_current: Now: %s\n", text);
free(text);
ts1 = PGTYPEStimestamp_from_asc("96-02-29", NULL);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_to_asc1: %s\n", text);
free(text);
ts1 = PGTYPEStimestamp_from_asc("1994-02-11 3:10:35", NULL);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_to_asc2: %s\n", text);
free(text);
ts1 = PGTYPEStimestamp_from_asc("1994-02-11 26:10:35", NULL);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_to_asc3: %s\n", text);
free(text);
/* abc-03:10:35-def-02/11/94-gh */
/* 12345678901234567890123456789 */
......@@ -177,138 +197,161 @@ main(void)
out = (char*) malloc(32);
i = PGTYPEStimestamp_fmt_asc(&ts1, out, 31, "abc-%X-def-%x-ghi%%");
printf("timestamp_fmt_asc: %d: %s\n", i, out);
free(out);
fmt = "This is a %m/%d/%y %H-%Ml%Stest";
in = "This is a 4/12/80 3-39l12test";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %d %H:%M:%S %z %Y";
in = "Tue Jul 22 17:28:44 +0200 2003";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %d %H:%M:%S %z %Y";
in = "Tue Feb 29 17:28:44 +0200 2000";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %d %H:%M:%S %z %Y";
in = "Tue Feb 29 17:28:44 +0200 1900";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %d %H:%M:%S %z %Y";
in = "Tue Feb 29 17:28:44 +0200 1996";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%b %d %H:%M:%S %z %Y";
in = " Jul 31 17:28:44 +0200 1996";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%b %d %H:%M:%S %z %Y";
in = " Jul 32 17:28:44 +0200 1996";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %d %H:%M:%S %z %Y";
in = "Tue Feb 29 17:28:44 +0200 1997";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = "%";
in = "Tue Jul 22 17:28:44 +0200 2003";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = "a %";
in = "Tue Jul 22 17:28:44 +0200 2003";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = "%b, %d %H_%M`%S %z %Y";
in = " Jul, 22 17_28 `44 +0200 2003 ";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %%%d %H:%M:%S %Z %Y";
in = "Tue Jul %22 17:28:44 CEST 2003";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%a %b %%%d %H:%M:%S %Z %Y";
in = "Tue Jul %22 17:28:44 CEST 2003";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "abc%n %C %B %%%d %H:%M:%S %Z %Y";
in = "abc\n 19 October %22 17:28:44 CEST 2003";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "abc%n %C %B %%%d %H:%M:%S %Z %y";
in = "abc\n 18 October %34 17:28:44 CEST 80";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = "";
in = "abc\n 18 October %34 17:28:44 CEST 80";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
free(text);
fmt = NULL;
in = "1980-04-12 3:49:44 ";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
fmt = "%B %d, %Y. Time: %I:%M%p";
in = "July 14, 1988. Time: 9:15am";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
in = "September 6 at 01:30 pm in the year 1983";
fmt = "%B %d at %I:%M %p in the year %Y";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
in = " 1976, July 14. Time: 9:15am";
fmt = "%Y, %B %d. Time: %I:%M %p";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
in = " 1976, July 14. Time: 9:15 am";
fmt = "%Y, %B %d. Time: %I:%M%p";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
in = " 1976, P.M. July 14. Time: 9:15";
fmt = "%Y, %P %B %d. Time: %I:%M";
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
text = PGTYPEStimestamp_to_asc(ts1);
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
free(text);
exec sql rollback;
exec sql disconnect;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment