@@ -167,8 +167,9 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
167
167
BOOL changed ;
168
168
static char * tempBuf = NULL ;
169
169
static unsigned int tempBuflen = 0 ;
170
- const char * neutstr = value ;
171
- char midtemp [16 ];
170
+ const char * neut_str = value ;
171
+ char midtemp [2 ][32 ];
172
+ int mtemp_cnt = 0 ;
172
173
173
174
if (!tempBuf )
174
175
tempBuflen = 0 ;
@@ -265,27 +266,18 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
265
266
break ;
266
267
267
268
case PG_TYPE_BOOL :
268
- { /* change T/F to 1/0 */
269
- char * s = ( char * ) value ;
269
+ { /* change T/F to 1/0 */
270
+ char * s ;
270
271
271
- /* Aidan Mountford (aidan@oz.to) 1/08/2001:
272
-
273
- >> if (s[0] == 'T' || s[0] == 't') <<< This wont work...
274
-
275
- When MoveFirst is called twice on one set of tuples,
276
- this will have the effect of setting s[0] to 1 on the
277
- first pass, and s[0] on the second.
278
-
279
- This is bad ;)
280
-
281
- */
282
-
283
- strcpy (midtemp , value );
272
+ s = midtemp [mtemp_cnt ];
273
+ strcpy (s , (char * ) value );
284
274
if (s [0 ] == 'f' || s [0 ] == 'F' || s [0 ] == 'n' || s [0 ] == 'N' || s [0 ] == '0' )
285
- midtemp [0 ] = '0' ;
275
+ s [0 ] = '0' ;
286
276
else
287
- midtemp [0 ] = '1' ;
288
- neutstr = midtemp ;
277
+ s [0 ] = '1' ;
278
+ s [1 ] = '\0' ;
279
+ neut_str = midtemp [mtemp_cnt ];
280
+ mtemp_cnt ++ ;
289
281
290
282
}
291
283
break ;
@@ -406,7 +398,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
406
398
len = 1 ;
407
399
if (cbValueMax > len )
408
400
{
409
- strcpy (rgbValueBindRow , neutstr );
401
+ strcpy (rgbValueBindRow , neut_str );
410
402
mylog ("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n" , rgbValueBindRow );
411
403
}
412
404
break ;
@@ -426,7 +418,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
426
418
*/
427
419
case PG_TYPE_BYTEA :/* convert binary data to hex strings
428
420
* (i.e, 255 = "FF") */
429
- len = convert_pgbinary_to_char (value , rgbValueBindRow , cbValueMax );
421
+ len = convert_pgbinary_to_char (neut_str , rgbValueBindRow , cbValueMax );
430
422
431
423
/***** THIS IS NOT PROPERLY IMPLEMENTED *****/
432
424
break ;
@@ -437,7 +429,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
437
429
if (stmt -> current_col < 0 || stmt -> bindings [stmt -> current_col ].data_left < 0 )
438
430
{
439
431
/* convert linefeeds to carriage-return/linefeed */
440
- len = convert_linefeeds (value , NULL , 0 , & changed );
432
+ len = convert_linefeeds (neut_str , NULL , 0 , & changed );
441
433
if (cbValueMax == 0 ) /* just returns length info */
442
434
{
443
435
result = COPY_RESULT_TRUNCATED ;
@@ -450,7 +442,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
450
442
tempBuf = realloc (tempBuf , len + 1 );
451
443
tempBuflen = len + 1 ;
452
444
}
453
- convert_linefeeds (value , tempBuf , tempBuflen , & changed );
445
+ convert_linefeeds (neut_str , tempBuf , tempBuflen , & changed );
454
446
ptr = tempBuf ;
455
447
}
456
448
else
@@ -460,7 +452,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
460
452
free (tempBuf );
461
453
tempBuf = NULL ;
462
454
}
463
- ptr = value ;
455
+ ptr = neut_str ;
464
456
}
465
457
}
466
458
else
@@ -534,7 +526,15 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
534
526
* those.
535
527
*/
536
528
if (field_type == PG_TYPE_MONEY )
537
- convert_money (value );
529
+ {
530
+ if (convert_money (neut_str , midtemp [mtemp_cnt ], sizeof (midtemp [0 ])))
531
+ {
532
+ neut_str = midtemp [mtemp_cnt ];
533
+ mtemp_cnt ++ ;
534
+ }
535
+ else
536
+ return COPY_UNSUPPORTED_TYPE ;
537
+ }
538
538
539
539
switch (fCType )
540
540
{
@@ -590,94 +590,94 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
590
590
case SQL_C_BIT :
591
591
len = 1 ;
592
592
if (bind_size > 0 )
593
- * (UCHAR * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (neutstr );
593
+ * (UCHAR * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (neut_str );
594
594
else
595
- * ((UCHAR * ) rgbValue + bind_row ) = atoi (neutstr );
595
+ * ((UCHAR * ) rgbValue + bind_row ) = atoi (neut_str );
596
596
597
597
/*
598
598
* mylog("SQL_C_BIT: bind_row = %d val = %d, cb = %d, rgb=%d\n",
599
- * bind_row, atoi(neutstr ), cbValueMax, *((UCHAR *)rgbValue));
599
+ * bind_row, atoi(neut_str ), cbValueMax, *((UCHAR *)rgbValue));
600
600
*/
601
601
break ;
602
602
603
603
case SQL_C_STINYINT :
604
604
case SQL_C_TINYINT :
605
605
len = 1 ;
606
606
if (bind_size > 0 )
607
- * (SCHAR * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (value );
607
+ * (SCHAR * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (neut_str );
608
608
else
609
- * ((SCHAR * ) rgbValue + bind_row ) = atoi (value );
609
+ * ((SCHAR * ) rgbValue + bind_row ) = atoi (neut_str );
610
610
break ;
611
611
612
612
case SQL_C_UTINYINT :
613
613
len = 1 ;
614
614
if (bind_size > 0 )
615
- * (UCHAR * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (value );
615
+ * (UCHAR * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (neut_str );
616
616
else
617
- * ((UCHAR * ) rgbValue + bind_row ) = atoi (value );
617
+ * ((UCHAR * ) rgbValue + bind_row ) = atoi (neut_str );
618
618
break ;
619
619
620
620
case SQL_C_FLOAT :
621
621
len = 4 ;
622
622
if (bind_size > 0 )
623
- * (SFLOAT * ) ((char * ) rgbValue + (bind_row * bind_size )) = (float ) atof (value );
623
+ * (SFLOAT * ) ((char * ) rgbValue + (bind_row * bind_size )) = (float ) atof (neut_str );
624
624
else
625
- * ((SFLOAT * ) rgbValue + bind_row ) = (float ) atof (value );
625
+ * ((SFLOAT * ) rgbValue + bind_row ) = (float ) atof (neut_str );
626
626
break ;
627
627
628
628
case SQL_C_DOUBLE :
629
629
len = 8 ;
630
630
if (bind_size > 0 )
631
- * (SDOUBLE * ) ((char * ) rgbValue + (bind_row * bind_size )) = atof (value );
631
+ * (SDOUBLE * ) ((char * ) rgbValue + (bind_row * bind_size )) = atof (neut_str );
632
632
else
633
- * ((SDOUBLE * ) rgbValue + bind_row ) = atof (value );
633
+ * ((SDOUBLE * ) rgbValue + bind_row ) = atof (neut_str );
634
634
break ;
635
635
636
636
case SQL_C_SSHORT :
637
637
case SQL_C_SHORT :
638
638
len = 2 ;
639
639
if (bind_size > 0 )
640
- * (SWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (value );
640
+ * (SWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (neut_str );
641
641
else
642
- * ((SWORD * ) rgbValue + bind_row ) = atoi (value );
642
+ * ((SWORD * ) rgbValue + bind_row ) = atoi (neut_str );
643
643
break ;
644
644
645
645
case SQL_C_USHORT :
646
646
len = 2 ;
647
647
if (bind_size > 0 )
648
- * (UWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (value );
648
+ * (UWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atoi (neut_str );
649
649
else
650
- * ((UWORD * ) rgbValue + bind_row ) = atoi (value );
650
+ * ((UWORD * ) rgbValue + bind_row ) = atoi (neut_str );
651
651
break ;
652
652
653
653
case SQL_C_SLONG :
654
654
case SQL_C_LONG :
655
655
len = 4 ;
656
656
if (bind_size > 0 )
657
- * (SDWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atol (value );
657
+ * (SDWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atol (neut_str );
658
658
else
659
- * ((SDWORD * ) rgbValue + bind_row ) = atol (value );
659
+ * ((SDWORD * ) rgbValue + bind_row ) = atol (neut_str );
660
660
break ;
661
661
662
662
case SQL_C_ULONG :
663
663
len = 4 ;
664
664
if (bind_size > 0 )
665
- * (UDWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atol (value );
665
+ * (UDWORD * ) ((char * ) rgbValue + (bind_row * bind_size )) = atol (neut_str );
666
666
else
667
- * ((UDWORD * ) rgbValue + bind_row ) = atol (value );
667
+ * ((UDWORD * ) rgbValue + bind_row ) = atol (neut_str );
668
668
break ;
669
669
670
670
case SQL_C_BINARY :
671
671
672
672
/* truncate if necessary */
673
673
/* convert octal escapes to bytes */
674
674
675
- if (len = strlen (value ), len >= (int ) tempBuflen )
675
+ if (len = strlen (neut_str ), len >= (int ) tempBuflen )
676
676
{
677
677
tempBuf = realloc (tempBuf , len + 1 );
678
678
tempBuflen = len + 1 ;
679
679
}
680
- len = convert_from_pgbinary (value , tempBuf , tempBuflen );
680
+ len = convert_from_pgbinary (neut_str , tempBuf , tempBuflen );
681
681
ptr = tempBuf ;
682
682
683
683
if (stmt -> current_col >= 0 )
@@ -1811,23 +1811,27 @@ convert_escape(char *value)
1811
1811
}
1812
1812
1813
1813
1814
- char *
1815
- convert_money (char * s )
1814
+ BOOL
1815
+ convert_money (const char * s , char * sout , size_t soutmax )
1816
1816
{
1817
- size_t i = 0 ,
1818
- out = 0 ;
1817
+ size_t i = 0 , out = 0 ;
1819
1818
1820
- for (i = 0 ; i < strlen ( s ) ; i ++ )
1819
+ for (i = 0 ; s [ i ] ; i ++ )
1821
1820
{
1822
1821
if (s [i ] == '$' || s [i ] == ',' || s [i ] == ')' )
1823
1822
; /* skip these characters */
1824
- else if (s [i ] == '(' )
1825
- s [out ++ ] = '-' ;
1826
1823
else
1827
- s [out ++ ] = s [i ];
1824
+ {
1825
+ if (out + 1 >= soutmax )
1826
+ return FALSE; /* sout is too short */
1827
+ if (s [i ] == '(' )
1828
+ sout [out ++ ] = '-' ;
1829
+ else
1830
+ sout [out ++ ] = s [i ];
1831
+ }
1828
1832
}
1829
- s [out ] = '\0' ;
1830
- return s ;
1833
+ sout [out ] = '\0' ;
1834
+ return TRUE ;
1831
1835
}
1832
1836
1833
1837
@@ -2270,6 +2274,7 @@ convert_lo(StatementClass *stmt, const void *value, Int2 fCType, PTR rgbValue,
2270
2274
lo_lseek (conn , stmt -> lobj_fd , 0L , SEEK_SET );
2271
2275
}
2272
2276
}
2277
+ mylog ("lo data left = %d\n" , left );
2273
2278
2274
2279
if (left == 0 )
2275
2280
return COPY_NO_DATA_FOUND ;
0 commit comments