yellowfeather / DbfDataReader

DbfDataReader is a small fast .Net Core library for reading dBase, xBase, Clipper and FoxPro database files
MIT License
134 stars 61 forks source link

columns of "Char" type in dbf are trimmed (ltrim) of space. #201

Open rajeshnandwani1969 opened 1 year ago

rajeshnandwani1969 commented 1 year ago

Describe the bug columns of "Char" type in dbf are trimmed (ltrim) of space.

To Reproduce Steps to reproduce the behavior: take a dbf with a "C" data type and add value in that column as " Hi there" Read it using DbfTable dbfrecord you will get the value of that column as "Hi There". the string values are TRIMED.

Solution suggested: following is LINE NO 26 in DbfValueString.cs Value = value.Trim(NullChar,' '); Can change it to Value = value.Trim(NullChar,' '); if(string.IsNullOrWhiteSpace(Value) Value=null; // this is the behaviour when we use ODBC

grvhack commented 1 year ago

How to implement this in nuget package please guide

rajeshnandwani1969 commented 1 year ago

I think that authors can do. And May do in future updates. i pulled, modified and built the dll

On Mon, 4 Sep 2023 at 11:45 AM, grvhack @.***> wrote:

How to implement this is nuget package please guide

— Reply to this email directly, view it on GitHub https://github.com/yellowfeather/DbfDataReader/issues/201#issuecomment-1704672800, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSHRDDEQCMEUPHLC5GNR63XYVWYTANCNFSM6AAAAAA2VBYSCM . You are receiving this because you authored the thread.Message ID: @.***>

grvhack commented 1 year ago

Ok thnx replacing line 26 with: Value = value; if (string.IsNullOrWhiteSpace(Value)) { Value = null; } worked for me instead of Value = value.Trim(NullChar,' '); if(string.IsNullOrWhiteSpace(Value) Value=null; // this is the behaviour when we use ODBC

chrisrichards commented 1 year ago

Looks like there are two separate issues here:

Instead of replacing the current behavior, I'm thinking of adding a couple of options to DbfDataReaderOptions that control the string trimming (e.g. don't trim, trim start, trim end, trim both) and a separate option to control the returning of nulls for empty strings.

Would that work?

rajeshnandwani1969 commented 1 year ago

That would be great indeed! Thanks 🙏

On Fri, 8 Sep 2023 at 7:20 PM, Chris Richards @.***> wrote:

Looks like there are two separate issues here:

  • string values that have whites space at the beginning are being trimmed
  • if the string is whitespace only an empty string is returned rather than null

Instead of replacing the current behavior, I'm thinking of adding a couple of options to DbfDataReaderOptions that control the string trimming (e.g. don't trim, trim start, trim end, trim both) and a separate option to control the returning of nulls for empty strings.

Would that work?

— Reply to this email directly, view it on GitHub https://github.com/yellowfeather/DbfDataReader/issues/201#issuecomment-1711707749, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSHRDF7J45D45WEPSP452TXZMPDVANCNFSM6AAAAAA2VBYSCM . You are receiving this because you authored the thread.Message ID: @.***>