Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rajeshnandwani1969 opened this issue Jul 24, 2023 · 5 comments
Open

Comments

@rajeshnandwani1969
Copy link

rajeshnandwani1969 commented Jul 24, 2023

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
Copy link

grvhack commented Sep 4, 2023

How to implement this in nuget package please guide

@rajeshnandwani1969
Copy link
Author

rajeshnandwani1969 commented Sep 4, 2023 via email

@grvhack
Copy link

grvhack commented Sep 4, 2023

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
Copy link
Member

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?

@rajeshnandwani1969
Copy link
Author

rajeshnandwani1969 commented Sep 8, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants