[Devel] Re: unixodbc trim padding result

Alex Gradinar Alex.Gradinar at cartel.md
Mon Mar 20 16:05:59 CET 2006


Hello,

unixodbc module uses this code
ret = SQLGetData(CON_RESULT(_h), i, SQL_C_CHAR,
        (CON_ROW(_h)[i-1]).s, STRN_LEN, &indicator);
to get data from odbc driver.
It means that this code converts from all SQL types to SQL_C_CHAR.
There are some ODBC drivers which pad SQL_C_CHAR data with spaces.
If the database doesn't pad some types (varchar) odbc driver can pad.

If the operser anywhere while comparing takes tail spaces as significant 
characters then my patch is wrong.
If nowhere then my patch can help while comparing by strcmp or strncmp because 
tail spaces won't take part in comparing.

My patch strip padding spaces from all column type.
It's possible to use ODBC function SQLDescribeCol to find out type of column and 
strip pad space only for SQL_CHAR type.

Best regards,
Alex Gradinar


> Hello,
>
> I am not sure that we have to integrate this in the database drivers, there 
> are other types in database which do not pad with spaces (varchar). Space is 
> not a forbidden character in all fields of SIP messages, although it may make 
> no sense to have spaces at the end of a text, it is not something that must 
> not exist.
>
> Does your patch strip only the padding chars, or it applies to all column 
> types?
>
> Cheers,
> Danie
>
>
> On 03/17/06 19:02, Alex Gradinar wrote:
>> Hi,
>>
>> I've write new patch for unixodbc module.
>>
>> Some of DBMS pads CHAR fields with spaces.
>> This patch removing tail padding chars from result strings.
>> If don't remove spaces the data in memory will contain padding chars and 
>> comparing won't be successed.
>> For example:
>> I use 'domain' module and if the string contains spaces the function 
>> is_from_local returns False.
>>
>> Best regards,
>> Alex Gradinar
> 




More information about the Devel mailing list