Update of /cvsroot/monetdb/clients/src/mapiclient
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv5189/src/mapiclient

Modified Files:
        MapiClient.mx 
Log Message:
propagated changes of Tuesday Dec 18 2007 - Wednesday Dec 19 2007
from the Clients_1-20 branch to the development trunk

I hope, I again resolved all conflicts correctly...



Index: MapiClient.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/MapiClient.mx,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- MapiClient.mx       18 Dec 2007 21:42:19 -0000      1.98
+++ MapiClient.mx       19 Dec 2007 19:13:27 -0000      1.99
@@ -181,6 +181,7 @@
        XMLformatter
 };
 static enum formatters formatter = NOformatter;
+char *output = NULL;           /* output format as string */
 
 #define DEFWIDTH 80
 
@@ -309,8 +310,6 @@
        return mapi_split_line(hdl);
 }
 
-char *output = NULL; /* output format is a global variable */
-
 static void
 SQLsetSpecial(const char *command)
 {
@@ -832,9 +831,14 @@
 }
 
 static void
-setFormatter(char *s)
+setFormatter(Mapi mid, char *s)
 {
-       if (strcmp(s, "sql") == 0)
+       if (mode == XQUERY) {
+               mapi_output(mid, s);
+               if (output != NULL)
+                       free(output);
+               output = strdup(s);
+       } else if (strcmp(s, "sql") == 0)
                formatter = TABLEformatter;
        else if (strcmp(s, "csv") == 0)
                formatter = CSVformatter;
@@ -1170,10 +1174,10 @@
                stream_printf(toConsole, "\\a      - disable auto commit\n");
        }
        if (mode == XQUERY) {
-               stream_printf(toConsole, "\\f      - result format: dm or 
xml[-noheader][-typed|-noroot|-root-FOOBAR] \n");
-        } else {
+               stream_printf(toConsole, "\\f      - result format: dm or 
xml[-noheader][-typed|-noroot|-root-FOOBAR]\n");
+       } else {
                stream_printf(toConsole, "\\e      - echo the query in sql 
formatting mode\n");
-               stream_printf(toConsole, "\\f      - format using a built-in 
renderer {csv,tab,raw,sql,xml} \n");
+               stream_printf(toConsole, "\\f      - format using a built-in 
renderer {csv,tab,raw,sql,xml}\n");
                stream_printf(toConsole, "\\w#     - set maximal page width 
(-1=raw,0=no limit, >0 max char)\n");
                stream_printf(toConsole, "\\r#     - set maximum rows per page 
(-1=raw)\n");
        }
@@ -1187,9 +1191,10 @@
 {
        char *line = NULL;
        char *oldbuf = NULL, *buf = NULL;
-       ssize_t length;
+       size_t length;
        MapiHdl hdl = mapi_get_active(mid);
        MapiMsg rc = MOK;
+       int sent = 0;           /* whether we sent any data to the server */
 
 #ifdef HAVE_LIBREADLINE
        if (prompt == NULL)
@@ -1250,13 +1255,17 @@
                }
 #endif
                if (line == NULL || (mode == XQUERY && line[0] == '<' && 
line[1] == '>')) {
-                       length = 0;
-                       if (line) 
-                                length = -1;
-                       else if (hdl == NULL) 
-                               return 0; /* EOF: nothing more to do */
+                       /* end of file */
+                       if (hdl == NULL) {
+                               if (line != NULL)
+                                       continue;
+                               /* nothing more to do */
+                               return 0;
+                       }
+
                        /* hdl != NULL, we should finish the current query */
                        line = NULL;
+                       length = 0;
                } else
                        length = strlen(line);
                if (hdl == NULL && length > 0 && line[length - 1] == '\n') {
@@ -1282,7 +1291,7 @@
                                        if (mark2)
                                                free(mark2);
                                        mark2 = strdup(line + 2);
-                                        if (mode == XQUERY)
+                                       if (mode == XQUERY)
                                                mapi_profile(mid, mark != NULL);
                                        continue;
                                case 'X':
@@ -1446,31 +1455,31 @@
                                        if (*line == 0) {
                                                stream_printf(toConsole, 
"Current formatter: ");
                                                if (mode == XQUERY)
-                                                       
stream_printf(toConsole, "%s\n", output);
-                                                else switch (formatter) {
-                                               case RAWformatter:
-                                                       
stream_printf(toConsole, "raw\n");
-                                                       break;
-                                               case TABLEformatter:
-                                                       
stream_printf(toConsole, "sql\n");
-                                                       break;
-                                               case CSVformatter:
-                                                       
stream_printf(toConsole, "csv\n");
-                                                       break;
-                                               case TABformatter:
-                                                       
stream_printf(toConsole, "tab\n");
-                                                       break;
-                                               case XMLformatter:
-                                                       
stream_printf(toConsole, "xml\n");
-                                                       break;
-                                               default:
-                                                       
stream_printf(toConsole, "none\n");
-                                                       break;
+                                                       
stream_printf(toConsole, "%s\n", output == NULL ? "dm" : output);
+                                               else {
+                                                       switch (formatter) {
+                                                       case RAWformatter:
+                                                               
stream_printf(toConsole, "raw\n");
+                                                               break;
+                                                       case TABLEformatter:
+                                                               
stream_printf(toConsole, "sql\n");
+                                                               break;
+                                                       case CSVformatter:
+                                                               
stream_printf(toConsole, "csv\n");
+                                                               break;
+                                                       case TABformatter:
+                                                               
stream_printf(toConsole, "tab\n");
+                                                               break;
+                                                       case XMLformatter:
+                                                               
stream_printf(toConsole, "xml\n");
+                                                               break;
+                                                       default:
+                                                               
stream_printf(toConsole, "none\n");
+                                                               break;
+                                                       }
                                                }
-                                       } else if (mode == XQUERY) 
-                                               mapi_output(mid, line);
-                                       else
-                                               setFormatter(line);
+                                       } else
+                                               setFormatter(mid, line);
                                        continue;
                                default:
                                        showCommands();
@@ -1480,34 +1489,37 @@
                }
 
                if (hdl == NULL) {
+                       timerStart();
                        hdl = mapi_query_prep(mid);
                        CHECK_RESULT(mid, hdl, buf, continue);
                }
                assert(hdl != NULL);
 
                if (length > 0) {
+                       sent = 1;
                        SQLsetSpecial(line);
                        mapi_query_part(hdl, line, length);
                        CHECK_RESULT(mid, hdl, buf, continue);
                }
 
-               if (mode == XQUERY && line)
-                       continue; /* XQuery always wants more data */
-
                /* If the server wants more but we're at the
                   end of file (line == NULL), notify the
                   server that we don't have anything more.
                   If the server still wants more (shouldn't
                   happen according to the protocol) we break
                   out of the loop (via the continue).  The
-                  assertion at the end will then go off.  
-                  */
-               timerStart();
-               if (mapi_query_done(hdl) == MMORE) {
-                       assert(mode != XQUERY); /* XQuery never sends MMORE */
-                       if (line != NULL) continue; /* get more data */
-                       timerStart();
-                        if (mapi_query_done(hdl) == MMORE) {
+                  assertion at the end will then go off.
+
+                  Note that XQuery is weird: we continue
+                  sending more until we reach end-of-file,
+                  and *then* we send the mapi_query_done.  To
+                  exit, you need to send an end-of-file
+                  again. */
+               if (mode == XQUERY || mapi_query_done(hdl) == MMORE) {
+                       if (line != NULL) {
+                               continue;       /* get more data */
+                       } else if (mapi_query_done(hdl) == MMORE) {
+                               assert(mode != XQUERY); /* XQuery never sends 
MMORE */
                                hdl = NULL;
                                continue;       /* done */
                        }
@@ -1527,7 +1539,7 @@
 
                /* for XQuery, only exit when end-of-file and we
                   didn't send any data */
-       } while (length != 0);
+       } while (line != NULL || (mode == XQUERY && sent));
        /* reached on end of file */
        assert(hdl == NULL);
        return 0;
@@ -1695,7 +1707,6 @@
                                   strcmp(optarg, "x") == 0) {
                                language = "xquery";
                                mode = XQUERY;
-                               if (!output) output = "dm";
                        } else {
                                fprintf(stderr, "language option needs to be 
one of sql, mil, mal, or xquery\n");
                                exit(-1);
@@ -1710,7 +1721,7 @@
                        passwd = optarg;        /* can be NULL */
                        break;
                case 'f':
-                       output = optarg;  /* output format */
+                       output = strdup(optarg); /* output format */
                        break;
                case 'I':
                        input = optarg;
@@ -1839,13 +1850,8 @@
 
        mapi_profile(mid, mark != NULL);
        mapi_trace(mid, trace);
-
-       if (output) {
-               if (mode == XQUERY)
-                       mapi_output(mid, output);
-               else
-                       setFormatter(output);
-       }
+       if (output)
+               setFormatter(mid, output);
 
        c = 0;
 


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to