psqlodbc driver returning empty string
am 14.05.2009 15:44:40 von Zahid Khan
--0-956788077-1242308680=:19241
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi All,
I am facing a issue in psqlodbc driver, that when i try to get the value of=
same colum twice throug ADO,odbc driver sends the empty value on second it=
eration.e.g if we get 'value1' of=0Acolum 'a' and we try to fetch the same =
value through ADO in loop then=0Awe will get a empty string.
=0AAfter investigation ,I found that odbc driver is explicit returning=0ANO=
_DATA_FOUND on the column if that is already fetched .following is the code=
snippt in convert.c.
if (pgdc->data_left == 0)
=A0 =A0 {
=A0 =A0 =A0 if (pgdc->ttlbuf !=3D NULL)
=A0 =A0 =A0 {
=A0 =A0 =A0 =A0 free(pgdc->ttlbuf);
=A0 =A0 =A0 =A0 pgdc->ttlbuf =3D NULL;
=A0 =A0 =A0 =A0 pgdc->ttlbuflen =3D 0;
=A0 =A0 =A0 }
=A0 =A0 =A0 pgdc->data_left =3D -2; =A0 =A0 /*=
needed by ADO ? */
=A0 =A0 =A0 return COPY_NO_DATA_FOUND;
=A0 =A0 }
=A0We can fix this=0Aby not returning NO_DATA_FOUND on the column value whi=
ch is already=0Afetched .We can allow the driver to copy same value in clie=
nt buffer=0Aeven that was fetched already.I have written C code to test thi=
s=0Ascenario.Following is the code snippet which will help in more=0Aunders=
tanding.
=0A
=A0 rc=3DSQLFetch(*(*hStmt));=20
=A0 if(SQL_NO_DATA == rc)
=A0 {
=A0 =A0 printf("No Data...\r\n");
=A0 =A0 return 0;
=A0 }
=0A
=0ATill here lets say we have fetched the data on driver.
=0A
=0ANow following call of=A0 SQLGetData() will copy the value of colum '1' =
(second param) into the client buffer.which is good.
=A0 SQLGetData( *(*hStmt),1,SQL_C_CHAR,szData,sizeof(szD=
ata),&cbData);
=A0 printf("Date one call =3D [%s]\n",szData);
=20
=0A
=0ANow we have same following call of SQLGetData() and trying to get same=
=0Acolum('1') second time.But the driver is returing NO_DATA_FOUND in code=
=0Aand no string copied in buffer.
=0A
=A0 SQLGetData( *(*hStmt),1,SQL_C_CHAR,szData,sizeof(szD=
ata),&cbData);
=A0 printf("Data 2 call =3D [%s]\n",szData);
=0AI hope I am able to describe the whole scenario.We can fix this by not=
=0Areturning NO_DATA_FOUND. But I wanted to confirm that if NO_DATA_FOUND i=
s explicitly returned.
Thanks,
Zahid K.
=0A
--0-956788077-1242308680=:19241
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
|
top" style=3D"font: inherit;">
Hi All,
I am facing a issue in=
psqlodbc driver, that when i try to get the value of same colum twice thro=
ug ADO,odbc driver sends the empty value on second iteration.e.g if we get =
'value1' of=0Acolum 'a' and we try to fetch the same value through ADO in l=
oop then=0Awe will get a empty string.
=0AAfter investigation ,I fou=
nd that odbc driver is explicit returning=0ANO_DATA_FOUND on the column if =
that is already fetched .following is the code snippt in convert.c.
=
if (pgdc->data_left == 0)
{=
if (pgdc->t=
tlbuf !=3D NULL)
 =
; {
 =
; free(pgdc->ttlbuf);
&nb=
sp; pgdc->ttlbuf =3D NULL;
 =
; pgdc->t=
tlbuflen =3D 0;
=
}
pgdc->dat=
a_left =3D -2; /* needed by ADO ? */
r> return COPY_NO_D=
ATA_FOUND;
}
We can fix this=0Aby not returning NO_DA=
TA_FOUND on the column value which is already=0Afetched .We can allow the d=
river to copy same value in client buffer=0Aeven that was fetched already.I=
have written C code to test this=0Ascenario.Following is the code snippet =
which will help in more=0Aunderstanding.
=0A
=0A &n=
bsp; rc=3DSQLFetch(*(*hStmt));
=0A =
if(SQL_NO_DATA == rc)
=0A  =
; {
=0A pr=
intf("No Data...\r\n");
=0A &=
nbsp; return 0;
=0A } &n=
bsp;
=0A
=0ATill here lets say we have fetched the data on dri=
ver.
=0A
=0ANow following call of SQLGetData() will copy the v=
alue of colum '1' (second param) into the client buffer.which is good.
<=
br>=0A SQLGetData( *(*hStmt),1,SQL_C_C=
HAR,szData,sizeof(szData),&cbData);
=0A &nbs=
p; printf("Date one call =3D [%s]\n",szData);
=0A  =
;
=0A
=0ANow we have same following call of SQLGetData() and trying =
to get same=0Acolum('1') second time.But the driver is returing NO_DATA_FOU=
ND in code=0Aand no string copied in buffer.
=0A
=0A  =
; SQLGetData( *(*hStmt),1,SQL_C_CHAR,szData,sizeof(szDat=
a),&cbData);
=0A printf("Data 2=
call =3D [%s]\n",szData);
=0A
=
=0AI hope I am able to describe the whole scenario.We can fix this by not=
=0Areturning NO_DATA_FOUND. But I wanted to confirm that if NO_DATA_FOUND i=
s explicitly returned.
Thanks,
Zahid K.
=
--0-956788077-1242308680=:19241--
Re: psqlodbc driver returning empty string
am 14.05.2009 16:52:01 von Imad
I believe you are retrieving value of a varchar type column which is
variable length. According to MS documentation, SQLGetData returns
value of variable length field on multiple calls. That is why it is
designed like that. In your case all the value is returned in the
first call and second call has nothing to return. If you try with a
fixed length field like INT or DATE it should work on subsequent
calls.
This is where I get my reference from
http://msdn.microsoft.com/en-us/library/ms715441.aspx
--Imad
On Thu, May 14, 2009 at 11:44 PM, Zahid Khan wrote:
>
> Hi All,
>
>
> I am facing a issue in psqlodbc driver, that when i try to get the value =
of
> same colum twice throug ADO,odbc driver sends the empty value on second
> iteration.e.g if we get 'value1' of colum 'a' and we try to fetch the same
> value through ADO in loop then we will get a empty string.
>
> After investigation ,I found that odbc driver is explicit returning
> NO_DATA_FOUND on the column if that is already fetched .following is the
> code snippt in convert.c.
>
> if (pgdc->data_left == 0)
> =A0 =A0 {
> =A0 =A0 =A0 if (pgdc->ttlbuf !=3D NULL)
> =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 free(pgdc->ttlbuf);
> =A0 =A0 =A0 =A0 pgdc->ttlbuf =3D NULL;
> =A0 =A0 =A0 =A0 pgdc->ttlbuflen =3D 0;
> =A0 =A0 =A0 }
> =A0 =A0 =A0 pgdc->data_left =3D -2; =A0 =A0 =
/* needed by ADO ? */
> =A0 =A0 =A0 return COPY_NO_DATA_FOUND;
> =A0 =A0 }
>
> =A0We can fix this by not returning NO_DATA_FOUND on the column value whi=
ch is
> already fetched .We can allow the driver to copy same value in client buf=
fer
> even that was fetched already.I have written C code to test this
> scenario.Following is the code snippet which will help in more
> understanding.
>
> =A0 =A0 rc=3DSQLFetch(*(*hStmt));
> =A0 =A0 if(SQL_NO_DATA == rc)
> =A0 =A0 {
> =A0 =A0 =A0 printf("No Data...\r\n");
> =A0 =A0 =A0 return 0;
> =A0 =A0 }
>
> Till here lets say we have fetched the data on driver.
>
> Now following call of=A0 SQLGetData() will copy the value of colum '1' (s=
econd
> param) into the client buffer.which is good.
>
> =A0 =A0 SQLGetData( *(*hStmt),1,SQL_C_CHAR,szData,sizeof(szDa=
ta),&cbData);
> =A0 =A0 printf("Date one call =3D [%s]\n",szData);
>
>
> Now we have same following call of SQLGetData() and trying to get same
> colum('1') second time.But the driver is returing NO_DATA_FOUND in code a=
nd
> no string copied in buffer.
>
> =A0 =A0 SQLGetData( *(*hStmt),1,SQL_C_CHAR,szData,sizeof(szDa=
ta),&cbData);
> =A0 =A0 printf("Data 2 call =3D [%s]\n",szData);
>
> I hope I am able to describe the whole scenario.We can fix this by not
> returning NO_DATA_FOUND. But I wanted to confirm that if NO_DATA_FOUND is
> explicitly returned.
>
> Thanks,
> Zahid K.
>
>
--=20
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc