@@ -59,11 +59,10 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *
59
59
* nres ;
60
60
int i ;
61
61
62
- if (risnull (CDECIMALTYPE , (char * ) arg1 ) || risnull (CDECIMALTYPE , (char * ) arg2 ))
63
- {
62
+ /* set it to null in case it errors out later */
64
63
rsetnull (CDECIMALTYPE , (char * ) result );
64
+ if (risnull (CDECIMALTYPE , (char * ) arg1 ) || risnull (CDECIMALTYPE , (char * ) arg2 ))
65
65
return 0 ;
66
- }
67
66
68
67
if ((a1 = PGTYPESnumeric_new ()) == NULL )
69
68
return ECPG_INFORMIX_OUT_OF_MEMORY ;
@@ -263,9 +262,13 @@ deccvlong(long lng, decimal * np)
263
262
}
264
263
265
264
int
266
- decdiv (decimal * n1 , decimal * n2 , decimal * n3 )
265
+ decdiv (decimal * n1 , decimal * n2 , decimal * result )
267
266
{
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 );
269
272
270
273
if (i != 0 )
271
274
switch (errno )
@@ -285,9 +288,12 @@ decdiv(decimal * n1, decimal * n2, decimal * n3)
285
288
}
286
289
287
290
int
288
- decmul (decimal * n1 , decimal * n2 , decimal * n3 )
291
+ decmul (decimal * n1 , decimal * n2 , decimal * result )
289
292
{
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 );
291
297
292
298
if (i != 0 )
293
299
switch (errno )
@@ -304,9 +310,12 @@ decmul(decimal * n1, decimal * n2, decimal * n3)
304
310
}
305
311
306
312
int
307
- decsub (decimal * n1 , decimal * n2 , decimal * n3 )
313
+ decsub (decimal * n1 , decimal * n2 , decimal * result )
308
314
{
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 );
310
319
311
320
if (i != 0 )
312
321
switch (errno )
@@ -341,7 +350,7 @@ dectoasc(decimal * np, char *cp, int len, int right)
341
350
if (right >= 0 )
342
351
str = PGTYPESnumeric_to_asc (nres , right );
343
352
else
344
- str = PGTYPESnumeric_to_asc (nres , -1 );
353
+ str = PGTYPESnumeric_to_asc (nres , nres -> dscale );
345
354
346
355
PGTYPESnumeric_free (nres );
347
356
if (!str )
@@ -431,10 +440,60 @@ rdatestr(date d, char *str)
431
440
return 0 ;
432
441
}
433
442
443
+ /*
444
+ *
445
+ * the input for this function is mmddyyyy and any non-numeric
446
+ * character can be used as a separator
447
+ *
448
+ */
434
449
int
435
450
rstrdate (char * str , date * d )
436
451
{
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 );
438
497
439
498
if (errno && errno != PGTYPES_DATE_BAD_DATE )
440
499
return ECPG_INFORMIX_BAD_DATE ;
@@ -617,7 +676,7 @@ initValue(long lng_val)
617
676
value .maxdigits = log10 (2 ) * (8 * sizeof (long ) - 1 );
618
677
619
678
/* determine the number of digits */
620
- for (i = 1 ; i <= value .maxdigits ; i ++ )
679
+ for (i = 0 ; i <= value .maxdigits ; i ++ )
621
680
{
622
681
if ((int ) (value .val / pow (10 , i )) != 0 )
623
682
value .digits = i + 1 ;
@@ -635,8 +694,6 @@ initValue(long lng_val)
635
694
}
636
695
/* safety-net */
637
696
value .val_string [value .digits ] = '\0' ;
638
- /* clean up */
639
- free (tmp );
640
697
}
641
698
642
699
/* return the position oft the right-most dot in some string */
0 commit comments