Re: Character Field Length Function for Binary Data
Posted in 1998
On 8 May 98 at 18:17, Nils Myklebust wrote: > On Fri, 8 May 1998 10:56:30 +0200, "Billy Wheeler" > <billy@west.co.za> wrote: > > >On 8 May 98 at 8:00, David & Adina Samson wrote: > > > >> Does anybody know of a function which returns the length actually > >> used in a character field when we store binary data? For example, > >> if I've got a field defined as "char(20)" with a value of > >> "0xa73123", I want to a function to return a value of 3. The basic > >> "length" and "char_length" return the defined size of the field > >> (20). > > > >Sorry, I must just be exceedingly dumb > Yes :-) Thank you, Nils. > >, but how does a string of > >"0xa73123" have a length of 3? If I ask for the length of that string > >in 4GL, I get 8. > > This must be the hex representation of the binary data that he > actually put into the char(20) field. > The regular sql length function should return 4 for this data on the > condition that the rest of the field is filled with spaces. If this But I'm still confused: if you strip off the 0x, you still get a73123, which is 6, neither 3 nor 4. And if you convert that to a base 10 or lower number, the length of that could be even longer. What am I missing here? > data is inserted via a C program (using ESQL/C) and hex 0 is filled > into the rest of the field the length returned would allways be 20. > In Informix databases the length function counts the length by > stripping spaces from the end of the field. You have to be aware > that you can't put a hex 0 into the first position of a char field. > It will then be interpreted as NULL by SQL. There may also be > problems with hex 0 in other positions in some cases. Any other 8 > bit value in any position have allways worked fine. Yours in continuing dumbness... -- Ciao, Billy /Group Managing Director, The West Solutions Group: http://www.west.co.za \\ Drivel @ http://www.west.co.za/tasteless/ / \\ "Granted, Mr Wheeler's ideas are stupid and unreasonable, but he does own the company and I / think we should go along with him..." \\________________________________________________________________________________________________