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

Commit 5b32850

Browse files
author
Hiroshi Inoue
committed
Fix the bug about boolean type handling reported by
Kristis Markis.
1 parent a8385d0 commit 5b32850

File tree

3 files changed

+66
-58
lines changed

3 files changed

+66
-58
lines changed

src/interfaces/odbc/convert.c

+62-57
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
167167
BOOL changed;
168168
static char *tempBuf= NULL;
169169
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;
172173

173174
if (!tempBuf)
174175
tempBuflen = 0;
@@ -265,27 +266,18 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
265266
break;
266267

267268
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;
270271

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);
284274
if (s[0] == 'f' || s[0] == 'F' || s[0] == 'n' || s[0] == 'N' || s[0] == '0')
285-
midtemp[0] = '0';
275+
s[0] = '0';
286276
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++;
289281

290282
}
291283
break;
@@ -406,7 +398,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
406398
len = 1;
407399
if (cbValueMax > len)
408400
{
409-
strcpy(rgbValueBindRow, neutstr);
401+
strcpy(rgbValueBindRow, neut_str);
410402
mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow);
411403
}
412404
break;
@@ -426,7 +418,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
426418
*/
427419
case PG_TYPE_BYTEA:/* convert binary data to hex strings
428420
* (i.e, 255 = "FF") */
429-
len = convert_pgbinary_to_char(value, rgbValueBindRow, cbValueMax);
421+
len = convert_pgbinary_to_char(neut_str, rgbValueBindRow, cbValueMax);
430422

431423
/***** THIS IS NOT PROPERLY IMPLEMENTED *****/
432424
break;
@@ -437,7 +429,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
437429
if (stmt->current_col < 0 || stmt->bindings[stmt->current_col].data_left < 0)
438430
{
439431
/* convert linefeeds to carriage-return/linefeed */
440-
len = convert_linefeeds(value, NULL, 0, &changed);
432+
len = convert_linefeeds(neut_str, NULL, 0, &changed);
441433
if (cbValueMax == 0) /* just returns length info */
442434
{
443435
result = COPY_RESULT_TRUNCATED;
@@ -450,7 +442,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
450442
tempBuf = realloc(tempBuf, len + 1);
451443
tempBuflen = len + 1;
452444
}
453-
convert_linefeeds(value, tempBuf, tempBuflen, &changed);
445+
convert_linefeeds(neut_str, tempBuf, tempBuflen, &changed);
454446
ptr = tempBuf;
455447
}
456448
else
@@ -460,7 +452,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
460452
free(tempBuf);
461453
tempBuf = NULL;
462454
}
463-
ptr = value;
455+
ptr = neut_str;
464456
}
465457
}
466458
else
@@ -534,7 +526,15 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
534526
* those.
535527
*/
536528
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+
}
538538

539539
switch (fCType)
540540
{
@@ -590,94 +590,94 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
590590
case SQL_C_BIT:
591591
len = 1;
592592
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);
594594
else
595-
*((UCHAR *) rgbValue + bind_row) = atoi(neutstr);
595+
*((UCHAR *) rgbValue + bind_row) = atoi(neut_str);
596596

597597
/*
598598
* 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));
600600
*/
601601
break;
602602

603603
case SQL_C_STINYINT:
604604
case SQL_C_TINYINT:
605605
len = 1;
606606
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);
608608
else
609-
*((SCHAR *) rgbValue + bind_row) = atoi(value);
609+
*((SCHAR *) rgbValue + bind_row) = atoi(neut_str);
610610
break;
611611

612612
case SQL_C_UTINYINT:
613613
len = 1;
614614
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);
616616
else
617-
*((UCHAR *) rgbValue + bind_row) = atoi(value);
617+
*((UCHAR *) rgbValue + bind_row) = atoi(neut_str);
618618
break;
619619

620620
case SQL_C_FLOAT:
621621
len = 4;
622622
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);
624624
else
625-
*((SFLOAT *) rgbValue + bind_row) = (float) atof(value);
625+
*((SFLOAT *) rgbValue + bind_row) = (float) atof(neut_str);
626626
break;
627627

628628
case SQL_C_DOUBLE:
629629
len = 8;
630630
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);
632632
else
633-
*((SDOUBLE *) rgbValue + bind_row) = atof(value);
633+
*((SDOUBLE *) rgbValue + bind_row) = atof(neut_str);
634634
break;
635635

636636
case SQL_C_SSHORT:
637637
case SQL_C_SHORT:
638638
len = 2;
639639
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);
641641
else
642-
*((SWORD *) rgbValue + bind_row) = atoi(value);
642+
*((SWORD *) rgbValue + bind_row) = atoi(neut_str);
643643
break;
644644

645645
case SQL_C_USHORT:
646646
len = 2;
647647
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);
649649
else
650-
*((UWORD *) rgbValue + bind_row) = atoi(value);
650+
*((UWORD *) rgbValue + bind_row) = atoi(neut_str);
651651
break;
652652

653653
case SQL_C_SLONG:
654654
case SQL_C_LONG:
655655
len = 4;
656656
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);
658658
else
659-
*((SDWORD *) rgbValue + bind_row) = atol(value);
659+
*((SDWORD *) rgbValue + bind_row) = atol(neut_str);
660660
break;
661661

662662
case SQL_C_ULONG:
663663
len = 4;
664664
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);
666666
else
667-
*((UDWORD *) rgbValue + bind_row) = atol(value);
667+
*((UDWORD *) rgbValue + bind_row) = atol(neut_str);
668668
break;
669669

670670
case SQL_C_BINARY:
671671

672672
/* truncate if necessary */
673673
/* convert octal escapes to bytes */
674674

675-
if (len = strlen(value), len >= (int) tempBuflen)
675+
if (len = strlen(neut_str), len >= (int) tempBuflen)
676676
{
677677
tempBuf = realloc(tempBuf, len + 1);
678678
tempBuflen = len + 1;
679679
}
680-
len = convert_from_pgbinary(value, tempBuf, tempBuflen);
680+
len = convert_from_pgbinary(neut_str, tempBuf, tempBuflen);
681681
ptr = tempBuf;
682682

683683
if (stmt->current_col >= 0)
@@ -1811,23 +1811,27 @@ convert_escape(char *value)
18111811
}
18121812

18131813

1814-
char *
1815-
convert_money(char *s)
1814+
BOOL
1815+
convert_money(const char *s, char *sout, size_t soutmax)
18161816
{
1817-
size_t i = 0,
1818-
out = 0;
1817+
size_t i = 0, out = 0;
18191818

1820-
for (i = 0; i < strlen(s); i++)
1819+
for (i = 0; s[i]; i++)
18211820
{
18221821
if (s[i] == '$' || s[i] == ',' || s[i] == ')')
18231822
; /* skip these characters */
1824-
else if (s[i] == '(')
1825-
s[out++] = '-';
18261823
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+
}
18281832
}
1829-
s[out] = '\0';
1830-
return s;
1833+
sout[out] = '\0';
1834+
return TRUE;
18311835
}
18321836

18331837

@@ -2270,6 +2274,7 @@ convert_lo(StatementClass *stmt, const void *value, Int2 fCType, PTR rgbValue,
22702274
lo_lseek(conn, stmt->lobj_fd, 0L, SEEK_SET);
22712275
}
22722276
}
2277+
mylog("lo data left = %d\n", left);
22732278

22742279
if (left == 0)
22752280
return COPY_NO_DATA_FOUND;

src/interfaces/odbc/convert.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, I
3535

3636
int copy_statement_with_parameters(StatementClass *stmt);
3737
char *convert_escape(char *value);
38-
char *convert_money(char *s);
38+
BOOL convert_money(const char *s, char *sout, size_t soutmax);
3939
char parse_datetime(char *buf, SIMPLE_TIME *st);
4040
int convert_linefeeds(const char *s, char *dst, size_t max, BOOL *changed);
4141
int convert_special_chars(const char *si, char *dst, int used);

src/interfaces/odbc/drvconn.c

+3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ dconn_get_connect_attributes(const UCHAR FAR *connect_string, ConnInfo *ci)
355355
char *strtok_arg;
356356

357357
memset(ci, 0, sizeof(ConnInfo));
358+
#ifdef DRIVER_CURSOR_IMPLEMENT
359+
ci->updatable_cursors = 1;
360+
#endif /* DRIVER_CURSOR_IMPLEMENT */
358361

359362
our_connect_string = strdup(connect_string);
360363
strtok_arg = our_connect_string;

0 commit comments

Comments
 (0)