Embarcadero / IB.NETDataProvider

InterBase database .NET Data Provider
Other
12 stars 7 forks source link

truncate char fields **request** #4

Closed GirusVirus closed 2 years ago

GirusVirus commented 3 years ago

Hi, Jeff, this is more of a request than an issue, I am used to being able to trim/truncate the char fields so that all strings are presented as if they were varchar. actually with other .Net Providers there are options in the connection string for this. for example IBProvider has "truncate_char = true" as default. This is convenient because I never want strings to have spaces. Is this something IB.NETDataProvider supports? I looked through the connection string documentation and did not see the feature. Unfortunately my existing DB has many char fields as well as varchar, but I would like to treat them all as varchar and not have to worry about trimming every field up on reading. Thanks,

jeffovercash commented 3 years ago

It is not something that the driver supports (although maybe at the field level I haven't looked). The VCL at the TField level has a property called FixedChar, if true (true for Char datatypes and false for VarChar by default) strings are represented always as fully padded to the DB size. When false for Char fields it is always right trimmed. So leading spaces are preserved and trailing removed. For VarChar trailing spaces remain as it was sent to the server with trailing spaces so those spaces are considered important, but no right space padding occurs - ex if a VarChar(10) is stored "abc " it would be returned as "abc ". If that were a char(10) field storing "abc " would return "abc " and you would want that to return "abc".

So would that be what you would want out of this global setting? For Chars only to right trim the string. VarChars are already right trimmed to basically the last real character stored (which can be a space).

GirusVirus commented 3 years ago

Jeff, yes, basically right trimmed strings that are type char. Not VarChar, those are fine. It tried changing my query to do a RTRIM() at the query level, but it slowed the query way down from normal 2 second fetch to about 9 second fetch. Not good. I then iterated through the set and did a .Trim() operation and that did the trick, only it is alot of code watching out for data coming in padded with blanks and having to do extra iterations to clean it up. I would appreciate it if this can be done with connection string property, or some other switch in the code. I am used to the truncate_char = true by default and false, when we need the padding. Thank you.

jeffovercash commented 3 years ago

Sorry this took so long I've been busy with IBX for Delphi 11.0 and with change view support in this driver.

I just finished it up (I think). Pretty simple, the connection string now has an attribute called truncate_char. If missing it is false and it acts as it does today. If there and =true then when you call GetString from the DBValue I do a TrimEnd() on it to trim off the trailing spaces. I did not take into consideration if this is a Char or VarChar type, is that important to you?

Outside of setting it in the connection string, IBConnection has a new property called TruncateChar. Setting it changes the connection string and connection options properties of the connection. This can only be set when the connection is closed. Unfortunately at the IBConnection layer, it needs to be stored in the Connection String/Options. That can only be changed when the connection is not active.

jeffovercash commented 3 years ago

Ok I re-read yours and you wanted only for Char types ... now it is just char types, VarChar is returned the same no matter the setting of truncate_char

GirusVirus commented 3 years ago

Jeff, thank you. I look forward to see the new setting soon. Any chance you will be supporting the latest version of Entity Framework... is that in the plans at some point?

jeffovercash commented 2 years ago

This is implemented in the 7.11.0 driver. EF6 is on the roadmap, but I do not have an ETA right now.