Re: Character Field Length Function for Binary Data
Posted in 1998
On Mon, 11 May 1998 08:03:20 +0200, "Billy Wheeler" <billy@west.co.za> wrote: > >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? You'r missing knowledge of how one writes out hexadecimal data. Each two characters in the string represents one byte written in hexadecimal notation. Then you'll finally get at the three bytes. a7 is some 8 bit character - which depends on the character set used. 31 is the character 1 23 is a # sign if this was interpreted as character data using ASCII. The initial 0x is nothing but an indicator that what follows is written in this hexadecimal notation. And from your next post: No it's unlikely that this is a decimal value or any such thing. It's probably character data, but for an extended 8 bit character set. If you write almost anything but english you'r unfortunate to need more than the letters A - Z. We could all easily have managed with thos letters, but someone decided otherwise a long time ago, and it's somewhat hard to change that by now. >> 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..." >\\________________________________________________________________________________________________ Nils Myklebust NM Data AS Norway E-mail: Nils.Myklebust@nmdata.com FAQ at: http://www.iiug.org/techinfo/faq/faq_top.html (Now with ODBC info under "Third party products".)