Commit 4a445f5d authored by Michael Meskes's avatar Michael Meskes

Sorry, forgot the new files.

parent b30da7ba
#include <stdio.h>
#include <stdlib.h>
#include <sqltypes.h>
int main(void)
{
char t1[] = "abc def ghi ";
/* 123456789012345 */
char buf[50];
int k;
printf("t1: _%s_\n", t1);
rupshift(t1);
printf("t1: _%s_\n", t1);
k = 2;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
k = 5;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
k = 9;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
k = 15;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_numeric.h>
#include <pgtypes_error.h>
#include <decimal.h>
#include <sqltypes.h>
exec sql include ../regression;
/*
TODO:
deccmp => DECUNKNOWN
decimal point: , and/or . ?
ECPG_INFORMIX_BAD_EXPONENT ?
*/
char* decs[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
"2E-394", ".1E-2", "+.0", "-592.49E-07", "+32.84e-4",
".500001", "-.5000001",
"1234567890123456789012345678.91", /* 30 digits should fit
into decimal */
"1234567890123456789012345678.921", /* 31 digits should NOT
fit into decimal */
"not a number",
NULL};
static void
check_errno(void);
#define BUFSIZE 200
int
main(void)
{
decimal *dec, *din;
char buf[BUFSIZE];
long l;
int i, j, k, q, r, count = 0;
double dbl;
decimal **decarr = (decimal **) malloc(1);
ECPGdebug(1, stderr);
for (i = 0; decs[i]; i++)
{
dec = PGTYPESdecimal_new();
r = deccvasc(decs[i], strlen(decs[i]), dec);
if (r)
{
check_errno();
printf("dec[%d,0]: r: %d\n", i, r);
continue;
}
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
decarr[count++] = dec;
r = dectoasc(dec, buf, BUFSIZE-1, -1);
if (r < 0) check_errno();
printf("dec[%d,1]: r: %d, %s\n", i, r, buf);
r = dectoasc(dec, buf, BUFSIZE-1, 0);
if (r < 0) check_errno();
printf("dec[%d,2]: r: %d, %s\n", i, r, buf);
r = dectoasc(dec, buf, BUFSIZE-1, 1);
if (r < 0) check_errno();
printf("dec[%d,3]: r: %d, %s\n", i, r, buf);
r = dectoasc(dec, buf, BUFSIZE-1, 2);
if (r < 0) check_errno();
printf("dec[%d,4]: r: %d, %s\n", i, r, buf);
din = PGTYPESdecimal_new();
r = dectoasc(din, buf, BUFSIZE-1, 2);
if (!r < 0) check_errno();
printf("dec[%d,5]: r: %d, %s\n", i, r, buf);
r = dectolong(dec, &l);
if (r) check_errno();
printf("dec[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
if (r == 0)
{
r = deccvlong(l, din);
if (r) check_errno();
dectoasc(din, buf, BUFSIZE-1, 2);
q = deccmp(dec, din);
printf("dec[%d,7]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
}
r = dectoint(dec, &k);
if (r) check_errno();
printf("dec[%d,8]: %d (r: %d)\n", i, r?0:k, r);
if (r == 0)
{
r = deccvint(k, din);
if (r) check_errno();
dectoasc(din, buf, BUFSIZE-1, 2);
q = deccmp(dec, din);
printf("dec[%d,9]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
}
r = dectodbl(dec, &dbl);
if (r) check_errno();
printf("dec[%d,10]: %2.7f (r: %d)\n", i, r?0.0:dbl, r);
if (r == 0)
{
r = deccvdbl(dbl, din);
if (r)
{
check_errno();
printf("dec[%d,11(f)]: - (r: %d)\n", i, r);
}
else
{
dectoasc(din, buf, BUFSIZE-1, 2);
q = deccmp(dec, din);
printf("dec[%d,11]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
}
}
PGTYPESdecimal_free(din);
printf("\n");
}
/* add a NULL value */
dec = PGTYPESdecimal_new();
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
decarr[count++] = dec;
rsetnull(CDECIMALTYPE, (char *) decarr[count-1]);
printf("dec[%d]: %sNULL\n", count-1,
risnull(CDECIMALTYPE, (char *) decarr[count-1]) ? "" : "NOT ");
printf("dec[0]: %sNULL\n",
risnull(CDECIMALTYPE, (char *) decarr[0]) ? "" : "NOT ");
r = dectoasc(decarr[3], buf, -1, -1);
check_errno(); printf("dectoasc with len == -1: r: %d\n", r);
r = dectoasc(decarr[3], buf, 0, -1);
check_errno(); printf("dectoasc with len == 0: r: %d\n", r);
for (i = 0; i < count; i++)
{
for (j = 0; j < count; j++)
{
decimal a, s, m, d;
int c;
c = deccmp(decarr[i], decarr[j]);
printf("dec[c,%d,%d]: %d\n", i, j, c);
r = decadd(decarr[i], decarr[j], &a);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&a, buf, BUFSIZE-1, -1);
printf("dec[a,%d,%d]: %s\n", i, j, buf);
}
r = decsub(decarr[i], decarr[j], &s);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&s, buf, BUFSIZE-1, -1);
printf("dec[s,%d,%d]: %s\n", i, j, buf);
}
r = decmul(decarr[i], decarr[j], &m);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&m, buf, BUFSIZE-1, -1);
printf("dec[m,%d,%d]: %s\n", i, j, buf);
}
r = decdiv(decarr[i], decarr[j], &d);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&d, buf, BUFSIZE-1, -1);
printf("dec[d,%d,%d]: %s\n", i, j, buf);
}
}
}
for (i = 0; i < count; i++)
{
dectoasc(decarr[i], buf, BUFSIZE-1, -1);
printf("%d: %s\n", i, buf);
}
return (0);
}
static void
check_errno(void)
{
switch(errno)
{
case 0:
printf("(no errno set) - ");
break;
case ECPG_INFORMIX_NUM_OVERFLOW:
printf("(errno == ECPG_INFORMIX_NUM_OVERFLOW) - ");
break;
case ECPG_INFORMIX_NUM_UNDERFLOW:
printf("(errno == ECPG_INFORMIX_NUM_UNDERFLOW) - ");
break;
case PGTYPES_NUM_OVERFLOW:
printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
break;
case PGTYPES_NUM_UNDERFLOW:
printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
break;
case PGTYPES_NUM_BAD_NUMERIC:
printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
break;
case PGTYPES_NUM_DIVIDE_ZERO:
printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
break;
default:
printf("(unknown errno (%d))\n", errno);
printf("(libc: (%s)) ", strerror(errno));
break;
}
}
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_error.h>
#include <sqltypes.h>
/*
* This file tests various forms of date-input/output by means of
* rfmtdate / rdefmtdate / rstrdate
*/
static void
check_return(int ret);
static void
date_test_strdate(char *input)
{
static int i;
date d;
int r, q;
char dbuf[11];
r = rstrdate(input, &d);
printf("r: %d ", r);
if (r == 0)
{
q = rdatestr(d, dbuf);
printf("q: %d ", q);
if (q == 0)
{
printf("date %d: %s\n", i++, dbuf);
}
else
printf("\n");
}
else
check_return(r);
}
static void
date_test_defmt(char *fmt, char *input)
{
static int i;
char dbuf[11];
date d;
int q, r;
r = rdefmtdate(&d, fmt, input);
printf("r: %d ", r);
if (r == 0)
{
q = rdatestr(d, dbuf);
printf("q: %d ", q);
if (q == 0)
{
printf("date %d: %s\n", i++, dbuf);
}
else
printf("\n");
}
else
check_return(r);
}
static void
date_test_fmt(date d, char *fmt)
{
static int i;
char buf[200];
int r;
r = rfmtdate(d, fmt, buf);
printf("r: %d ", r);
if (r != 0)
check_return(r);
else
printf("date: %d: %s\n", i++, buf);
}
int
main(void)
{
short mdy[3] = { 11, 23, 1959 };
char dbuf[11];
date d;
int r;
ECPGdebug(1, stderr);
r = rmdyjul(mdy, &d);
printf("create: r: %d\n", r);
if (r == 0)
{
rdatestr(d, dbuf);
printf("date: %s\n", dbuf);
}
/* input mask is mmddyyyy */
date_test_strdate("12031994");
date_test_strdate("9.6.1994");
date_test_fmt(d, "mmddyy");
date_test_fmt(d, "ddmmyy");
date_test_fmt(d, "yymmdd");
date_test_fmt(d, "yy/mm/dd");
date_test_fmt(d, "yy mm dd");
date_test_fmt(d, "yy.mm.dd");
date_test_fmt(d, ".mm.yyyy.dd.");
date_test_fmt(d, "mmm. dd, yyyy");
date_test_fmt(d, "mmm dd yyyy");
date_test_fmt(d, "yyyy dd mm");
date_test_fmt(d, "ddd, mmm. dd, yyyy");
date_test_fmt(d, "(ddd) mmm. dd, yyyy");
date_test_defmt("ddmmyy", "21-2-54");
date_test_defmt("ddmmyy", "2-12-54");
date_test_defmt("ddmmyy", "20111954");
date_test_defmt("ddmmyy", "130464");
date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
date_test_defmt("yy/mm/dd", "1954, February 3rd");
date_test_defmt("mmm.dd.yyyy", "041269");
date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
date_test_defmt("mmm.dd.yyyy", "9/14/58");
date_test_defmt("yy/mm/dd", "47/03/29");
date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
date_test_defmt("mmddyy", "Nov 14th, 1985");
/* ok: still contains dd mm yy */
date_test_defmt("bladdfoommbaryybong", "20/11/1954");
/* 1994 is not a leap year, it accepts the date as 01-03-1994 */
date_test_defmt("ddmmyy", "29-02-1994");
/* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
date_test_defmt("dmy", "20/11/1954");
/* ECPG_INFORMIX_ENOSHORTDATE */
date_test_defmt("ddmmyy", "21254");
date_test_defmt("ddmmyy", " 21254 ");
/* ECPG_INFORMIX_BAD_DAY */
date_test_defmt("ddmmyy", "320494");
/* ECPG_INFORMIX_BAD_MONTH */
date_test_defmt("mm-yyyy-dd", "13-1993-21");
/* ECPG_INFORMIX_BAD_YEAR */
/* ??? */
return (0);
}
static void
check_return(ret)
{
switch(ret)
{
case ECPG_INFORMIX_ENOTDMY:
printf("(ECPG_INFORMIX_ENOTDMY)");
break;
case ECPG_INFORMIX_ENOSHORTDATE:
printf("(ECPG_INFORMIX_ENOSHORTDATE)");
break;
case ECPG_INFORMIX_BAD_DAY:
printf("(ECPG_INFORMIX_BAD_DAY)");
break;
case ECPG_INFORMIX_BAD_MONTH:
printf("(ECPG_INFORMIX_BAD_MONTH)");
break;
default:
printf("(unknown ret: %d)", ret);
break;
}
printf("\n");
}
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_error.h>
#include <sqltypes.h>
/*
* This file tests various forms of long-input/output by means of
* rfmtlong
*/
static void
check_return(int ret);
static void
fmtlong(long lng, char *fmt)
{
static int i;
int r;
char buf[30];
r = rfmtlong(lng, fmt, buf);
printf("r: %d ", r);
if (r == 0)
{
printf("%d: %s (fmt was: %s)\n", i++, buf, fmt);
}
else
check_return(r);
}
int
main(void)
{
ECPGdebug(1, stderr);
fmtlong(-8494493, "-<<<<,<<<,<<<,<<<");
fmtlong(-8494493, "################");
fmtlong(-8494493, "+++$$$$$$$$$$$$$.##");
fmtlong(-8494493, "(&,&&&,&&&,&&&.)");
fmtlong(-8494493, "<<<<,<<<,<<<,<<<");
fmtlong(-8494493, "$************.**");
fmtlong(-8494493, "---$************.**");
fmtlong(-8494493, "+-+################");
fmtlong(-8494493, "abc: ################+-+");
fmtlong(-8494493, "+<<<<,<<<,<<<,<<<");
return (0);
}
static void
check_return(ret)
{
switch(ret)
{
case ECPG_INFORMIX_ENOTDMY:
printf("(ECPG_INFORMIX_ENOTDMY)");
break;
case ECPG_INFORMIX_ENOSHORTDATE:
printf("(ECPG_INFORMIX_ENOSHORTDATE)");
break;
case ECPG_INFORMIX_BAD_DAY:
printf("(ECPG_INFORMIX_BAD_DAY)");
break;
case ECPG_INFORMIX_BAD_MONTH:
printf("(ECPG_INFORMIX_BAD_MONTH)");
break;
default:
printf("(unknown ret: %d)", ret);
break;
}
printf("\n");
}
/* Processed by ecpg (4.2.1) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* Needed for informix compatibility */
#include <ecpg_informix.h>
/* End of automatic include section */
#line 1 "charfuncs.pgc"
#include <stdio.h>
#include <stdlib.h>
#include <sqltypes.h>
int main(void)
{
char t1[] = "abc def ghi ";
/* 123456789012345 */
char buf[50];
int k;
printf("t1: _%s_\n", t1);
rupshift(t1);
printf("t1: _%s_\n", t1);
k = 2;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
k = 5;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
k = 9;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
k = 15;
ldchar(t1, k, buf);
printf("byleng(t1, %d): %d, ldchar: _%s_\n", k, byleng(t1, k), buf);
return 0;
}
t1: _abc def ghi _
t1: _ABC DEF GHI _
byleng(t1, 2): 2, ldchar: _AB_
byleng(t1, 5): 3, ldchar: _ABC_
byleng(t1, 9): 8, ldchar: _ABC DEF_
byleng(t1, 15): 13, ldchar: _ABC DEF GHI_
/* Processed by ecpg (4.2.1) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* Needed for informix compatibility */
#include <ecpg_informix.h>
/* End of automatic include section */
#line 1 "dec_test.pgc"
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_numeric.h>
#include <pgtypes_error.h>
#include <decimal.h>
#include <sqltypes.h>
#line 1 "./../regression.h"
#line 8 "dec_test.pgc"
/*
TODO:
deccmp => DECUNKNOWN
decimal point: , and/or . ?
ECPG_INFORMIX_BAD_EXPONENT ?
*/
char* decs[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
"2E-394", ".1E-2", "+.0", "-592.49E-07", "+32.84e-4",
".500001", "-.5000001",
"1234567890123456789012345678.91", /* 30 digits should fit
into decimal */
"1234567890123456789012345678.921", /* 31 digits should NOT
fit into decimal */
"not a number",
NULL};
static void
check_errno(void);
#define BUFSIZE 200
int
main(void)
{
decimal *dec, *din;
char buf[BUFSIZE];
long l;
int i, j, k, q, r, count = 0;
double dbl;
decimal **decarr = (decimal **) malloc(1);
ECPGdebug(1, stderr);
for (i = 0; decs[i]; i++)
{
dec = PGTYPESdecimal_new();
r = deccvasc(decs[i], strlen(decs[i]), dec);
if (r)
{
check_errno();
printf("dec[%d,0]: r: %d\n", i, r);
continue;
}
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
decarr[count++] = dec;
r = dectoasc(dec, buf, BUFSIZE-1, -1);
if (r < 0) check_errno();
printf("dec[%d,1]: r: %d, %s\n", i, r, buf);
r = dectoasc(dec, buf, BUFSIZE-1, 0);
if (r < 0) check_errno();
printf("dec[%d,2]: r: %d, %s\n", i, r, buf);
r = dectoasc(dec, buf, BUFSIZE-1, 1);
if (r < 0) check_errno();
printf("dec[%d,3]: r: %d, %s\n", i, r, buf);
r = dectoasc(dec, buf, BUFSIZE-1, 2);
if (r < 0) check_errno();
printf("dec[%d,4]: r: %d, %s\n", i, r, buf);
din = PGTYPESdecimal_new();
r = dectoasc(din, buf, BUFSIZE-1, 2);
if (!r < 0) check_errno();
printf("dec[%d,5]: r: %d, %s\n", i, r, buf);
r = dectolong(dec, &l);
if (r) check_errno();
printf("dec[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
if (r == 0)
{
r = deccvlong(l, din);
if (r) check_errno();
dectoasc(din, buf, BUFSIZE-1, 2);
q = deccmp(dec, din);
printf("dec[%d,7]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
}
r = dectoint(dec, &k);
if (r) check_errno();
printf("dec[%d,8]: %d (r: %d)\n", i, r?0:k, r);
if (r == 0)
{
r = deccvint(k, din);
if (r) check_errno();
dectoasc(din, buf, BUFSIZE-1, 2);
q = deccmp(dec, din);
printf("dec[%d,9]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
}
r = dectodbl(dec, &dbl);
if (r) check_errno();
printf("dec[%d,10]: %2.7f (r: %d)\n", i, r?0.0:dbl, r);
if (r == 0)
{
r = deccvdbl(dbl, din);
if (r)
{
check_errno();
printf("dec[%d,11(f)]: - (r: %d)\n", i, r);
}
else
{
dectoasc(din, buf, BUFSIZE-1, 2);
q = deccmp(dec, din);
printf("dec[%d,11]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
}
}
PGTYPESdecimal_free(din);
printf("\n");
}
/* add a NULL value */
dec = PGTYPESdecimal_new();
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
decarr[count++] = dec;
rsetnull(CDECIMALTYPE, (char *) decarr[count-1]);
printf("dec[%d]: %sNULL\n", count-1,
risnull(CDECIMALTYPE, (char *) decarr[count-1]) ? "" : "NOT ");
printf("dec[0]: %sNULL\n",
risnull(CDECIMALTYPE, (char *) decarr[0]) ? "" : "NOT ");
r = dectoasc(decarr[3], buf, -1, -1);
check_errno(); printf("dectoasc with len == -1: r: %d\n", r);
r = dectoasc(decarr[3], buf, 0, -1);
check_errno(); printf("dectoasc with len == 0: r: %d\n", r);
for (i = 0; i < count; i++)
{
for (j = 0; j < count; j++)
{
decimal a, s, m, d;
int c;
c = deccmp(decarr[i], decarr[j]);
printf("dec[c,%d,%d]: %d\n", i, j, c);
r = decadd(decarr[i], decarr[j], &a);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&a, buf, BUFSIZE-1, -1);
printf("dec[a,%d,%d]: %s\n", i, j, buf);
}
r = decsub(decarr[i], decarr[j], &s);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&s, buf, BUFSIZE-1, -1);
printf("dec[s,%d,%d]: %s\n", i, j, buf);
}
r = decmul(decarr[i], decarr[j], &m);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&m, buf, BUFSIZE-1, -1);
printf("dec[m,%d,%d]: %s\n", i, j, buf);
}
r = decdiv(decarr[i], decarr[j], &d);
if (r)
{
check_errno();
printf("r: %d\n", r);
}
else
{
dectoasc(&d, buf, BUFSIZE-1, -1);
printf("dec[d,%d,%d]: %s\n", i, j, buf);
}
}
}
for (i = 0; i < count; i++)
{
dectoasc(decarr[i], buf, BUFSIZE-1, -1);
printf("%d: %s\n", i, buf);
}
return (0);
}
static void
check_errno(void)
{
switch(errno)
{
case 0:
printf("(no errno set) - ");
break;
case ECPG_INFORMIX_NUM_OVERFLOW:
printf("(errno == ECPG_INFORMIX_NUM_OVERFLOW) - ");
break;
case ECPG_INFORMIX_NUM_UNDERFLOW:
printf("(errno == ECPG_INFORMIX_NUM_UNDERFLOW) - ");
break;
case PGTYPES_NUM_OVERFLOW:
printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
break;
case PGTYPES_NUM_UNDERFLOW:
printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
break;
case PGTYPES_NUM_BAD_NUMERIC:
printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
break;
case PGTYPES_NUM_DIVIDE_ZERO:
printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
break;
default:
printf("(unknown errno (%d))\n", errno);
printf("(libc: (%s)) ", strerror(errno));
break;
}
}
[NO_PID]: ECPGdebug: set to 1
[NO_PID]: sqlca: code: 0, state: 00000
/* Processed by ecpg (4.2.1) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* Needed for informix compatibility */
#include <ecpg_informix.h>
/* End of automatic include section */
#line 1 "rfmtdate.pgc"
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_error.h>
#include <sqltypes.h>
/*
* This file tests various forms of date-input/output by means of
* rfmtdate / rdefmtdate / rstrdate
*/
static void
check_return(int ret);
static void
date_test_strdate(char *input)
{
static int i;
date d;
int r, q;
char dbuf[11];
r = rstrdate(input, &d);
printf("r: %d ", r);
if (r == 0)
{
q = rdatestr(d, dbuf);
printf("q: %d ", q);
if (q == 0)
{
printf("date %d: %s\n", i++, dbuf);
}
else
printf("\n");
}
else
check_return(r);
}
static void
date_test_defmt(char *fmt, char *input)
{
static int i;
char dbuf[11];
date d;
int q, r;
r = rdefmtdate(&d, fmt, input);
printf("r: %d ", r);
if (r == 0)
{
q = rdatestr(d, dbuf);
printf("q: %d ", q);
if (q == 0)
{
printf("date %d: %s\n", i++, dbuf);
}
else
printf("\n");
}
else
check_return(r);
}
static void
date_test_fmt(date d, char *fmt)
{
static int i;
char buf[200];
int r;
r = rfmtdate(d, fmt, buf);
printf("r: %d ", r);
if (r != 0)
check_return(r);
else
printf("date: %d: %s\n", i++, buf);
}
int
main(void)
{
short mdy[3] = { 11, 23, 1959 };
char dbuf[11];
date d;
int r;
ECPGdebug(1, stderr);
r = rmdyjul(mdy, &d);
printf("create: r: %d\n", r);
if (r == 0)
{
rdatestr(d, dbuf);
printf("date: %s\n", dbuf);
}
/* input mask is mmddyyyy */
date_test_strdate("12031994");
date_test_strdate("9.6.1994");
date_test_fmt(d, "mmddyy");
date_test_fmt(d, "ddmmyy");
date_test_fmt(d, "yymmdd");
date_test_fmt(d, "yy/mm/dd");
date_test_fmt(d, "yy mm dd");
date_test_fmt(d, "yy.mm.dd");
date_test_fmt(d, ".mm.yyyy.dd.");
date_test_fmt(d, "mmm. dd, yyyy");
date_test_fmt(d, "mmm dd yyyy");
date_test_fmt(d, "yyyy dd mm");
date_test_fmt(d, "ddd, mmm. dd, yyyy");
date_test_fmt(d, "(ddd) mmm. dd, yyyy");
date_test_defmt("ddmmyy", "21-2-54");
date_test_defmt("ddmmyy", "2-12-54");
date_test_defmt("ddmmyy", "20111954");
date_test_defmt("ddmmyy", "130464");
date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
date_test_defmt("yy/mm/dd", "1954, February 3rd");
date_test_defmt("mmm.dd.yyyy", "041269");
date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
date_test_defmt("mmm.dd.yyyy", "9/14/58");
date_test_defmt("yy/mm/dd", "47/03/29");
date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
date_test_defmt("mmddyy", "Nov 14th, 1985");
/* ok: still contains dd mm yy */
date_test_defmt("bladdfoommbaryybong", "20/11/1954");
/* 1994 is not a leap year, it accepts the date as 01-03-1994 */
date_test_defmt("ddmmyy", "29-02-1994");
/* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
date_test_defmt("dmy", "20/11/1954");
/* ECPG_INFORMIX_ENOSHORTDATE */
date_test_defmt("ddmmyy", "21254");
date_test_defmt("ddmmyy", " 21254 ");
/* ECPG_INFORMIX_BAD_DAY */
date_test_defmt("ddmmyy", "320494");
/* ECPG_INFORMIX_BAD_MONTH */
date_test_defmt("mm-yyyy-dd", "13-1993-21");
/* ECPG_INFORMIX_BAD_YEAR */
/* ??? */
return (0);
}
static void
check_return(ret)
{
switch(ret)
{
case ECPG_INFORMIX_ENOTDMY:
printf("(ECPG_INFORMIX_ENOTDMY)");
break;
case ECPG_INFORMIX_ENOSHORTDATE:
printf("(ECPG_INFORMIX_ENOSHORTDATE)");
break;
case ECPG_INFORMIX_BAD_DAY:
printf("(ECPG_INFORMIX_BAD_DAY)");
break;
case ECPG_INFORMIX_BAD_MONTH:
printf("(ECPG_INFORMIX_BAD_MONTH)");
break;
default:
printf("(unknown ret: %d)", ret);
break;
}
printf("\n");
}
[NO_PID]: ECPGdebug: set to 1
[NO_PID]: sqlca: code: 0, state: 00000
create: r: 0
date: 1959-11-23
r: 0 q: 0 date 0: 1994-12-03
r: 0 q: 0 date 1: 1994-09-06
r: 0 date: 0: 112359
r: 0 date: 1: 231159
r: 0 date: 2: 591123
r: 0 date: 3: 59/11/23
r: 0 date: 4: 59 11 23
r: 0 date: 5: 59.11.23
r: 0 date: 6: .11.1959.23.
r: 0 date: 7: Nov. 23, 1959
r: 0 date: 8: Nov 23 1959
r: 0 date: 9: 1959 23 11
r: 0 date: 10: Mon, Nov. 23, 1959
r: 0 date: 11: (Mon) Nov. 23, 1959
r: 0 q: 0 date 0: 0054-02-21
r: 0 q: 0 date 1: 0054-12-02
r: 0 q: 0 date 2: 1954-11-20
r: 0 q: 0 date 3: 0064-04-13
r: 0 q: 0 date 4: 1967-03-12
r: 0 q: 0 date 5: 1954-02-03
r: 0 q: 0 date 6: 0069-04-12
r: 0 q: 0 date 7: 2525-07-28
r: 0 q: 0 date 8: 2525-07-28
r: 0 q: 0 date 9: 0058-09-14
r: 0 q: 0 date 10: 0047-03-29
r: 0 q: 0 date 11: 1975-10-28
r: 0 q: 0 date 12: 1985-11-14
r: 0 q: 0 date 13: 1954-11-20
r: 0 q: 0 date 14: 1994-03-01
r: -1212 (ECPG_INFORMIX_ENOTDMY)
r: -1209 (ECPG_INFORMIX_ENOSHORTDATE)
r: -1209 (ECPG_INFORMIX_ENOSHORTDATE)
r: -1206 (ECPG_INFORMIX_BAD_DAY)
r: -1205 (ECPG_INFORMIX_BAD_MONTH)
/* Processed by ecpg (4.2.1) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* Needed for informix compatibility */
#include <ecpg_informix.h>
/* End of automatic include section */
#line 1 "rfmtlong.pgc"
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_error.h>
#include <sqltypes.h>
/*
* This file tests various forms of long-input/output by means of
* rfmtlong
*/
static void
check_return(int ret);
static void
fmtlong(long lng, char *fmt)
{
static int i;
int r;
char buf[30];
r = rfmtlong(lng, fmt, buf);
printf("r: %d ", r);
if (r == 0)
{
printf("%d: %s (fmt was: %s)\n", i++, buf, fmt);
}
else
check_return(r);
}
int
main(void)
{
ECPGdebug(1, stderr);
fmtlong(-8494493, "-<<<<,<<<,<<<,<<<");
fmtlong(-8494493, "################");
fmtlong(-8494493, "+++$$$$$$$$$$$$$.##");
fmtlong(-8494493, "(&,&&&,&&&,&&&.)");
fmtlong(-8494493, "<<<<,<<<,<<<,<<<");
fmtlong(-8494493, "$************.**");
fmtlong(-8494493, "---$************.**");
fmtlong(-8494493, "+-+################");
fmtlong(-8494493, "abc: ################+-+");
fmtlong(-8494493, "+<<<<,<<<,<<<,<<<");
return (0);
}
static void
check_return(ret)
{
switch(ret)
{
case ECPG_INFORMIX_ENOTDMY:
printf("(ECPG_INFORMIX_ENOTDMY)");
break;
case ECPG_INFORMIX_ENOSHORTDATE:
printf("(ECPG_INFORMIX_ENOSHORTDATE)");
break;
case ECPG_INFORMIX_BAD_DAY:
printf("(ECPG_INFORMIX_BAD_DAY)");
break;
case ECPG_INFORMIX_BAD_MONTH:
printf("(ECPG_INFORMIX_BAD_MONTH)");
break;
default:
printf("(unknown ret: %d)", ret);
break;
}
printf("\n");
}
[NO_PID]: ECPGdebug: set to 1
[NO_PID]: sqlca: code: 0, state: 00000
r: 0 0: -8,494,493 (fmt was: -<<<<,<<<,<<<,<<<)
r: 0 1: 8494493 (fmt was: ################)
r: 0 2: - $8494493.00 (fmt was: +++$$$$$$$$$$$$$.##)
r: 0 3: (00008,494,493.) (fmt was: (&,&&&,&&&,&&&.))
r: 0 4: 8,494,493 (fmt was: <<<<,<<<,<<<,<<<)
r: 0 5: $*****8494493.00 (fmt was: $************.**)
r: 0 6: -$*****8494493.00 (fmt was: ---$************.**)
r: 0 7: - 8494493 (fmt was: +-+################)
r: 0 8: abc: 8494493 (fmt was: abc: ################+-+)
r: 0 9: -8,494,493 (fmt was: +<<<<,<<<,<<<,<<<)
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