Update of /cvsroot/monetdb/sql/src/server
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15446/src/server

Modified Files:
        rel_dump.mx 
Log Message:
propagated changes of Friday Oct 30 2009
from the Nov2009 branch to the development trunk

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2009/10/30 - mr-meltdown: src/server/rel_dump.mx,1.41.2.1
  give PLAN a nice header, such that we can lift the interactive (mclient) 
restriction
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Index: rel_dump.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_dump.mx,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- rel_dump.mx 14 Sep 2009 18:21:35 -0000      1.41
+++ rel_dump.mx 30 Oct 2009 12:14:43 -0000      1.42
@@ -38,7 +38,7 @@
 #include "rel_dump.h"
 
 static void
-print_indent( mvc *sql, stream *fout, int depth)
+print_indent(mvc *sql, stream *fout, int depth)
 {
        char buf[LINESIZE+1];
        int i;
@@ -47,8 +47,8 @@
        depth *= TABSTOP;
        if (depth > LINESIZE)
                depth = LINESIZE;
-       for(i=0; i<depth; i++){
-               if ((i%TABSTOP) == 0)   
+       for (i = 0; i < depth; i++){
+               if ((i % TABSTOP) == 0) 
                        buf[i] = '|';
                else
                        buf[i] = ' ';
@@ -195,7 +195,7 @@
                stream_printf(fout, "(");
        else
                stream_printf(fout, " [ ");
-       for( en = exps->h; en; en = en->next ) 
+       for (en = exps->h; en; en = en->next) 
                exp_print(sql, fout, en->data, depth+1, (en->next!=NULL), 
alias);
        if (brackets)
                stream_printf(fout, ")");
@@ -462,8 +462,49 @@
 rel_print(mvc *sql, sql_rel *rel, int depth) 
 {
        list *refs = list_create(NULL);
-       rel_print_refs(sql, sql->scanner.ws, rel, depth, refs);
-       rel_print_(sql, sql->scanner.ws, rel, depth, refs);
-       stream_printf(sql->scanner.ws, "\n");
+       size_t pos;
+       size_t nl = 0;
+       size_t len = 0, lastpos = 0;
+       stream *fd = sql->scanner.ws;
+       stream *s;
+       buffer *b = buffer_create(16364); /* hopefully enough */
+       if (!b)
+               return; /* signal somehow? */
+       s = buffer_wastream(b, "SQL Plan");
+       if (!s) {
+               buffer_destroy(b);
+               return; /* signal somehow? */
+       }
+
+       rel_print_refs(sql, s, rel, depth, refs);
+       rel_print_(sql, s, rel, depth, refs);
+       stream_printf(s, "\n");
+
+       /* count the number of lines in the output, skip the leading \n */
+       for (pos = 1; pos < b->pos; pos++) {
+               if (b->buf[pos] == '\n') {
+                       nl++;
+                       if (len < pos - lastpos)
+                               len = pos - lastpos;
+                       lastpos = pos + 1;
+               }
+       }
+       b->buf[b->pos - 1] = '\0';  /* should always end with a \n, can 
overwrite */
+
+       /* craft a semi-professional header */
+       stream_printf(fd, "&1 0 %d 1 %d\n", /* type id rows columns tuples */
+                       nl, nl);
+       stream_printf(fd, "%% .plan # table_name\n");
+       stream_printf(fd, "%% rel # name\n");
+       stream_printf(fd, "%% clob # type\n");
+       stream_printf(fd, "%% " SZFMT " # length\n", len - 2 /* remove = and \n 
*/);
+
+       /* output the data */
+       stream_printf(fd, "%s\n", b->buf + 1 /* omit starting \n */);
+
+       stream_close(s);
+       stream_destroy(s);
+       buffer_destroy(b);
+
        list_destroy(refs);
 }


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to