Storing non-printable chars in CHAR columns

Storing non-printable chars in CHAR columns

Post by Victor Ch » Fri, 02 Jul 1993 04:40:48



I have questions about storing non-printable chars in CHAR columns.

Because of the way our COBOL programs work, we need to store all
255 possible ASCII chars (some non-printable) in CHAR columns of
Informix Online 5.01 database under HP-UX 9.0.  For example,
programs may store COBOL HIGH-VALUE, LOW-VALUE, a data structure
(sometimes union) that contains chars and integers (binary data),
uninitialized fields.  Usually such CHAR columns we use aren't
very long (10-100 chars, a few 2000 chars), and a table may have
several such columns.

However, the Informix User's Guide and Reference manuals mention
that CHAR column should store only printable characters.  Storing
non-printable chars in CHAR column using 3GL with embedded SQLs
is possible, but not recommended.  TEXT/BLOB should be used.

Since the approach we are using is not recommended, we were
suggested to use BLOB to store such data.  However, from what I
heard, accessing a BLOB column requires similar logic as if
accessing a file in 3GL, which in COBOL requires a lot of
declaraction and logic.  Thus we did not take the BLOB approach.

So far we don't have any problem storing/retrieving non-printable
chars to/from CHAR columns using embedded SQLs in COBOL, except
we found that some Informix utilities which create ASCII file
version of the database are not working properly.  For example,
dbimport/dbexport, SQL UNLOAD/LOAD.  The problems are:

 - if there's a '\0' (null byte) in a CHAR column, anything after
   the null byte in the CHAR column and all the columns after
   that CHAR column will be truncated and not possible to be
   reloaded back to the database after the database is unloaded.
   (Perhaps the data were not unloaded to ASCII data files in
   the first place).

 - if there's a '\n' (newline) in a CHAR column, the record
   becomes two records when the ASCII data file is read.  And of
   course both records are incorrect in the database.

Now my questions are:

 - Is there anyone out there also storing non-printable chars in CHAR columns
   with work arounds?

 - Are there other non-printable chars that may cause problems?

 - Is it safe to store non-printable chars in CHAR columns?  i.e.

   - Is it likely future Informix Online versions continue to work
     with non-printable chars in CHAR columns (with limitations)?
     (or maybe other utilities will be enhanced to work perfectly)?

   - Does it break anything important (archive, logs, etc) other than
     dbimport/dbexport and SQL UNLOAD/LOAD?

 - Is it really that bad to access BLOB using embedded SQL in 3GL?

 - Other than TEXT/BLOB, what other options can we use to store
   non-printable chars as need by our application?

I appreciate any comments you have.

Thanks, Victor


 
 
 

Storing non-printable chars in CHAR columns

Post by Bob Beauli » Fri, 02 Jul 1993 07:24:49



>I have questions about storing non-printable chars in CHAR columns.

>Because of the way our COBOL programs work, we need to store all
>255 possible ASCII chars (some non-printable) in CHAR columns of

How about storing it as ascii values?

variable myvar char(10)

let myvar = '^L' would give you problems
but
let myvar = ascii 12 won't

Bob
--
 ---------------------------------------------------------------------------


|4640-B Meridian                           Telephone:  (408) 978-0808       |
|San Jose, CA  95124                       Facsimile:  (408) 978-7024       |
|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
|             Serving all your travel needs from start to finish            |
|                            $$$  Best Fares  $$$                           |
|                               Great Service                               |
|                     Specializing in International Travel                  |
 ---------------------------------------------------------------------------

 
 
 

Storing non-printable chars in CHAR columns

Post by Todd M. Sayl » Fri, 02 Jul 1993 09:28:26


Here at Bi-Tech Software, we also use COBOL and store binary (non-printable)
values in character fields.  We have found that, if the first character
of a field is NULL (low values), the column is considered NULL by Informix.
Note that a NULL column means a value which was not supplied, not just
a value of binary "0".  We also experienced problems using the import/export
utilities.  For this reason, we do not use the import/export utilities.

We consider it a limitation, but we work around it.  I'd be interested
to hear a response from one of you Informix support-types.  Will future
versions of Informix continue to behave this way?  Can the import/export
utilities be enhanced to handle binary data in character fields?

 
 
 

Storing non-printable chars in CHAR columns

Post by ihor.j.kin » Sat, 03 Jul 1993 05:14:20



> I have questions about storing non-printable chars in CHAR columns.

> However, the Informix User's Guide and Reference manuals mention
> that CHAR column should store only printable characters.  Storing
> non-printable chars in CHAR column using 3GL with embedded SQLs
> is possible, but not recommended.  TEXT/BLOB should be used.

We started using Informix well before TEXT/BLOB was available -
the interpretation of char hasn't changed, so we haven't
recoded our many lines of code.

Quote:

>  - if there's a '\0' (null byte) in a CHAR column, anything after
>    the null byte in the CHAR column and all the columns after
>    that CHAR column will be truncated and not possible to be
>    reloaded back to the database after the database is unloaded.
>    (Perhaps the data were not unloaded to ASCII data files in
>    the first place).

Correct, if you use the informix provided routines.  Unfortunately,
they seem to think of multi-char data as a C string, where the
null terminates the string.  
Quote:

>  - if there's a '\n' (newline) in a CHAR column, the record
>    becomes two records when the ASCII data file is read.  And of
>    course both records are incorrect in the database.

Also correct - and here's another GOTCH'YA -what if you have data
with that translates to the DBDELIMITER [usually '|' ].

Quote:> Now my questions are:

>  - Is there anyone out there also storing non-printable chars in CHAR columns
>    with work arounds?

>  - Are there other non-printable chars that may cause problems?

See above - also, a backslash will cause havoc if it's the last char.

Quote:

>  - Is it safe to store non-printable chars in CHAR columns?  i.e.

I believe it's safe, just as noted above, you can't use the
normal isql unload commands.

Note that it is possible to dump these fields, if you do the
following:
1). Dump the entire length of the field [normally, you can skip
trailing blanks].
2). ESCAPE with '\' the newline, the DBDELIMITER, and the backslash
        itself.

        Unfortunately, this requires some moderately sophisticated
dynamic ESQL coding to handle the general case for all files.

        If, however, you only need a tool for a specific file,
then it becomes a normal ESQL hack.

Once dumped with such a tool, data is re-loadable with
normal isql load commands.
Hope that helps.

Standard disclaimers apply,
Ihor Kinal
att!trumpet!ijk

 
 
 

Storing non-printable chars in CHAR columns

Post by Victor Ch » Sun, 04 Jul 1993 02:43:45



: Here at Bi-Tech Software, we also use COBOL and store binary (non-printable)
: values in character fields.  We have found that, if the first character
: of a field is NULL (low values), the column is considered NULL by Informix.
: Note that a NULL column means a value which was not supplied, not just
: a value of binary "0".  We also experienced problems using the import/export
: utilities.  For this reason, we do not use the import/export utilities.
:
: We consider it a limitation, but we work around it.  I'd be interested
: to hear a response from one of you Informix support-types.  Will future
: versions of Informix continue to behave this way?  Can the import/export
: utilities be enhanced to handle binary data in character fields?

Now if you need to store a binary value, whose first byte may be '\0'
(say COBOL low-value), in a CHAR column, how do you work-around
it so that Informix does not consider the value a database NULL
and be able to retrieve the column back with the original value?

Thanks, Victor


 
 
 

Storing non-printable chars in CHAR columns

Post by Todd M. Sayl » Sun, 04 Jul 1993 10:38:09


Quote:>Now if you need to store a binary value, whose first byte may be '\0'
>(say COBOL low-value), in a CHAR column, how do you work-around
>it so that Informix does not consider the value a database NULL
>and be able to retrieve the column back with the original value?

>Thanks, Victor

Well, we cheat.  We identify the columns ahead of time, then allocate one
extra byte for each column (the leading byte), which our low-level routines
always set to blank.  Of course, it helps to have all of our Informix I/O
going through a common set of routines.

Todd

 
 
 

Storing non-printable chars in CHAR columns

Post by M9 » Wed, 07 Jul 1993 00:57:54


How about storing the values uuencoded?
It's probably not as effective but should work in more general cases
as well.

Stefan

 
 
 

Storing non-printable chars in CHAR columns

Post by Steve Szal » Wed, 07 Jul 1993 11:10:51



>Now if you need to store a binary value, whose first byte may be '\0'
>(say COBOL low-value), in a CHAR column, how do you work-around
>it so that Informix does not consider the value a database NULL
>and be able to retrieve the column back with the original value?

>Thanks, Victor



Try escaping the '/0' with a '/1'. This will prevent Informix
from treating it as a null and preserve the collating sequence.

Cheers
--

 Co-Cam Computer Group,  Tel: +61 3 286 3456    
 Melbourne, Australia    Fax: +61 3 417 7857

 
 
 

Storing non-printable chars in CHAR columns

Post by Steve Szal » Thu, 08 Jul 1993 07:28:48



>Try escaping the '/0' with a '/1'. This will prevent Informix
>from treating it as a null and preserve the collating sequence.

Of course any value already starting with a '/1' must also be
escaped in the same way, in case it isn't obvious.
--

 Co-Cam Computer Group,  Tel: +61 3 286 3456    
 Melbourne, Australia    Fax: +61 3 417 7857
 
 
 

Storing non-printable chars in CHAR columns

Post by Alexander Koern » Wed, 14 Jul 1993 02:09:15



Quote:>Here at Bi-Tech Software, we also use COBOL and store binary (non-printable)
>values in character fields.  We have found that, if the first character
>of a field is NULL (low values), the column is considered NULL by Informix.
>Note that a NULL column means a value which was not supplied, not just
>a value of binary "0".  We also experienced problems using the import/export
>utilities.  For this reason, we do not use the import/export utilities.

>We consider it a limitation, but we work around it.  I'd be interested
>to hear a response from one of you Informix support-types.  Will future
>versions of Informix continue to behave this way?  Can the import/export
>utilities be enhanced to handle binary data in character fields?

Take a look at 6.0 as soon as 6.0 (OnLine & SE) will be out...

It doesn't solve the 'first byte not equal \0' problem but it adds
an option to the tools (load/unload, dbexport/dbimport, dbload) in order to
handle binary information correctly: Every unprintable character will
be represented as hex value escaped by a '\' (eg. \FF).

I hope that info helps...

I might demo it to interested people during the Informix Users Conference
in San Jose this week (I will be at the SAP booth in th exhibit hall).

Greetings,

Alexander
Consultant, Informix Software Germany

 
 
 

1. Searching Char(0) to Char(31) in NVARCHAR column

Hi All,
        I have "N" tables with NVARCHAR column datatype.
I need to find all the CHAR(0) to CHAR(31) characters in
each column and delete the data.
        One way to find this is to use WHERE clause with
LIKE '%CHAR(0)%' option. But this will be VERY slow and I
have to make check of 32 such characters. Is their any
other faster way to do the same.

Thx.

Sumit

2. Help needed : ServerSide Cursor and Optimistic Locking

3. Altering a CHAR(4) column CHAR(5) changing

4. Problem running SP5 for SQL6.5

5. Altering a CHAR(4) column CHAR(5) changing pg_attribute

6. Copying Field data to new field

7. Can't insert char into CHAR column

8. Is the use of Oracle and COM+ too massive a risk?

9. Putting non-ascii text into a char column

10. Non case censitive CHAR columns

11. Find non aplha/non numeric char

12. Paradox table, store nonprintable char into alpha field

13. How to convert from Char to int and discard rows that contain char