Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f590a5e

Browse files
author
Michael Meskes
committed
Applied patch by Dave Cramer to fix several bugs in compatlib.
1 parent d807bbe commit f590a5e

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

src/interfaces/ecpg/ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,10 @@ Sun Oct 26 10:47:05 CET 2003
16971697

16981698
- Fixed bug with indicators when storage for the
16991699
string is dynamically allocated
1700+
1701+
Thu Oct 30 11:12:37 CET 2003
1702+
1703+
- Applied patch by Dave Cramer fixing several bugs in compatlib.
17001704
- Set ecpg version to 3.0.0
17011705
- Set ecpg library to 4.0.0
17021706
- Set pgtypes library to 1.0.0

src/interfaces/ecpg/compatlib/informix.c

+71-14
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *
5959
*nres;
6060
int i;
6161

62-
if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2))
63-
{
62+
/* set it to null in case it errors out later */
6463
rsetnull(CDECIMALTYPE, (char *) result);
64+
if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2))
6565
return 0;
66-
}
6766

6867
if ((a1 = PGTYPESnumeric_new()) == NULL)
6968
return ECPG_INFORMIX_OUT_OF_MEMORY;
@@ -263,9 +262,13 @@ deccvlong(long lng, decimal * np)
263262
}
264263

265264
int
266-
decdiv(decimal * n1, decimal * n2, decimal * n3)
265+
decdiv(decimal * n1, decimal * n2, decimal * result)
267266
{
268-
int i = deccall3(n1, n2, n3, PGTYPESnumeric_div);
267+
268+
int i;
269+
270+
rsetnull(CDECIMALTYPE, (char *) result);
271+
i = deccall3(n1, n2, result, PGTYPESnumeric_div);
269272

270273
if (i != 0)
271274
switch (errno)
@@ -285,9 +288,12 @@ decdiv(decimal * n1, decimal * n2, decimal * n3)
285288
}
286289

287290
int
288-
decmul(decimal * n1, decimal * n2, decimal * n3)
291+
decmul(decimal * n1, decimal * n2, decimal * result)
289292
{
290-
int i = deccall3(n1, n2, n3, PGTYPESnumeric_mul);
293+
int i;
294+
295+
rsetnull(CDECIMALTYPE, (char *) result);
296+
i = deccall3(n1, n2, result, PGTYPESnumeric_mul);
291297

292298
if (i != 0)
293299
switch (errno)
@@ -304,9 +310,12 @@ decmul(decimal * n1, decimal * n2, decimal * n3)
304310
}
305311

306312
int
307-
decsub(decimal * n1, decimal * n2, decimal * n3)
313+
decsub(decimal * n1, decimal * n2, decimal * result)
308314
{
309-
int i = deccall3(n1, n2, n3, PGTYPESnumeric_sub);
315+
int i;
316+
317+
rsetnull(CDECIMALTYPE, (char *) result);
318+
i = deccall3(n1, n2, result, PGTYPESnumeric_sub);
310319

311320
if (i != 0)
312321
switch (errno)
@@ -341,7 +350,7 @@ dectoasc(decimal * np, char *cp, int len, int right)
341350
if (right >= 0)
342351
str = PGTYPESnumeric_to_asc(nres, right);
343352
else
344-
str = PGTYPESnumeric_to_asc(nres, -1);
353+
str = PGTYPESnumeric_to_asc(nres, nres->dscale);
345354

346355
PGTYPESnumeric_free(nres);
347356
if (!str)
@@ -431,10 +440,60 @@ rdatestr(date d, char *str)
431440
return 0;
432441
}
433442

443+
/*
444+
*
445+
* the input for this function is mmddyyyy and any non-numeric
446+
* character can be used as a separator
447+
*
448+
*/
434449
int
435450
rstrdate(char *str, date * d)
436451
{
437-
date dat = PGTYPESdate_from_asc(str, NULL);
452+
date dat;
453+
char strbuf[10];
454+
int i,j;
455+
456+
rsetnull(CDATETYPE, (char *)&dat);
457+
/*
458+
* we have to flip the year month date around for postgres
459+
* expects yyyymmdd
460+
*
461+
*/
462+
463+
for (i=0,j=0; i < 10; i++ )
464+
{
465+
/* ignore non-digits */
466+
if ( isdigit(str[i]) )
467+
{
468+
469+
/* j only increments if it is a digit */
470+
switch(j)
471+
{
472+
/* stick the month into the 4th, 5th position */
473+
case 0:
474+
case 1:
475+
strbuf[j+4] = str[i];
476+
break;
477+
/* stick the day into the 6th, and 7th position */
478+
case 2:
479+
case 3:
480+
strbuf[j+4] = str[i];
481+
break;
482+
483+
/* stick the year into the first 4 positions */
484+
case 4:
485+
case 5:
486+
case 6:
487+
case 7:
488+
strbuf[j-4] = str[i];
489+
break;
490+
491+
}
492+
j++;
493+
}
494+
}
495+
strbuf[8] = '\0';
496+
dat = PGTYPESdate_from_asc(strbuf, NULL);
438497

439498
if (errno && errno != PGTYPES_DATE_BAD_DATE)
440499
return ECPG_INFORMIX_BAD_DATE;
@@ -617,7 +676,7 @@ initValue(long lng_val)
617676
value.maxdigits = log10(2) * (8 * sizeof(long) - 1);
618677

619678
/* determine the number of digits */
620-
for (i = 1; i <= value.maxdigits; i++)
679+
for (i = 0; i <= value.maxdigits; i++)
621680
{
622681
if ((int) (value.val / pow(10, i)) != 0)
623682
value.digits = i + 1;
@@ -635,8 +694,6 @@ initValue(long lng_val)
635694
}
636695
/* safety-net */
637696
value.val_string[value.digits] = '\0';
638-
/* clean up */
639-
free(tmp);
640697
}
641698

642699
/* return the position oft the right-most dot in some string */

0 commit comments

Comments
 (0)