Commit b30da7ba authored by Michael Meskes's avatar Michael Meskes

Added lots of SoC stuff made by Joachim.

Fixed broken newline on Windows.
Fixed a nasty buffer underrun that only occured when using Informix
no_indicator NULL setting on timestamps and intervals.
parent 58538a0f
...@@ -2082,5 +2082,18 @@ We Aug 9 09:28:56 CEST 2006 ...@@ -2082,5 +2082,18 @@ We Aug 9 09:28:56 CEST 2006
- Fixed error handling in numeric conversion (Joachim). - Fixed error handling in numeric conversion (Joachim).
- Fixed some memory bugs that somehow reappeared. - Fixed some memory bugs that somehow reappeared.
- Also fixed a new Coverity report. - Also fixed a new Coverity report.
Su Aug 13 11:01:13 CEST 2006
- Applied patch for VPATH builds by Alvaro Herrera
<alvherre@commandprompt.com>
- Merged dyntest.pgc and dyntest2.pgc.
Mo Aug 14 10:39:59 CEST 2006
- Added lots of SoC stuff made by Joachim.
- Fixed broken newline on Windows.
- Fixed a nasty buffer underrun that only occured when using Informix
no_indicator NULL setting on timestamps and intervals.
- Set ecpg library version to 5.2. - Set ecpg library version to 5.2.
- Set ecpg version to 4.2.1. - Set ecpg version to 4.2.1.
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.46 2006/06/26 09:20:09 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.47 2006/08/15 06:40:19 meskes Exp $ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -122,12 +122,15 @@ deccall3(decimal *arg1, decimal *arg2, decimal *result, int (*ptr) (numeric *, n ...@@ -122,12 +122,15 @@ deccall3(decimal *arg1, decimal *arg2, decimal *result, int (*ptr) (numeric *, n
int int
decadd(decimal *arg1, decimal *arg2, decimal *sum) decadd(decimal *arg1, decimal *arg2, decimal *sum)
{ {
errno = 0;
deccall3(arg1, arg2, sum, PGTYPESnumeric_add); deccall3(arg1, arg2, sum, PGTYPESnumeric_add);
if (errno == PGTYPES_NUM_OVERFLOW) if (errno == PGTYPES_NUM_OVERFLOW)
return ECPG_INFORMIX_NUM_OVERFLOW; return ECPG_INFORMIX_NUM_OVERFLOW;
else if (errno != 0) else if (errno == PGTYPES_NUM_UNDERFLOW)
return ECPG_INFORMIX_NUM_UNDERFLOW; return ECPG_INFORMIX_NUM_UNDERFLOW;
else if (errno != 0)
return -1;
else else
return 0; return 0;
} }
...@@ -179,6 +182,7 @@ deccvasc(char *cp, int len, decimal *np) ...@@ -179,6 +182,7 @@ deccvasc(char *cp, int len, decimal *np)
ret = ECPG_INFORMIX_NUM_UNDERFLOW; ret = ECPG_INFORMIX_NUM_UNDERFLOW;
else else
{ {
errno = 0;
result = PGTYPESnumeric_from_asc(str, NULL); result = PGTYPESnumeric_from_asc(str, NULL);
if (!result) if (!result)
{ {
...@@ -280,6 +284,7 @@ decdiv(decimal *n1, decimal *n2, decimal *result) ...@@ -280,6 +284,7 @@ decdiv(decimal *n1, decimal *n2, decimal *result)
int i; int i;
errno = 0;
i = deccall3(n1, n2, result, PGTYPESnumeric_div); i = deccall3(n1, n2, result, PGTYPESnumeric_div);
if (i != 0) if (i != 0)
...@@ -304,6 +309,7 @@ decmul(decimal *n1, decimal *n2, decimal *result) ...@@ -304,6 +309,7 @@ decmul(decimal *n1, decimal *n2, decimal *result)
{ {
int i; int i;
errno = 0;
i = deccall3(n1, n2, result, PGTYPESnumeric_mul); i = deccall3(n1, n2, result, PGTYPESnumeric_mul);
if (i != 0) if (i != 0)
...@@ -325,6 +331,7 @@ decsub(decimal *n1, decimal *n2, decimal *result) ...@@ -325,6 +331,7 @@ decsub(decimal *n1, decimal *n2, decimal *result)
{ {
int i; int i;
errno = 0;
i = deccall3(n1, n2, result, PGTYPESnumeric_sub); i = deccall3(n1, n2, result, PGTYPESnumeric_sub);
if (i != 0) if (i != 0)
...@@ -371,13 +378,25 @@ dectoasc(decimal *np, char *cp, int len, int right) ...@@ -371,13 +378,25 @@ dectoasc(decimal *np, char *cp, int len, int right)
return -1; return -1;
/* /*
* TODO: have to take care of len here and create exponatial notion if * TODO: have to take care of len here and create exponential notation
* necessary * if necessary
*/ */
strncpy(cp, str, len); if ((int) (strlen(str) + 1) > len)
free(str); {
if (len > 1)
return 0; {
cp[0] = '*';
cp[1] = '\0';
}
free(str);
return -1;
}
else
{
strcpy(cp, str);
free(str);
return 0;
}
} }
int int
...@@ -474,59 +493,7 @@ rdatestr(date d, char *str) ...@@ -474,59 +493,7 @@ rdatestr(date d, char *str)
int int
rstrdate(char *str, date * d) rstrdate(char *str, date * d)
{ {
date dat; return rdefmtdate(d, "mm/dd/yyyy", str);
char strbuf[10];
int i,
j;
rsetnull(CDATETYPE, (char *) &dat);
/*
* we have to flip the year month date around for postgres expects
* yyyymmdd
*
*/
for (i = 0, j = 0; i < 10; i++)
{
/* ignore non-digits */
if (isdigit((unsigned char) str[i]))
{
/* j only increments if it is a digit */
switch (j)
{
/* stick the month into the 4th, 5th position */
case 0:
case 1:
strbuf[j + 4] = str[i];
break;
/* stick the day into the 6th, and 7th position */
case 2:
case 3:
strbuf[j + 4] = str[i];
break;
/* stick the year into the first 4 positions */
case 4:
case 5:
case 6:
case 7:
strbuf[j - 4] = str[i];
break;
}
j++;
}
}
strbuf[8] = '\0';
dat = PGTYPESdate_from_asc(strbuf, NULL);
if (errno && errno != PGTYPES_DATE_BAD_DATE)
return ECPG_INFORMIX_BAD_DATE;
*d = dat;
return 0;
} }
void void
...@@ -554,6 +521,7 @@ rdefmtdate(date * d, char *fmt, char *str) ...@@ -554,6 +521,7 @@ rdefmtdate(date * d, char *fmt, char *str)
/* TODO: take care of DBCENTURY environment variable */ /* TODO: take care of DBCENTURY environment variable */
/* PGSQL functions allow all centuries */ /* PGSQL functions allow all centuries */
errno = 0;
if (PGTYPESdate_defmt_asc(d, fmt, str) == 0) if (PGTYPESdate_defmt_asc(d, fmt, str) == 0)
return 0; return 0;
...@@ -576,6 +544,7 @@ rdefmtdate(date * d, char *fmt, char *str) ...@@ -576,6 +544,7 @@ rdefmtdate(date * d, char *fmt, char *str)
int int
rfmtdate(date d, char *fmt, char *str) rfmtdate(date d, char *fmt, char *str)
{ {
errno = 0;
if (PGTYPESdate_fmt_asc(d, fmt, str) == 0) if (PGTYPESdate_fmt_asc(d, fmt, str) == 0)
return 0; return 0;
...@@ -618,15 +587,18 @@ dtcvasc(char *str, timestamp * ts) ...@@ -618,15 +587,18 @@ dtcvasc(char *str, timestamp * ts)
int i; int i;
char **endptr = &str; char **endptr = &str;
errno = 0;
ts_tmp = PGTYPEStimestamp_from_asc(str, endptr); ts_tmp = PGTYPEStimestamp_from_asc(str, endptr);
i = errno; i = errno;
if (i) if (i)
/* TODO: rewrite to Informix error codes */
return i; return i;
if (**endptr) if (**endptr)
{ {
/* extra characters exist at the end */ /* extra characters exist at the end */
return ECPG_INFORMIX_EXTRA_CHARS; return ECPG_INFORMIX_EXTRA_CHARS;
} }
/* TODO: other Informix error codes missing */
/* everything went fine */ /* everything went fine */
*ts = ts_tmp; *ts = ts_tmp;
...@@ -634,6 +606,12 @@ dtcvasc(char *str, timestamp * ts) ...@@ -634,6 +606,12 @@ dtcvasc(char *str, timestamp * ts)
return 0; return 0;
} }
int
dtcvfmtasc(char *inbuf, char *fmtstr, timestamp * dtvalue)
{
return PGTYPEStimestamp_defmt_asc(inbuf, fmtstr, dtvalue);
}
int int
dtsub(timestamp * ts1, timestamp * ts2, interval * iv) dtsub(timestamp * ts1, timestamp * ts2, interval * iv)
{ {
...@@ -659,6 +637,7 @@ dttofmtasc(timestamp * ts, char *output, int str_len, char *fmtstr) ...@@ -659,6 +637,7 @@ dttofmtasc(timestamp * ts, char *output, int str_len, char *fmtstr)
int int
intoasc(interval * i, char *str) intoasc(interval * i, char *str)
{ {
errno = 0;
str = PGTYPESinterval_to_asc(i); str = PGTYPESinterval_to_asc(i);
if (!str) if (!str)
...@@ -797,17 +776,21 @@ rfmtlong(long lng_val, char *fmt, char *outbuf) ...@@ -797,17 +776,21 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
/* qualify, where we are in the value_string */ /* qualify, where we are in the value_string */
if (k < 0) if (k < 0)
{ {
if (leftalign)
{
/* can't use strncat(,,0) here, Solaris would freek out */
temp[j] = '\0';
break;
}
blank = 1; blank = 1;
if (k == -2) if (k == -2)
entity = 1; entity = 1;
else if (k == -1) else if (k == -1)
sign = 1; sign = 1;
if (leftalign)
{
/* can't use strncat(,,0) here, Solaris would freek out */
if (sign)
if (signdone)
{
temp[j] = '\0';
break;
}
}
} }
/* if we're right side of the right-most dot, print '0' */ /* if we're right side of the right-most dot, print '0' */
if (dotpos >= 0 && dotpos <= i) if (dotpos >= 0 && dotpos <= i)
...@@ -829,6 +812,9 @@ rfmtlong(long lng_val, char *fmt, char *outbuf) ...@@ -829,6 +812,9 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
fmtchar = lastfmt; fmtchar = lastfmt;
else else
fmtchar = fmt[i]; fmtchar = fmt[i];
/* waiting for the sign */
if (k < 0 && leftalign && sign && !signdone && fmtchar != '+' && fmtchar != '-')
continue;
/* analyse this format-char */ /* analyse this format-char */
switch (fmtchar) switch (fmtchar)
{ {
...@@ -854,9 +840,6 @@ rfmtlong(long lng_val, char *fmt, char *outbuf) ...@@ -854,9 +840,6 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
else else
tmp[0] = value.val_string[k]; tmp[0] = value.val_string[k];
break; break;
case '<':
tmp[0] = value.val_string[k];
break;
case '-': case '-':
if (sign && value.sign == '-' && !signdone) if (sign && value.sign == '-' && !signdone)
{ {
...@@ -904,6 +887,9 @@ rfmtlong(long lng_val, char *fmt, char *outbuf) ...@@ -904,6 +887,9 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
else else
tmp[0] = value.val_string[k]; tmp[0] = value.val_string[k];
break; break;
case '<':
tmp[0] = value.val_string[k];
break;
default: default:
tmp[0] = fmt[i]; tmp[0] = fmt[i];
} }
...@@ -950,8 +936,9 @@ byleng(char *str, int len) ...@@ -950,8 +936,9 @@ byleng(char *str, int len)
void void
ldchar(char *src, int len, char *dest) ldchar(char *src, int len, char *dest)
{ {
memmove(dest, src, len); int dlen = byleng(src, len);
dest[len] = 0; memmove(dest, src, dlen);
dest[dlen] = '\0';
} }
int int
...@@ -978,12 +965,6 @@ rtypwidth(int sqltype, int sqllen) ...@@ -978,12 +965,6 @@ rtypwidth(int sqltype, int sqllen)
return 0; return 0;
} }
int
dtcvfmtasc(char *inbuf, char *fmtstr, timestamp * dtvalue)
{
return PGTYPEStimestamp_defmt_asc(inbuf, fmtstr, dtvalue);
}
static struct var_list static struct var_list
{ {
int number; int number;
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.30 2006/08/08 11:51:24 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.31 2006/08/15 06:40:19 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -346,8 +346,8 @@ ECPGset_noind_null(enum ECPGttype type, void *ptr) ...@@ -346,8 +346,8 @@ ECPGset_noind_null(enum ECPGttype type, void *ptr)
static bool static bool
_check(unsigned char *ptr, int length) _check(unsigned char *ptr, int length)
{ {
for (; ptr[--length] == 0xff && length >= 0; length--); for (; length > 0 && ptr[--length] == 0xff;);
if (length < 0) if (length <= 0)
return true; return true;
return false; return false;
} }
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/pgtypes_error.h,v 1.7 2006/03/11 04:38:39 momjian Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/include/pgtypes_error.h,v 1.8 2006/08/15 06:40:19 meskes Exp $ */
#define PGTYPES_NUM_OVERFLOW 301 #define PGTYPES_NUM_OVERFLOW 301
#define PGTYPES_NUM_BAD_NUMERIC 302 #define PGTYPES_NUM_BAD_NUMERIC 302
#define PGTYPES_NUM_DIVIDE_ZERO 303 #define PGTYPES_NUM_DIVIDE_ZERO 303
#define PGTYPES_NUM_UNDERFLOW 304
#define PGTYPES_DATE_BAD_DATE 310 #define PGTYPES_DATE_BAD_DATE 310
#define PGTYPES_DATE_ERR_EARGS 311 #define PGTYPES_DATE_ERR_EARGS 311
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.29 2006/06/21 10:24:41 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.30 2006/08/15 06:40:19 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -230,7 +230,7 @@ PGTYPESdate_fmt_asc(date dDate, char *fmtstring, char *outbuf) ...@@ -230,7 +230,7 @@ PGTYPESdate_fmt_asc(date dDate, char *fmtstring, char *outbuf)
replace_type = PGTYPES_TYPE_UINT_4_LZ; replace_type = PGTYPES_TYPE_UINT_4_LZ;
break; break;
case PGTYPES_FMTDATE_YEAR_DIGITS_SHORT: case PGTYPES_FMTDATE_YEAR_DIGITS_SHORT:
replace_val.uint_val = tm.tm_year % 1000; replace_val.uint_val = tm.tm_year % 100;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
default: default:
...@@ -537,7 +537,7 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str) ...@@ -537,7 +537,7 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
* matches * matches
*/ */
free(str_copy); free(str_copy);
errno = PGTYPES_DATE_ERR_ENOTDMY; errno = PGTYPES_DATE_ERR_ENOSHORTDATE;
return -1; return -1;
} }
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.31 2006/08/13 10:18:30 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.32 2006/08/15 06:40:19 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include <ctype.h> #include <ctype.h>
...@@ -1512,7 +1512,10 @@ numericvar_to_double(numeric *var, double *dp) ...@@ -1512,7 +1512,10 @@ numericvar_to_double(numeric *var, double *dp)
if (errno == ERANGE) if (errno == ERANGE)
{ {
free(tmp); free(tmp);
errno = PGTYPES_NUM_OVERFLOW; if (val == 0)
errno = PGTYPES_NUM_UNDERFLOW;
else
errno = PGTYPES_NUM_OVERFLOW;
return -1; return -1;
} }
...@@ -1576,7 +1579,10 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp) ...@@ -1576,7 +1579,10 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
return -1; return -1;
if (errno == ERANGE) if (errno == ERANGE)
{ {
errno = PGTYPES_NUM_OVERFLOW; if (*lp == LONG_MIN)
errno = PGTYPES_NUM_UNDERFLOW;
else
errno = PGTYPES_NUM_OVERFLOW;
return -1; return -1;
} }
free(s); free(s);
......
...@@ -423,34 +423,47 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -423,34 +423,47 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
switch (*p) switch (*p)
{ {
/* the abbreviated name of the day in the week */
/* XXX should be locale aware */
case 'a': case 'a':
replace_val.str_val = pgtypes_date_weekdays_short[dow]; replace_val.str_val = pgtypes_date_weekdays_short[dow];
replace_type = PGTYPES_TYPE_STRING_CONSTANT; replace_type = PGTYPES_TYPE_STRING_CONSTANT;
break; break;
/* the full name of the day in the week */
/* XXX should be locale aware */
case 'A': case 'A':
replace_val.str_val = days[dow]; replace_val.str_val = days[dow];
replace_type = PGTYPES_TYPE_STRING_CONSTANT; replace_type = PGTYPES_TYPE_STRING_CONSTANT;
break; break;
/* the abbreviated name of the month */
/* XXX should be locale aware */
case 'b': case 'b':
case 'h': case 'h':
replace_val.str_val = months[tm->tm_mon]; replace_val.str_val = months[tm->tm_mon];
replace_type = PGTYPES_TYPE_STRING_CONSTANT; replace_type = PGTYPES_TYPE_STRING_CONSTANT;
break; break;
/* the full name name of the month */
/* XXX should be locale aware */
case 'B': case 'B':
replace_val.str_val = pgtypes_date_months[tm->tm_mon]; replace_val.str_val = pgtypes_date_months[tm->tm_mon];
replace_type = PGTYPES_TYPE_STRING_CONSTANT; replace_type = PGTYPES_TYPE_STRING_CONSTANT;
break; break;
/* The preferred date and time representation for the
* current locale. */
case 'c': case 'c':
/* XXX */ /* XXX */
break; break;
/* the century number with leading zeroes */
case 'C': case 'C':
replace_val.uint_val = tm->tm_year / 100; replace_val.uint_val = tm->tm_year / 100;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* day with leading zeroes (01 - 31) */
case 'd': case 'd':
replace_val.uint_val = tm->tm_mday; replace_val.uint_val = tm->tm_mday;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* the date in the format mm/dd/yy */
case 'D': case 'D':
/* /*
...@@ -467,10 +480,14 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -467,10 +480,14 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
if (i) if (i)
return i; return i;
break; break;
/* day with leading spaces (01 - 31) */
case 'e': case 'e':
replace_val.uint_val = tm->tm_mday; replace_val.uint_val = tm->tm_mday;
replace_type = PGTYPES_TYPE_UINT_2_LS; replace_type = PGTYPES_TYPE_UINT_2_LS;
break; break;
/*
* alternative format modifier
*/
case 'E': case 'E':
{ {
char tmp[4] = "%Ex"; char tmp[4] = "%Ex";
...@@ -496,6 +513,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -496,6 +513,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
} }
/*
* The ISO 8601 year with century as a decimal number. The
* 4-digit year corresponding to the ISO week number.
*/
case 'G': case 'G':
tm->tm_mon -= 1; tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%G", tm); i = strftime(q, *pstr_len, "%G", tm);
...@@ -509,6 +530,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -509,6 +530,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
tm->tm_mon += 1; tm->tm_mon += 1;
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/*
* Like %G, but without century, i.e., with a 2-digit year
* (00-99).
*/
case 'g': case 'g':
{ {
char *fmt = "%g"; /* Keep compiler quiet about char *fmt = "%g"; /* Keep compiler quiet about
...@@ -527,38 +552,57 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -527,38 +552,57 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
} }
break; break;
/* hour (24 hour clock) with leading zeroes */
case 'H': case 'H':
replace_val.uint_val = tm->tm_hour; replace_val.uint_val = tm->tm_hour;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* hour (12 hour clock) with leading zeroes */
case 'I': case 'I':
replace_val.uint_val = tm->tm_hour % 12; replace_val.uint_val = tm->tm_hour % 12;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/*
* The day of the year as a decimal number with leading zeroes.
* It ranges from 001 to 366.
*/
case 'j': case 'j':
replace_val.uint_val = tm->tm_yday; replace_val.uint_val = tm->tm_yday;
replace_type = PGTYPES_TYPE_UINT_3_LZ; replace_type = PGTYPES_TYPE_UINT_3_LZ;
break; break;
/*
* The hour (24 hour clock). Leading zeroes will be turned into
* spaces.
*/
case 'k': case 'k':
replace_val.uint_val = tm->tm_hour; replace_val.uint_val = tm->tm_hour;
replace_type = PGTYPES_TYPE_UINT_2_LS; replace_type = PGTYPES_TYPE_UINT_2_LS;
break; break;
/*
* The hour (12 hour clock). Leading zeroes will be turned into
* spaces.
*/
case 'l': case 'l':
replace_val.uint_val = tm->tm_hour % 12; replace_val.uint_val = tm->tm_hour % 12;
replace_type = PGTYPES_TYPE_UINT_2_LS; replace_type = PGTYPES_TYPE_UINT_2_LS;
break; break;
/* The month as a decimal number with a leading zero */
case 'm': case 'm':
replace_val.uint_val = tm->tm_mon; replace_val.uint_val = tm->tm_mon;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* The minute as a decimal number with a leading zero */
case 'M': case 'M':
replace_val.uint_val = tm->tm_min; replace_val.uint_val = tm->tm_min;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* A newline character */
case 'n': case 'n':
replace_val.char_val = '\n'; replace_val.char_val = '\n';
replace_type = PGTYPES_TYPE_CHAR; replace_type = PGTYPES_TYPE_CHAR;
break; break;
/* the AM/PM specifier (uppercase) */
/* XXX should be locale aware */
case 'p': case 'p':
if (tm->tm_hour < 12) if (tm->tm_hour < 12)
replace_val.str_val = "AM"; replace_val.str_val = "AM";
...@@ -566,6 +610,8 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -566,6 +610,8 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_val.str_val = "PM"; replace_val.str_val = "PM";
replace_type = PGTYPES_TYPE_STRING_CONSTANT; replace_type = PGTYPES_TYPE_STRING_CONSTANT;
break; break;
/* the AM/PM specifier (lowercase) */
/* XXX should be locale aware */
case 'P': case 'P':
if (tm->tm_hour < 12) if (tm->tm_hour < 12)
replace_val.str_val = "am"; replace_val.str_val = "am";
...@@ -573,6 +619,8 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -573,6 +619,8 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_val.str_val = "pm"; replace_val.str_val = "pm";
replace_type = PGTYPES_TYPE_STRING_CONSTANT; replace_type = PGTYPES_TYPE_STRING_CONSTANT;
break; break;
/* the time in the format %I:%M:%S %p */
/* XXX should be locale aware */
case 'r': case 'r':
i = dttofmtasc_replace(ts, dDate, dow, tm, i = dttofmtasc_replace(ts, dDate, dow, tm,
q, pstr_len, q, pstr_len,
...@@ -580,6 +628,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -580,6 +628,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
if (i) if (i)
return i; return i;
break; break;
/* The time in 24 hour notation (%H:%M) */
case 'R': case 'R':
i = dttofmtasc_replace(ts, dDate, dow, tm, i = dttofmtasc_replace(ts, dDate, dow, tm,
q, pstr_len, q, pstr_len,
...@@ -587,6 +636,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -587,6 +636,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
if (i) if (i)
return i; return i;
break; break;
/* The number of seconds since the Epoch (1970-01-01) */
case 's': case 's':
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
replace_val.int64_val = (*ts - SetEpochTimestamp()) / 1000000.0; replace_val.int64_val = (*ts - SetEpochTimestamp()) / 1000000.0;
...@@ -596,14 +646,17 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -596,14 +646,17 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_DOUBLE_NF; replace_type = PGTYPES_TYPE_DOUBLE_NF;
#endif #endif
break; break;
/* seconds as a decimal number with leading zeroes */
case 'S': case 'S':
replace_val.uint_val = tm->tm_sec; replace_val.uint_val = tm->tm_sec;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* A tabulator */
case 't': case 't':
replace_val.char_val = '\t'; replace_val.char_val = '\t';
replace_type = PGTYPES_TYPE_CHAR; replace_type = PGTYPES_TYPE_CHAR;
break; break;
/* The time in 24 hour notation (%H:%M:%S) */
case 'T': case 'T':
i = dttofmtasc_replace(ts, dDate, dow, tm, i = dttofmtasc_replace(ts, dDate, dow, tm,
q, pstr_len, q, pstr_len,
...@@ -611,12 +664,14 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -611,12 +664,14 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
if (i) if (i)
return i; return i;
break; break;
/* The day of the week as a decimal, Monday = 1, Sunday = 7 */
case 'u': case 'u':
if (dow == 0)
dow = 7;
replace_val.uint_val = dow; replace_val.uint_val = dow;
if (replace_val.uint_val == 0)
replace_val.uint_val = 7;
replace_type = PGTYPES_TYPE_UINT; replace_type = PGTYPES_TYPE_UINT;
break; break;
/* The week number of the year as a decimal number */
case 'U': case 'U':
tm->tm_mon -= 1; tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%U", tm); i = strftime(q, *pstr_len, "%U", tm);
...@@ -630,6 +685,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -630,6 +685,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
tm->tm_mon += 1; tm->tm_mon += 1;
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/*
* The ISO 8601:1988 week number of the current year as a
* decimal number.
*/
case 'V': case 'V':
i = strftime(q, *pstr_len, "%V", tm); i = strftime(q, *pstr_len, "%V", tm);
if (i == 0) if (i == 0)
...@@ -641,10 +700,15 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -641,10 +700,15 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
} }
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/*
* The day of the week as a decimal, Sunday being 0 and
* Monday 1.
*/
case 'w': case 'w':
replace_val.uint_val = dow; replace_val.uint_val = dow;
replace_type = PGTYPES_TYPE_UINT; replace_type = PGTYPES_TYPE_UINT;
break; break;
/* The week number of the year (another definition) */
case 'W': case 'W':
tm->tm_mon -= 1; tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%U", tm); i = strftime(q, *pstr_len, "%U", tm);
...@@ -658,6 +722,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -658,6 +722,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
tm->tm_mon += 1; tm->tm_mon += 1;
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/*
* The preferred date representation for the current locale
* without the time.
*/
case 'x': case 'x':
{ {
char *fmt = "%x"; /* Keep compiler quiet about char *fmt = "%x"; /* Keep compiler quiet about
...@@ -676,6 +744,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -676,6 +744,10 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
} }
break; break;
/*
* The preferred time representation for the current locale
* without the date.
*/
case 'X': case 'X':
tm->tm_mon -= 1; tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%X", tm); i = strftime(q, *pstr_len, "%X", tm);
...@@ -689,14 +761,17 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -689,14 +761,17 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
tm->tm_mon += 1; tm->tm_mon += 1;
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/* The year without the century (2 digits, leading zeroes) */
case 'y': case 'y':
replace_val.uint_val = tm->tm_year % 100; replace_val.uint_val = tm->tm_year % 100;
replace_type = PGTYPES_TYPE_UINT_2_LZ; replace_type = PGTYPES_TYPE_UINT_2_LZ;
break; break;
/* The year with the century (4 digits) */
case 'Y': case 'Y':
replace_val.uint_val = tm->tm_year; replace_val.uint_val = tm->tm_year;
replace_type = PGTYPES_TYPE_UINT; replace_type = PGTYPES_TYPE_UINT;
break; break;
/* The time zone offset from GMT */
case 'z': case 'z':
tm->tm_mon -= 1; tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%z", tm); i = strftime(q, *pstr_len, "%z", tm);
...@@ -710,6 +785,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -710,6 +785,7 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
tm->tm_mon += 1; tm->tm_mon += 1;
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/* The name or abbreviation of the time zone */
case 'Z': case 'Z':
tm->tm_mon -= 1; tm->tm_mon -= 1;
i = strftime(q, *pstr_len, "%Z", tm); i = strftime(q, *pstr_len, "%Z", tm);
...@@ -723,19 +799,18 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, ...@@ -723,19 +799,18 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
tm->tm_mon += 1; tm->tm_mon += 1;
replace_type = PGTYPES_TYPE_NOTHING; replace_type = PGTYPES_TYPE_NOTHING;
break; break;
/* A % sign */
case '%': case '%':
replace_val.char_val = '%'; replace_val.char_val = '%';
replace_type = PGTYPES_TYPE_CHAR; replace_type = PGTYPES_TYPE_CHAR;
break; break;
case '\0': case '\0':
/* fmtstr: blabla%' */ /* fmtstr: foo%' - The string ends with a % sign */
/* /*
* this is not compliant to the specification * this is not compliant to the specification
*/ */
return -1; return -1;
default: default:
/* /*
* if we don't know the pattern, we just copy it * if we don't know the pattern, we just copy it
*/ */
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.17 2006/03/11 04:38:40 momjian Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.18 2006/08/15 06:40:19 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -139,6 +139,11 @@ output_escaped_str(char *str) ...@@ -139,6 +139,11 @@ output_escaped_str(char *str)
fputs("\\\"", yyout); fputs("\\\"", yyout);
else if (str[i] == '\n') else if (str[i] == '\n')
fputs("\\\n", yyout); fputs("\\\n", yyout);
else if (str[i] == '\r' && str[i+1] == '\n')
{
fputs("\\\r\n", yyout);
i++;
}
else else
fputc(str[i], yyout); fputc(str[i], yyout);
} }
......
...@@ -10,7 +10,11 @@ override LDFLAGS += -L../../compatlib ...@@ -10,7 +10,11 @@ override LDFLAGS += -L../../compatlib
override LIBS += $(LIBS) -lecpg_compat override LIBS += $(LIBS) -lecpg_compat
TESTS = test_informix test_informix.c \ TESTS = test_informix test_informix.c \
test_informix2 test_informix2.c test_informix2 test_informix2.c \
dec_test dec_test.c \
rfmtdate rfmtdate.c \
rfmtlong rfmtlong.c \
charfuncs charfuncs.c
all: $(TESTS) all: $(TESTS)
...@@ -18,5 +22,19 @@ test_informix.c: test_informix.pgc ../regression.h ...@@ -18,5 +22,19 @@ test_informix.c: test_informix.pgc ../regression.h
$(ECPG) -o $@ -I$(srcdir) $< $(ECPG) -o $@ -I$(srcdir) $<
test_informix2.c: test_informix2.pgc ../regression.h test_informix2.c: test_informix2.pgc ../regression.h
$(ECPG) -o $@ -I$(srcdir) $<
dec_test.c: dec_test.pgc ../regression.h
$(ECPG) -o $@ -I$(srcdir) $<
rfmtdate.c: rfmtdate.pgc ../regression.h
$(ECPG) -o $@ -I$(srcdir) $<
rfmtlong.c: rfmtlong.pgc ../regression.h
$(ECPG) -o $@ -I$(srcdir) $<
rnull.c: rnull.pgc ../regression.h
$(ECPG_NOIND) -o $@ -I$(srcdir) $< $(ECPG_NOIND) -o $@ -I$(srcdir) $<
charfuncs.c: charfuncs.pgc ../regression.h
$(ECPG) -o $@ -I$(srcdir) $<
...@@ -59,10 +59,6 @@ int main(void) ...@@ -59,10 +59,6 @@ int main(void)
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
/* if (strlen(REGRESSDB1) > MAXDBLEN) {
exit(1);
}
*/
strcpy(dbname, "regress1"); strcpy(dbname, "regress1");
EXEC SQL connect to :dbname; EXEC SQL connect to :dbname;
sql_check("main", "connect", 0); sql_check("main", "connect", 0);
...@@ -80,12 +76,6 @@ int main(void) ...@@ -80,12 +76,6 @@ int main(void)
from history; from history;
sql_check("main", "select max", 100); sql_check("main", "select max", 100);
if (risnull(CDTIMETYPE, (char *) &maxd))
{
printf("Nothing on the history table\n\n");
exit(0);
}
EXEC SQL select customerid, timestamp EXEC SQL select customerid, timestamp
into :c, :d into :c, :d
from history from history
......
...@@ -170,62 +170,52 @@ int main(void) ...@@ -170,62 +170,52 @@ int main(void)
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
/* if (strlen(REGRESSDB1) > MAXDBLEN) {
exit(1);
}
*/
strcpy(dbname, "regress1"); strcpy(dbname, "regress1");
{ ECPGconnect(__LINE__, 1, dbname , NULL,NULL , NULL, 0); { ECPGconnect(__LINE__, 1, dbname , NULL,NULL , NULL, 0);
#line 67 "test_informix2.pgc" #line 63 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 67 "test_informix2.pgc" #line 63 "test_informix2.pgc"
sql_check("main", "connect", 0); sql_check("main", "connect", 0);
{ ECPGdo(__LINE__, 1, 0, NULL, "create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) ) ", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 1, 1, NULL, "create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) ) ", ECPGt_EOIT, ECPGt_EORT);
#line 70 "test_informix2.pgc" #line 66 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 70 "test_informix2.pgc" #line 66 "test_informix2.pgc"
sql_check("main", "create", 0); sql_check("main", "create", 0);
{ ECPGdo(__LINE__, 1, 0, NULL, "insert into history ( customerid , timestamp , action_taken , narrative ) values( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 1, 1, NULL, "insert into history ( customerid , timestamp , action_taken , narrative ) values( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )", ECPGt_EOIT, ECPGt_EORT);
#line 75 "test_informix2.pgc" #line 71 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 75 "test_informix2.pgc" #line 71 "test_informix2.pgc"
sql_check("main", "insert", 0); sql_check("main", "insert", 0);
{ ECPGdo(__LINE__, 1, 0, NULL, "select max ( timestamp ) from history ", ECPGt_EOIT, { ECPGdo(__LINE__, 1, 1, NULL, "select max ( timestamp ) from history ", ECPGt_EOIT,
ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp), ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 80 "test_informix2.pgc" #line 76 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 80 "test_informix2.pgc" #line 76 "test_informix2.pgc"
sql_check("main", "select max", 100); sql_check("main", "select max", 100);
if (risnull(CDTIMETYPE, (char *) &maxd)) { ECPGdo(__LINE__, 1, 1, NULL, "select customerid , timestamp from history where timestamp = ? limit 1 ",
{
printf("Nothing on the history table\n\n");
exit(0);
}
{ ECPGdo(__LINE__, 1, 0, NULL, "select customerid , timestamp from history where timestamp = ? limit 1 ",
ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp), ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_int,&(c),(long)1,(long)1,sizeof(int), ECPGt_int,&(c),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_timestamp,&(d),(long)1,(long)1,sizeof(timestamp), ECPGt_timestamp,&(d),(long)1,(long)1,sizeof(timestamp),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 93 "test_informix2.pgc" #line 83 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 93 "test_informix2.pgc" #line 83 "test_informix2.pgc"
sql_check("main", "select", 0); sql_check("main", "select", 0);
...@@ -236,45 +226,45 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -236,45 +226,45 @@ if (sqlca.sqlcode < 0) sqlprint();}
c++; c++;
{ ECPGdo(__LINE__, 1, 0, NULL, "insert into history ( customerid , timestamp , action_taken , narrative ) values( ? , ? , 'test' , 'test' )", { ECPGdo(__LINE__, 1, 1, NULL, "insert into history ( customerid , timestamp , action_taken , narrative ) values( ? , ? , 'test' , 'test' )",
ECPGt_int,&(c),(long)1,(long)1,sizeof(int), ECPGt_int,&(c),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp), ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 105 "test_informix2.pgc" #line 95 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 105 "test_informix2.pgc" #line 95 "test_informix2.pgc"
sql_check("main", "update", 0); sql_check("main", "update", 0);
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 108 "test_informix2.pgc" #line 98 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 108 "test_informix2.pgc" #line 98 "test_informix2.pgc"
{ ECPGdo(__LINE__, 1, 0, NULL, "drop table history ", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 1, 1, NULL, "drop table history ", ECPGt_EOIT, ECPGt_EORT);
#line 110 "test_informix2.pgc" #line 100 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 110 "test_informix2.pgc" #line 100 "test_informix2.pgc"
sql_check("main", "drop", 0); sql_check("main", "drop", 0);
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 113 "test_informix2.pgc" #line 103 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 113 "test_informix2.pgc" #line 103 "test_informix2.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT"); { ECPGdisconnect(__LINE__, "CURRENT");
#line 115 "test_informix2.pgc" #line 105 "test_informix2.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 115 "test_informix2.pgc" #line 105 "test_informix2.pgc"
sql_check("main", "disconnect", 0); sql_check("main", "disconnect", 0);
......
...@@ -2,39 +2,39 @@ ...@@ -2,39 +2,39 @@
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 70: QUERY: create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) ) on connection regress1 [NO_PID]: ECPGexecute line 66: QUERY: create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) ) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 70 Ok: CREATE TABLE [NO_PID]: ECPGexecute line 66 Ok: CREATE TABLE
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 73: QUERY: insert into history ( customerid , timestamp , action_taken , narrative ) values( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' ) on connection regress1 [NO_PID]: ECPGexecute line 69: QUERY: insert into history ( customerid , timestamp , action_taken , narrative ) values( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' ) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 73 Ok: INSERT 0 1 [NO_PID]: ECPGexecute line 69 Ok: INSERT 0 1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 78: QUERY: select max ( timestamp ) from history on connection regress1 [NO_PID]: ECPGexecute line 74: QUERY: select max ( timestamp ) from history on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 78: Correctly got 1 tuples with 1 fields [NO_PID]: ECPGexecute line 74: Correctly got 1 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_data line 78: RESULT: Wed May 07 13:28:34 2003 offset: -1 array: Yes [NO_PID]: ECPGget_data line 74: RESULT: Wed May 07 13:28:34 2003 offset: -1 array: Yes
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 89: QUERY: select customerid , timestamp from history where timestamp = timestamp '2003-05-07 13:28:34' limit 1 on connection regress1 [NO_PID]: ECPGexecute line 79: QUERY: select customerid , timestamp from history where timestamp = timestamp '2003-05-07 13:28:34' limit 1 on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 89: Correctly got 1 tuples with 2 fields [NO_PID]: ECPGexecute line 79: Correctly got 1 tuples with 2 fields
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_data line 89: RESULT: 1 offset: -1 array: Yes [NO_PID]: ECPGget_data line 79: RESULT: 1 offset: -1 array: Yes
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_data line 89: RESULT: Wed May 07 13:28:34 2003 offset: -1 array: Yes [NO_PID]: ECPGget_data line 79: RESULT: Wed May 07 13:28:34 2003 offset: -1 array: Yes
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 103: QUERY: insert into history ( customerid , timestamp , action_taken , narrative ) values( 2 , timestamp '2003-05-08 15:53:39' , 'test' , 'test' ) on connection regress1 [NO_PID]: ECPGexecute line 93: QUERY: insert into history ( customerid , timestamp , action_taken , narrative ) values( 2 , timestamp '2003-05-08 15:53:39' , 'test' , 'test' ) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 103 Ok: INSERT 0 1 [NO_PID]: ECPGexecute line 93 Ok: INSERT 0 1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGtrans line 108 action = commit connection = regress1 [NO_PID]: ECPGtrans line 98 action = commit connection = regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 110: QUERY: drop table history on connection regress1 [NO_PID]: ECPGexecute line 100: QUERY: drop table history on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGexecute line 110 Ok: DROP TABLE [NO_PID]: ECPGexecute line 100 Ok: DROP TABLE
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGtrans line 113 action = commit connection = regress1 [NO_PID]: ECPGtrans line 103 action = commit connection = regress1
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection regress1 closed. [NO_PID]: ecpg_finish: Connection regress1 closed.
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
...@@ -31,6 +31,7 @@ char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4", ...@@ -31,6 +31,7 @@ char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
into decimal */ into decimal */
"1234567890123456789012345678.921", /* 31 digits should NOT "1234567890123456789012345678.921", /* 31 digits should NOT
fit into decimal */ fit into decimal */
"not a number",
NULL}; NULL};
...@@ -45,46 +46,52 @@ main(void) ...@@ -45,46 +46,52 @@ main(void)
numeric *num, *nin; numeric *num, *nin;
decimal *dec; decimal *dec;
long l; long l;
int i, q, r, k; int i, j, k, q, r, count = 0;
double d; double d;
numeric **numarr = (numeric **) malloc(1);
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
for (i = 0; nums[i]; i++) for (i = 0; nums[i]; i++)
{ {
num = PGTYPESnumeric_from_asc(nums[i], &endptr); num = PGTYPESnumeric_from_asc(nums[i], &endptr);
check_errno(); if (!num) check_errno();
if (endptr != NULL) if (endptr != NULL)
{ {
printf("endptr of %d is not NULL\n", i); printf("endptr of %d is not NULL\n", i);
if (*endptr != '\0') if (*endptr != '\0')
printf("*endptr of %d is not \\0\n", i); printf("*endptr of %d is not \\0\n", i);
} }
if (!num) continue;
numarr = realloc(numarr, sizeof(numeric *) * (count + 1));
numarr[count++] = num;
text = PGTYPESnumeric_to_asc(num, -1); text = PGTYPESnumeric_to_asc(num, -1);
check_errno(); if (!text) check_errno();
printf("num[%d,1]: %s\n", i, text); free(text); printf("num[%d,1]: %s\n", i, text); free(text);
text = PGTYPESnumeric_to_asc(num, 0); text = PGTYPESnumeric_to_asc(num, 0);
check_errno(); if (!text) check_errno();
printf("num[%d,2]: %s\n", i, text); free(text); printf("num[%d,2]: %s\n", i, text); free(text);
text = PGTYPESnumeric_to_asc(num, 1); text = PGTYPESnumeric_to_asc(num, 1);
check_errno(); if (!text) check_errno();
printf("num[%d,3]: %s\n", i, text); free(text); printf("num[%d,3]: %s\n", i, text); free(text);
text = PGTYPESnumeric_to_asc(num, 2); text = PGTYPESnumeric_to_asc(num, 2);
check_errno(); if (!text) check_errno();
printf("num[%d,4]: %s\n", i, text); free(text); printf("num[%d,4]: %s\n", i, text); free(text);
nin = PGTYPESnumeric_new(); nin = PGTYPESnumeric_new();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
check_errno(); if (!text) check_errno();
printf("num[%d,5]: %s\n", i, text); free(text); printf("num[%d,5]: %s\n", i, text); free(text);
r = PGTYPESnumeric_to_long(num, &l); r = PGTYPESnumeric_to_long(num, &l);
check_errno(); if (r) check_errno();
printf("num[%d,6]: %ld (r: %d)\n", i, r?0L:l, r); printf("num[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_long(l, nin); r = PGTYPESnumeric_from_long(l, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,7]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,7]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -92,12 +99,12 @@ main(void) ...@@ -92,12 +99,12 @@ main(void)
} }
r = PGTYPESnumeric_to_int(num, &k); r = PGTYPESnumeric_to_int(num, &k);
check_errno(); if (r) check_errno();
printf("num[%d,8]: %d (r: %d)\n", i, r?0:k, r); printf("num[%d,8]: %d (r: %d)\n", i, r?0:k, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_int(k, nin); r = PGTYPESnumeric_from_int(k, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,9]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,9]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -105,12 +112,12 @@ main(void) ...@@ -105,12 +112,12 @@ main(void)
} }
r = PGTYPESnumeric_to_double(num, &d); r = PGTYPESnumeric_to_double(num, &d);
check_errno(); if (r) check_errno();
printf("num[%d,10]: %2.7f (r: %d)\n", i, r?0.0:d, r); printf("num[%d,10]: %2.7f (r: %d)\n", i, r?0.0:d, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_double(d, nin); r = PGTYPESnumeric_from_double(d, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,11]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,11]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -119,14 +126,14 @@ main(void) ...@@ -119,14 +126,14 @@ main(void)
dec = PGTYPESdecimal_new(); dec = PGTYPESdecimal_new();
r = PGTYPESnumeric_to_decimal(num, dec); r = PGTYPESnumeric_to_decimal(num, dec);
check_errno(); if (r) check_errno();
/* we have no special routine for outputting decimal, it would /* we have no special routine for outputting decimal, it would
* convert to a numeric anyway */ * convert to a numeric anyway */
printf("num[%d,12]: - (r: %d)\n", i, r); printf("num[%d,12]: - (r: %d)\n", i, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_decimal(dec, nin); r = PGTYPESnumeric_from_decimal(dec, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,13]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,13]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -138,6 +145,72 @@ main(void) ...@@ -138,6 +145,72 @@ main(void)
printf("\n"); printf("\n");
} }
for (i = 0; i < count; i++)
{
for (j = 0; j < count; j++)
{
numeric* a = PGTYPESnumeric_new();
numeric* s = PGTYPESnumeric_new();
numeric* m = PGTYPESnumeric_new();
numeric* d = PGTYPESnumeric_new();
r = PGTYPESnumeric_add(numarr[i], numarr[j], a);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(a, 10);
printf("num[a,%d,%d]: %s\n", i, j, text);
free(text);
}
r = PGTYPESnumeric_sub(numarr[i], numarr[j], s);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(s, 10);
printf("num[s,%d,%d]: %s\n", i, j, text);
free(text);
}
r = PGTYPESnumeric_mul(numarr[i], numarr[j], m);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(m, 10);
printf("num[m,%d,%d]: %s\n", i, j, text);
free(text);
}
r = PGTYPESnumeric_div(numarr[i], numarr[j], d);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(d, 10);
printf("num[d,%d,%d]: %s\n", i, j, text);
free(text);
}
}
}
for (i = 0; i < count; i++)
{
text = PGTYPESnumeric_to_asc(numarr[i], -1);
printf("%d: %s\n", i, text);
free(text);
}
return (0); return (0);
} }
...@@ -152,9 +225,15 @@ check_errno(void) ...@@ -152,9 +225,15 @@ check_errno(void)
case PGTYPES_NUM_OVERFLOW: case PGTYPES_NUM_OVERFLOW:
printf("(errno == PGTYPES_NUM_OVERFLOW) - "); printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
break; break;
case PGTYPES_NUM_UNDERFLOW:
printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
break;
case PGTYPES_NUM_BAD_NUMERIC: case PGTYPES_NUM_BAD_NUMERIC:
printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - "); printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
break; break;
case PGTYPES_NUM_DIVIDE_ZERO:
printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
break;
default: default:
printf("(unknown errno (%d))\n", errno); printf("(unknown errno (%d))\n", errno);
printf("(libc: (%s)) ", strerror(errno)); printf("(libc: (%s)) ", strerror(errno));
......
...@@ -13,6 +13,7 @@ char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4", ...@@ -13,6 +13,7 @@ char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
into decimal */ into decimal */
"1234567890123456789012345678.921", /* 31 digits should NOT "1234567890123456789012345678.921", /* 31 digits should NOT
fit into decimal */ fit into decimal */
"not a number",
NULL}; NULL};
...@@ -27,46 +28,52 @@ main(void) ...@@ -27,46 +28,52 @@ main(void)
numeric *num, *nin; numeric *num, *nin;
decimal *dec; decimal *dec;
long l; long l;
int i, q, r, k; int i, j, k, q, r, count = 0;
double d; double d;
numeric **numarr = (numeric **) malloc(1);
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
for (i = 0; nums[i]; i++) for (i = 0; nums[i]; i++)
{ {
num = PGTYPESnumeric_from_asc(nums[i], &endptr); num = PGTYPESnumeric_from_asc(nums[i], &endptr);
check_errno(); if (!num) check_errno();
if (endptr != NULL) if (endptr != NULL)
{ {
printf("endptr of %d is not NULL\n", i); printf("endptr of %d is not NULL\n", i);
if (*endptr != '\0') if (*endptr != '\0')
printf("*endptr of %d is not \\0\n", i); printf("*endptr of %d is not \\0\n", i);
} }
if (!num) continue;
numarr = realloc(numarr, sizeof(numeric *) * (count + 1));
numarr[count++] = num;
text = PGTYPESnumeric_to_asc(num, -1); text = PGTYPESnumeric_to_asc(num, -1);
check_errno(); if (!text) check_errno();
printf("num[%d,1]: %s\n", i, text); free(text); printf("num[%d,1]: %s\n", i, text); free(text);
text = PGTYPESnumeric_to_asc(num, 0); text = PGTYPESnumeric_to_asc(num, 0);
check_errno(); if (!text) check_errno();
printf("num[%d,2]: %s\n", i, text); free(text); printf("num[%d,2]: %s\n", i, text); free(text);
text = PGTYPESnumeric_to_asc(num, 1); text = PGTYPESnumeric_to_asc(num, 1);
check_errno(); if (!text) check_errno();
printf("num[%d,3]: %s\n", i, text); free(text); printf("num[%d,3]: %s\n", i, text); free(text);
text = PGTYPESnumeric_to_asc(num, 2); text = PGTYPESnumeric_to_asc(num, 2);
check_errno(); if (!text) check_errno();
printf("num[%d,4]: %s\n", i, text); free(text); printf("num[%d,4]: %s\n", i, text); free(text);
nin = PGTYPESnumeric_new(); nin = PGTYPESnumeric_new();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
check_errno(); if (!text) check_errno();
printf("num[%d,5]: %s\n", i, text); free(text); printf("num[%d,5]: %s\n", i, text); free(text);
r = PGTYPESnumeric_to_long(num, &l); r = PGTYPESnumeric_to_long(num, &l);
check_errno(); if (r) check_errno();
printf("num[%d,6]: %ld (r: %d)\n", i, r?0L:l, r); printf("num[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_long(l, nin); r = PGTYPESnumeric_from_long(l, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,7]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,7]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -74,12 +81,12 @@ main(void) ...@@ -74,12 +81,12 @@ main(void)
} }
r = PGTYPESnumeric_to_int(num, &k); r = PGTYPESnumeric_to_int(num, &k);
check_errno(); if (r) check_errno();
printf("num[%d,8]: %d (r: %d)\n", i, r?0:k, r); printf("num[%d,8]: %d (r: %d)\n", i, r?0:k, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_int(k, nin); r = PGTYPESnumeric_from_int(k, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,9]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,9]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -87,12 +94,12 @@ main(void) ...@@ -87,12 +94,12 @@ main(void)
} }
r = PGTYPESnumeric_to_double(num, &d); r = PGTYPESnumeric_to_double(num, &d);
check_errno(); if (r) check_errno();
printf("num[%d,10]: %2.7f (r: %d)\n", i, r?0.0:d, r); printf("num[%d,10]: %2.7f (r: %d)\n", i, r?0.0:d, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_double(d, nin); r = PGTYPESnumeric_from_double(d, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,11]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,11]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -101,14 +108,14 @@ main(void) ...@@ -101,14 +108,14 @@ main(void)
dec = PGTYPESdecimal_new(); dec = PGTYPESdecimal_new();
r = PGTYPESnumeric_to_decimal(num, dec); r = PGTYPESnumeric_to_decimal(num, dec);
check_errno(); if (r) check_errno();
/* we have no special routine for outputting decimal, it would /* we have no special routine for outputting decimal, it would
* convert to a numeric anyway */ * convert to a numeric anyway */
printf("num[%d,12]: - (r: %d)\n", i, r); printf("num[%d,12]: - (r: %d)\n", i, r);
if (r == 0) if (r == 0)
{ {
r = PGTYPESnumeric_from_decimal(dec, nin); r = PGTYPESnumeric_from_decimal(dec, nin);
check_errno(); if (r) check_errno();
text = PGTYPESnumeric_to_asc(nin, 2); text = PGTYPESnumeric_to_asc(nin, 2);
q = PGTYPESnumeric_cmp(num, nin); q = PGTYPESnumeric_cmp(num, nin);
printf("num[%d,13]: %s (r: %d - cmp: %d)\n", i, text, r, q); printf("num[%d,13]: %s (r: %d - cmp: %d)\n", i, text, r, q);
...@@ -120,6 +127,72 @@ main(void) ...@@ -120,6 +127,72 @@ main(void)
printf("\n"); printf("\n");
} }
for (i = 0; i < count; i++)
{
for (j = 0; j < count; j++)
{
numeric* a = PGTYPESnumeric_new();
numeric* s = PGTYPESnumeric_new();
numeric* m = PGTYPESnumeric_new();
numeric* d = PGTYPESnumeric_new();
r = PGTYPESnumeric_add(numarr[i], numarr[j], a);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(a, 10);
printf("num[a,%d,%d]: %s\n", i, j, text);
free(text);
}
r = PGTYPESnumeric_sub(numarr[i], numarr[j], s);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(s, 10);
printf("num[s,%d,%d]: %s\n", i, j, text);
free(text);
}
r = PGTYPESnumeric_mul(numarr[i], numarr[j], m);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(m, 10);
printf("num[m,%d,%d]: %s\n", i, j, text);
free(text);
}
r = PGTYPESnumeric_div(numarr[i], numarr[j], d);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
text = PGTYPESnumeric_to_asc(d, 10);
printf("num[d,%d,%d]: %s\n", i, j, text);
free(text);
}
}
}
for (i = 0; i < count; i++)
{
text = PGTYPESnumeric_to_asc(numarr[i], -1);
printf("%d: %s\n", i, text);
free(text);
}
return (0); return (0);
} }
...@@ -134,9 +207,15 @@ check_errno(void) ...@@ -134,9 +207,15 @@ check_errno(void)
case PGTYPES_NUM_OVERFLOW: case PGTYPES_NUM_OVERFLOW:
printf("(errno == PGTYPES_NUM_OVERFLOW) - "); printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
break; break;
case PGTYPES_NUM_UNDERFLOW:
printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
break;
case PGTYPES_NUM_BAD_NUMERIC: case PGTYPES_NUM_BAD_NUMERIC:
printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - "); printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
break; break;
case PGTYPES_NUM_DIVIDE_ZERO:
printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
break;
default: default:
printf("(unknown errno (%d))\n", errno); printf("(unknown errno (%d))\n", errno);
printf("(libc: (%s)) ", strerror(errno)); printf("(libc: (%s)) ", strerror(errno));
......
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