Update of /cvsroot/monetdb/MonetDB4/src/modules/plain
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12367/src/modules/plain

Modified Files:
        ascii_io.mx 
Log Message:
ascii_io now has a new field nullstr which is used for printing NULL
values and reading NULL values


Index: ascii_io.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/ascii_io.mx,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- ascii_io.mx 8 Feb 2008 22:36:06 -0000       1.21
+++ ascii_io.mx 17 Feb 2008 21:29:52 -0000      1.22
@@ -263,6 +263,7 @@
        frStr frstr;
        void *extra;
        void *data;
+       char *nullstr;
        int len;
        int nillen;
        bit ws;         /* if set we need to skip white space */
@@ -462,6 +463,7 @@
                fmt[p].ws = !(has_whitespace(fmt[p].sep));
                fmt[p].quote = '"';
                fmt[p].data = GDKmalloc(fmt[p].len);
+               fmt[p].nullstr = GDKstrdup("nil");
                if (ascii_io_debug)
                        stream_printf(GDKerr, "%s\n", fmt[p].name);
        }
@@ -498,6 +500,7 @@
                fmt[p].len = 0;
                fmt[p].nillen = 0;
                fmt[p].ws = 0;
+               fmt[p].nullstr = GDKstrdup("nil");
                BBPunfix(b->batCacheid);
        }
        return as->nr_attrs;
@@ -513,6 +516,8 @@
                if (fmt[p].c)
                        BBPunfix(fmt[p].c->batCacheid);
                GDKfree(fmt[p].sep);
+               if (fmt[p].nullstr)
+                       GDKfree(fmt[p].nullstr);
                if (fmt[p].data)
                        GDKfree(fmt[p].data);
        }
@@ -673,7 +678,16 @@
        }
        if (e < s)
                e = s;
-       adt = fmt->frstr(fmt->extra, fmt->adt, s, e, quote);
+       if ( s == NULL ||
+            (s == e && fmt->nullstr[0] == 0) ||
+            (!quote && strcasecmp(s,fmt->nullstr) == 0) ||
+            (quote && strncasecmp(s+1, fmt->nullstr, e-s-2) == 0)
+               ) {
+               adt = fmt->data;
+               memcpy(adt, ATOMnilptr(fmt->adt), fmt->nillen);
+       } else {
+               adt = fmt->frstr(fmt->extra, fmt->adt, s, e, quote);
+       }
        *end = bak;
 
        if (!adt) {
@@ -789,9 +803,15 @@
                if (f->c) {
                        p = (char *) bun_tail(f->c, id);
 
-                       l = f->tostr(f->extra, buf, len, f->adt, p);
-                       if (stream_write(fd, *buf, 1, l) != l)
-                               return ascii_io_error(fd);
+                       if (!p || ATOMcmp(f->adt, ATOMnilptr(f->adt), p) ==0) {
+                               l = strlen(f->nullstr);
+                               if (stream_write(fd, f->nullstr, 1, l) != l)
+                                       return ascii_io_error(fd);
+                       } else {
+                               l = f->tostr(f->extra, buf, len, f->adt, p);
+                               if (stream_write(fd, *buf, 1, l) != l)
+                                       return ascii_io_error(fd);
+                       }
                }
                if (stream_write(fd, f->sep, 1, f->seplen) != f->seplen)
                        return ascii_io_error(fd);
@@ -821,9 +841,16 @@
                        f = fmt + i;
                        if (f->c) {
                                p = BUNtail(f->ci, f->p);
-                               l = f->tostr(f->extra, buf, len, f->adt, p);
-                               if (stream_write(fd, *buf, 1, l) != l)
-                                       return ascii_io_error(fd);
+
+                               if (!p || ATOMcmp(f->adt, ATOMnilptr(f->adt), 
p) ==0) {
+                                       l = strlen(f->nullstr);
+                                       if (stream_write(fd, f->nullstr, 1, l) 
!= l)
+                                               return ascii_io_error(fd);
+                               } else {
+                                       l = f->tostr(f->extra, buf, len, 
f->adt, p);
+                                       if (stream_write(fd, *buf, 1, l) != l)
+                                               return ascii_io_error(fd);
+                               }
                        }
                        if (stream_write(fd, f->sep, 1, f->seplen) != f->seplen)
                                return ascii_io_error(fd);
@@ -842,10 +869,16 @@
 
                if (f->c) {
                        char *p = BUNtail(f->ci, f->p);
-                       int l = f->tostr(f->extra, buf, len, f->adt, p);
 
-                       if (stream_write(fd, *buf, 1, l) != l)
-                               return ascii_io_error(fd);
+                       if (!p || ATOMcmp(f->adt, ATOMnilptr(f->adt), p) ==0) {
+                               int l = strlen(f->nullstr);
+                               if (stream_write(fd, f->nullstr, 1, l) != l)
+                                       return ascii_io_error(fd);
+                       } else {
+                               int l = f->tostr(f->extra, buf, len, f->adt, p);
+                               if (stream_write(fd, *buf, 1, l) != l)
+                                       return ascii_io_error(fd);
+                       }
                        f->p++;
                }
                if (stream_write(fd, f->sep, 1, f->seplen) != f->seplen)
@@ -864,10 +897,17 @@
 
                if (f->c) {
                        char *p = BUNtail(f->ci, id + BUNfirst(f->c));
-                       int l = f->tostr(f->extra, buf, len, f->adt, p);
 
-                       if (stream_write(fd, *buf, 1, l) != l)
-                               return ascii_io_error(fd);
+                       if (!p || ATOMcmp(f->adt, ATOMnilptr(f->adt), p) ==0) {
+                               int l = strlen(f->nullstr);
+                               if (stream_write(fd, f->nullstr, 1, l) != l)
+                                       return ascii_io_error(fd);
+                       } else {
+                               int l = f->tostr(f->extra, buf, len, f->adt, p);
+
+                               if (stream_write(fd, *buf, 1, l) != l)
+                                       return ascii_io_error(fd);
+                       }
                }
                if (stream_write(fd, f->sep, 1, f->seplen) != f->seplen)
                        return ascii_io_error(fd);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to