Re: Character Field Length Function for Binary Data
Posted in 1998
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 :-) >, 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 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. 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".)