Re: ODBC Boolean handling - Mailing list pgsql-patches
From | Bruce Momjian |
---|---|
Subject | Re: ODBC Boolean handling |
Date | |
Msg-id | 200108021543.f72FhV727032@candle.pha.pa.us Whole thread Raw |
In response to | ODBC Boolean handling (Aidan Mountford <Aidan@oz.to>) |
List | pgsql-patches |
Here is the submitted patch so everyone can see it. > As Requested ... > > > > > -----Original Message----- > From: Bruce Momjian [mailto:pgman@candle.pha.pa.us] > Sent: Thursday, 2 August 2001 12:30 PM > To: Aidan Mountford > Cc: 'pgsql-patches@postgresql.org' > Subject: Re: [PATCHES] ODBC Boolean handling > > > > I have reviewed the current CVS code and it looks quite different from > the patch you submitted. Any chance of you downloading the snapshot and > sending a context diff, rather than an ordinary one. I could apply that > easily. > > > > > I had a few issues with boolean handling in ODBC driver. > > > > 1) When a row is retrieved, and then a SQL_FETCH_FIRST is issued, the > check > > in convert.c > > does not consider the fact that the value in the field has been altered to > > be a '1' if the > > backend handed it a 't'. The net result being that the first row on any > > subsequent queries > > has all it's boolean set to 0. > > > > 2) I had issues with some utilities that, when casting from string to > > boolean, and having > > the global 'bools as char' set, require that -1 = True, and 0 = false. > > > > The following patch fixes both of these issues.. > > > > Cheers for building a fantastic product > > > > Aidan -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 *** ./interfaces/odbc/convert.c Thu Aug 02 15:28:28 2001 --- ./interfaces/odbc/.#convert.c.1.44 Wed Aug 01 23:36:58 2001 *************** *** 292,301 **** { /* change T/F to 1/0 */ char *s = (char *) value; ! if (s[0] == 'T' || s[0] == 't') s[0] = '1'; else ! s[0] = '0'; } break; --- 292,314 ---- { /* change T/F to 1/0 */ char *s = (char *) value; ! /* Aidan Mountford (aidan@oz.to) 1/08/2001: ! ! >> if (s[0] == 'T' || s[0] == 't') <<< This wont work... ! ! When MoveFirst is called twice on one set of tuples, ! this will have the effect of setting s[0] to 1 on the ! first pass, and s[0] on the second. ! ! This is bad ;) ! ! */ ! ! if (s[0] == 'T' || s[0] == 't' || s[0] == '1') s[0] = '1'; else ! s[0] = '0'; ! } break; *************** *** 412,421 **** break; case PG_TYPE_BOOL: ! len = 1; if (cbValueMax > len) { ! strcpy(rgbValueBindRow, value); mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow); } break; --- 425,452 ---- break; case PG_TYPE_BOOL: ! if (cbValueMax > len) { ! /* Aidan Mountford (aidan@oz.to) 1/08/2001: ! ! When returning a CHAR datatype, return -1 ! instead of +1. ! ! That way if someone casts it back to a boolean ! again - it will work. ! */ ! if ( *(char *) value = '1') ! { ! strcpy(rgbValueBindRow, "-1"); ! len = 2; ! } ! else ! { ! strcpy(rgbValueBindRow, "0"); ! len = 1; ! } ! mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow); } break; *************** *** 1158,1164 **** --- 1189,1198 ---- } else { + + used = stmt->parameters[param_number].used ? *stmt->parameters[param_number].used : SQL_NTS; + buffer = stmt->parameters[param_number].buffer; }
pgsql-patches by date: