Re: Cleaning NUL bytes in TEXT column
Posted in 2010
On Tue, Feb 16, 2010 at 22:35, Jonathan Leffler <jleffler.iiug@gmail.com>wrote: > > On Tue, Feb 16, 2010 at 14:51, John Hardin <jhardin@epicor.com> wrote: > >> "Art Kagel" <art.kagel@gmail.com> wrote: >> > Read the data with an ESQL/C program, scrub it and update the row. >> >> Unfortunately we don't have a lot of C+ESQL expertise here. Everything we >> do >> is 4GL, Delphi and .NET. >> >> I was thinking of suggesting something similar in .NET to the devs but >> wanted to probe alternatives first. > > > Read the blobs with I4GL - located in memory. > Sanitize the memory - then write the blobs back again. > The sanitize step would still be C code, but roughly: > > #include "fglsys.h" > > int sanitize_text(int i) > { > loc_t *blob; > if (i != 1) > fgl_fatal(__FILE__, __LINE__, -1318); > poplocator(&blob); > if (blob->loc_loctype != LOCMEMORY) > return(0); > char *dst = blob->loc_buffer; > char *src = blob->loc_buffer; > char *end = src + blob->loc_bufsize; > char c; > while (src < end) > { > c = *src++; > if (c != '\\0') > *dst++ = c; > } > blob->loc_bufsize = dst - blob->loc_buffer; > return(0); > } > > That compiles, but is otherwise untested. Use at your own peril (but let me > know if there's anything grotesquely wrong with it, please). > I should observe that this compiles if your C compiler runs in a sufficiently C99-compliant mode to accept declarations part way through a block. If it doesn't, you have to move some of the declarations around to meet the older, stricter C89 requirements that variables are only declared at the top of a block. I should also move the declaration of 'c' into the loop: char c = *src++; -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/ "Blessed are we who can laugh at ourselves, for we shall never cease to be amused." NB: Please do not use this email for correspondence. I don't necessarily read it every week, even. Marie von Ebner-Eschenbach<http://www.brainyquote.com/quotes/authors/m/marie_von_ebnereschenbac.html> - "Even a stopped clock is right twice a day."