Re: Null Characters in Strings, Version 9.3.1

Поиск
Список
Период
Сортировка
От Nils Gösche
Тема Re: Null Characters in Strings, Version 9.3.1
Дата
Msg-id 003b01cf2ce1$2e33bc80$8a9b3580$@de
обсуждение исходный текст
Ответ на Re: Null Characters in Strings, Version 9.3.1  (Heikki Linnakangas <hlinnakangas@vmware.com>)
Ответы Re: Null Characters in Strings, Version 9.3.1  (Heikki Linnakangas <hlinnakangas@vmware.com>)
Список pgsql-odbc
Heikki wrote:

> On 02/18/2014 07:06 PM, Nils Gösche wrote:
> > I wrote:
> >
> >> If I retrieve the value in a C# program using the ODBC driver, I get
> >> a string that has a null character at position 459, but a total
> >> length of 487!  The string up to position 458 is correct, but has
> now
> >> been extended with a null character and a few junk characters.
> >
> > Am I the only one thinking this is a serious bug?
>
> Maybe.. I don't have a C# environment to test this with; if you can
> write a small stand-alone C program to reproduce this and post it, I'll
> take a look.

Thanks! I have never written an ODBC program in C before. Wow, what a PITA... ;-).  I took a little example program
fromMicrosoft's site and adapted it.  The code is attached.  The essential point is at line 353: 

    if (wcslen(pThisBinding->wszBuffer) * sizeof(wchar_t) != pThisBinding->indPtr)
    {
        wprintf(L"2 * wcslen = %d, indPtr = %d\n", wcslen(pThisBinding->wszBuffer) * sizeof(wchar_t),
                pThisBinding->indPtr);
    }
    else
    {
        wprintf(pThisBinding->fChar ? DISPLAY_FORMAT_C:DISPLAY_FORMAT,
                PIPE,
                pThisBinding->cDisplaySize,
                pThisBinding->cDisplaySize,
                pThisBinding->wszBuffer);
    }

If I run this with version 9.2.1 of the driver (I am using 32 Bit here), it will go to the else clause and print the
valueof the text column. However, if I run this with the latest version, I get the following output: 

Connected!
Enter SQL commands, type (control)Z to exit
SQL COMMAND>| body
          |
2 * wcslen = 918, indPtr = 974
 |

SQL COMMAND>
Disconnected.

(indPtr is what we got in the last parameter of SQLBindCol)

The numeric values here are consistent with the result I am getting in the C# program: There is a null character at
characterindex 459, but the returned value is actually larger than that (974 bytes), resulting in a C# string with 487
characters!

Regards,
--
Nils Gösche
"Don't ask for whom the <CTRL-G> tolls."



Вложения

В списке pgsql-odbc по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Null Characters in Strings, Version 9.3.1
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Null Characters in Strings, Version 9.3.1