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

Modified Files:
        MapiClient.mx 
Log Message:


Index: MapiClient.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/MapiClient.mx,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- MapiClient.mx       16 Aug 2007 14:24:50 -0000      1.54
+++ MapiClient.mx       16 Aug 2007 18:49:45 -0000      1.55
@@ -228,7 +228,6 @@
 {
        t1 = gettime();
        if (mark &&
-               !debugMode() &&
                specials == 0){
                fprintf(toConsole, "%s % 7ld.%03ld msec %s\n", mark, (t1 - t0) 
/ 1000, (t1 - t0) % 1000, mark2 ? mark2 : "");
                fflush(toConsole);
@@ -282,7 +281,7 @@
                        fprintf(toConsole, "| ");
                        more = 0;
                        for (i = 0; i < fields; i++) {
-                               if (rest[i] == NULL)
+                               if (rest[i] == NULL || *rest[i]== 0)
                                        fprintf(toConsole, "%*s |", len[i], " 
");
                                else {
                                        /* break the string into pieces and 
left-adjust them in the column */
@@ -294,7 +293,7 @@
                                                        t = rest[i] + len[i];
                                                old = *t;
                                                *t = 0;
-                                               fprintf(toConsole, "%*s |", 
first && numeric[i] ? len[i] : -len[i], rest[i]);
+                                               fprintf(toConsole, "%*s |", 
(first && numeric[i]) ? len[i] : -len[i], rest[i]);
                                                *t = old;
                                                if (old) {
                                                        while (*t && (*t == ' ' 
|| *t == '\n'))
@@ -306,7 +305,7 @@
                                                        more++;
                                                }
                                        } else {
-                                               fprintf(toConsole, "%*s |", 
first && numeric[i] ? len[i] : -len[i], rest[i]);
+                                               fprintf(toConsole, "%*s |", 
(first && numeric[i]) ? len[i] : -len[i], rest[i]);
                                                rest[i] = 0;
                                        }
                                }
@@ -417,28 +416,31 @@
                        fprintf(toConsole, "%c+", sep);
                }
                fprintf(toConsole, "\n");
-               break;
-       default:
-               break;
        }
 }
 
 static void
-SQLheader(MapiHdl hdl, int *len, int fields)
-{
-       int i;
-       char **names = (char **) alloca(fields * sizeof(char *));
-       int *numeric = (int *) alloca(fields * sizeof(int));
-
+SQLqueryEcho(MapiHdl hdl){
        if (echoquery) {
                char *qry;
 
                qry = mapi_get_query(hdl);
                if (!interactive_stdin)
                        fputc('#', toConsole);
-               fprintf(toConsole, "%s", qry);
-               free(qry);
+               if( qry){
+                       fprintf(toConsole, "%s", qry);
+                       free(qry);
+               }
        }
+}
+static void
+SQLheader(MapiHdl hdl, int *len, int fields)
+{
+       int i;
+       char **names = (char **) alloca(fields * sizeof(char *));
+       int *numeric = (int *) alloca(fields * sizeof(int));
+
+       SQLqueryEcho(hdl);
        switch (formatter) {
        case TABLEformatter:
                SQLseparator(len, fields, '-');
@@ -450,9 +452,6 @@
                        SQLrow(len, numeric, names, fields,1);
                }
                SQLseparator(len, fields, '=');
-               break;
-       default:
-               break;
        }
 }
 
@@ -479,6 +478,20 @@
                specials=0;
        }
 }
+static void
+SQLpagemove(int *len, int fields, int *ps, int *silent){
+                       char buf[BUFSIZ];
+
+                       SQLseparator(len, fields, '-');
+                       fprintf(toConsole, "next page? (continue,quit,next)");
+                       fgets(buf, BUFSIZ, fromConsole);
+                       if (buf[0] == 'c')
+                               *ps = 0;
+                       if (buf[0] == 'q')
+                               *silent = 1;
+                       if (*silent == 0)
+                               SQLseparator(len, fields, '-');
+}
 
 static void
 SQLexplainRendering(MapiHdl hdl)
@@ -489,28 +502,20 @@
 
        if (mapi_result_error(hdl) != NULL) {
                mapi_explain_result(hdl, stderr);
+               return;
        }
 
+       SQLqueryEcho(hdl);
+
        len[0] = pagewidth-4; /* remove borders */
        numeric[0] = 0;
-       SQLheader(hdl, len, 1);
+       SQLseparator(len, 1, '-');
        while ((fields[0] = mapi_fetch_line(hdl)) != NULL) {
                if (silent)
                        continue;
                SQLrow(len, numeric, fields, 1,0);
-               if (ps && rows % ps == ps - 1 && rows != 
mapi_get_row_count(hdl) && fromConsole) {
-                       char buf[BUFSIZ];
-
-                       SQLseparator(len, 1, '-');
-                       fprintf(toConsole, "next page? (continue,quit,next)");
-                       fgets(buf, BUFSIZ, fromConsole);
-                       if (buf[0] == 'c')
-                               ps = 0;
-                       if (buf[0] == 'q')
-                               silent = 1;
-                       if (silent == 0)
-                               SQLseparator(len, 1, '-');
-               }
+               if (ps && rows % ps == ps - 1 && rows != 
mapi_get_row_count(hdl) && fromConsole) 
+                       SQLpagemove(len,1, &ps, &silent);
                rows++;
        }
        SQLseparator(len, 1, '-');
@@ -529,7 +534,9 @@
 
        if (mapi_result_error(hdl) != NULL) {
                mapi_explain_result(hdl, stderr);
+               return;
        }
+       SQLqueryEcho(hdl);
        len[0] = pagewidth-4; /* remove borders */
        numeric[0] = 0;
        numeric[1] = 0;
@@ -546,8 +553,7 @@
                if (s)
                        *s = 0;
 
-               if ( (s=strstr(fields[0], "usec  #")) ){
-                       s= strchr(s,'#');
+               if ( (s=strchr(fields[0],'#')) ){
                        *s=0;
                        fields[1]=s+1;
                        if (cols == 1){
@@ -568,17 +574,7 @@
                SQLrow(len, numeric, fields, cols,0);
                if (ps && rows % ps == ps - 1 && 
                        rows != mapi_get_row_count(hdl) && fromConsole) {
-                       char buf[BUFSIZ];
-
-                       SQLseparator(len, cols, '-');
-                       fprintf(toConsole, "next page? (continue,quit,next)");
-                       fgets(buf, BUFSIZ, fromConsole);
-                       if (buf[0] == 'c')
-                               ps = 0;
-                       if (buf[0] == 'q')
-                               silent = 1;
-                       if (silent == 0)
-                               SQLseparator(len, cols, '-');
+                       SQLpagemove(len, cols, &ps, &silent);
                }
                rows++;
        }
@@ -606,8 +602,11 @@
                        char *type;
 
                        len = (int *) alloca(sizeof(int) * fields);
+                       memset( (char*) len, 0, sizeof(int)* fields);
                        rest = (char **) alloca(sizeof(char *) * fields);
+                       memset( (char*) rest, 0, sizeof(char *) * fields);
                        numeric = (int *) alloca(sizeof(int) * fields);
+                       memset( (char*) numeric, 0, sizeof(int) * fields);
 
                        for (i = 0; i < fields; i++) {
                                len[i] = mapi_get_len(hdl, i);
@@ -878,9 +877,6 @@
                        if ((reply = mapi_result_error(hdl)) != NULL)
                                mapi_explain_result(hdl, stderr);
                        if (mapi_get_querytype(hdl) == Q_UPDATE) {
-                               if( mode== SQL && pagewidth >= 0)
-                                       fprintf(toConsole, "Rows affected 
%d\n", mapi_rows_affected(hdl));
-                               else
                                        fprintf(toConsole, "[ %d\t]\n", 
mapi_rows_affected(hdl));
                        } else {
                                while ((reply = mapi_fetch_line(hdl)) != NULL) {
@@ -927,6 +923,13 @@
                fprintf(toConsole, " pf:add-doc($uri as xs:string, 
$documentName as xs:string\n");
                fprintf(toConsole, "     [,$collectionName as xs:string 
[,$freePercentage as xs:integer]])\n");
                fprintf(toConsole, "\nSession commands:\n");
+               fprintf(toConsole, "<>       - send query to server (or %s)\n",
+#ifdef WIN32
+                       "CTRL-Z"
+#else
+                       "CTRL-D"
+#endif
+                   );
        }
 
        /* shared control options */
@@ -941,15 +944,6 @@
                fprintf(toConsole, "\\t      - toggle timer\n");
 
        switch (mode) {
-       case XQUERY:
-               fprintf(toConsole, "<>       - send query to server (or %s)\n",
-#ifdef WIN32
-                       "CTRL-Z"
-#else
-                       "CTRL-D"
-#endif
-                   );
-               break;
        case MAL:
                fprintf(toConsole, "\\?pat   - MAL function help. 
pat=[modnme[.fcnnme][(][)]] wildcard *\n");
                break;
@@ -962,15 +956,13 @@
                fprintf(toConsole, "\\d table- describe the table, or the 
complete database if none given.\n");
                fprintf(toConsole, "\\A      - enable auto commit\n");
                fprintf(toConsole, "\\a      - disable auto commit\n");
-       default:
-               fprintf(toConsole, "\\l      - line is sent immediately\n");
        }
                fprintf(toConsole, "\\L file - save client/server 
interaction\n");
                fprintf(toConsole, "\\X      - trace MapiClient code\n");
 }
 
 static int
-doFileByLines(Mapi mid, FILE *fp, const char *prompt, int linemode)
+doFileByLines(Mapi mid, FILE *fp, const char *prompt)
 {
        char *line = NULL;
        char *buf = NULL;
@@ -1023,10 +1015,10 @@
                }
                if (line == NULL || (mode == XQUERY && line[0] == '<' && 
line[1] == '>')) {
                        /* end of file */
-                       if (hdl == NULL) {
+                       if (hdl == NULL)
                                /* nothing more to do */
                                return 0;
-                       }
+
                        /* hdl != NULL, we should finish the current query */
                        line = NULL;
                        length = 0;
@@ -1035,8 +1027,7 @@
 
                if (length > 0 && 
                        mode != MAL &&
-                       (!linemode || 
-                        (hdl == NULL && length > 0 && line[length - 1] == 
'\n'))) {
+                        (hdl == NULL && length > 0 && line[length - 1] == 
'\n')) {
                        /* test for special commands */
                        while (length > 0 && (*line & ~0x7F) == 0 && 
isspace((int) *line)) {
                                line++;
@@ -1063,13 +1054,6 @@
                                        /* toggle interaction trace */
                                        mapi_trace(mid, !mapi_get_trace(mid));
                                        continue;
-                               case 'l':
-                                       if (mode == XQUERY)
-                                               break;
-                                       linemode = 1;
-                                       line = "";
-                                       length = 0;
-                                       continue;
                                case 'A':
                                        if (mode == XQUERY)
                                                break;
@@ -1195,7 +1179,7 @@
                                                continue;
                                        }
                                case '?':
-                                       if (!isspace((int) line[1]) && mode == 
MAL) {
+                                       if (!isspace((int) line[2]) && mode == 
MAL) {
                                                strcpy(line, line + 1);
                                                break;
                                        }
@@ -1285,131 +1269,129 @@
                        mapi_query_part(hdl, line, length);
                        CHECK_RESULT(mid, hdl, buf, continue);
                }
-               if (linemode || 
-                       (specials && debugMode()) ){
-                       assert(hdl != NULL);
-                       /* 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.
+               assert(hdl != NULL);
+               /* 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.
 
-                          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 */
-                               }
+                  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 */
                        }
-                       CHECK_RESULT(mid, hdl, buf, continue);
+               }
+               CHECK_RESULT(mid, hdl, buf, continue);
 
 #ifdef HAVE_POPEN
-                       if (pager) {
-                               pagerFD = popen(pager, "w");
-                               if (pagerFD == NULL)
-                                       fprintf(stderr, "Starting '%s' 
failed\n", pager);
-                       }
+               if (pager) {
+                       pagerFD = popen(pager, "w");
+                       if (pagerFD == NULL)
+                               fprintf(stderr, "Starting '%s' failed\n", 
pager);
+               }
 #endif
 
-                       do {
-                               char *reply;
+               do {
+                       char *reply;
 
-                               if (mapi_get_querytype(hdl) == Q_UPDATE) {
-                                       if( mode== SQL && pagewidth >= 0)
-                                               fprintf(toConsole, "Rows 
affected %d\n", mapi_rows_affected(hdl));
-                                       else
-                                               fprintf(toConsole, "[ %d\t]\n", 
mapi_rows_affected(hdl));
-                               } else if (mode == SQL) {
-                                       if (specials && debugMode())
+                       if (mapi_get_querytype(hdl) == Q_UPDATE) {
+                               if( mode== SQL && pagewidth >= 0)
+                                       fprintf(toConsole, "Rows affected 
%d\n", mapi_rows_affected(hdl));
+                               else
+                                       fprintf(toConsole, "[ %d\t]\n", 
mapi_rows_affected(hdl));
+                       } else if (mode == SQL) {
+                               if (specials && debugMode())
+                                       SQLdebugRendering(hdl);
+                               else if ((reply = mapi_result_error(hdl)) != 
NULL) {
+                                       if (pagewidth < 0)
+                                               goto nononsense;
+                                       fprintf(toConsole, "%s", reply);
+                               } else
+                                       switch (specials) {
+                                       case 1:
+                                               if (pagewidth < 0)
+                                                       goto nononsense;
+                                               SQLexplainRendering(hdl);
+                                               break;
+                                       case 2:
                                                SQLdebugRendering(hdl);
-                                       else if ((reply = 
mapi_result_error(hdl)) != NULL) {
+                                               break;
+                                       case 3:
                                                if (pagewidth < 0)
                                                        goto nononsense;
-                                               fprintf(toConsole, "%s", reply);
-                                       } else
-                                               switch (specials) {
-                                               case 1:
-                                                       if (pagewidth < 0)
-                                                               goto nononsense;
-                                                       
SQLexplainRendering(hdl);
-                                                       break;
-                                               case 2:
-                                                       SQLdebugRendering(hdl);
-                                                       break;
-                                               case 3:
-                                                       if (pagewidth < 0)
-                                                               goto nononsense;
-                                                       SQLtraceRenderer(hdl);
-                                                       break;
-                                               default:
-                                                       if (pagewidth < 0)
-                                                               goto nononsense;
-                                                       if (formatter == 
XMLformatter)
-                                                               
XMLrenderer(hdl);
-                                                       else if (formatter == 
RAWformatter)
-                                                               
RAWrenderer(hdl);
-                                                       else
-                                                               
SQLrenderer(hdl);
-                                               }
-                               } else {
-                 nononsense:
-                                       if ((reply = mapi_result_error(hdl)) != 
NULL) {
-                                               mapi_explain_result(hdl, 
stderr);
+                                               SQLtraceRenderer(hdl);
+                                               break;
+                                       default:
+                                               if (pagewidth < 0)
+                                                       goto nononsense;
+                                               if (formatter == XMLformatter)
+                                                       XMLrenderer(hdl);
+                                               else if (formatter == 
RAWformatter)
+                                                       RAWrenderer(hdl);
+                                               else
+                                                       SQLrenderer(hdl);
                                        }
-                                       if (mode == SQL && pagewidth >= 0 && 
(reply = mapi_fetch_line(hdl)) != NULL) {
-                                               if (*reply == '%') {
-                                                       if (formatter == 
XMLformatter)
-                                                               
XMLrenderer(hdl);
-                                                       else if (formatter == 
RAWformatter)
-                                                               
RAWrenderer(hdl);
-                                                       else
-                                                               
SQLrenderer(hdl);
-                                               } else
-                                                       fprintf(toConsole, 
"%s\n", reply);
+                       } else {
+         nononsense:
+                               if ((reply = mapi_result_error(hdl)) != NULL) {
+                                       mapi_explain_result(hdl, stderr);
+                               }
+                               if (mode == SQL && pagewidth >= 0 && (reply = 
mapi_fetch_line(hdl)) != NULL) {
+                                       if (*reply == '%') {
+                                               if (formatter == XMLformatter)
+                                                       XMLrenderer(hdl);
+                                               else if (formatter == 
RAWformatter)
+                                                       RAWrenderer(hdl);
+                                               else
+                                                       SQLrenderer(hdl);
+                                       } else
+                                               fprintf(toConsole, "%s\n", 
reply);
+                               }
+                               while ((reply = mapi_fetch_line(hdl)) != NULL 
&& *reply) {
+                                       if ((mode == XQUERY || mode == MAL) && 
*reply == '=')
+                                               reply++;
+                                       /* we know when the MAL debugger 
becomes active  and finishes*/
+                                       if (strncmp(reply, "mdb>#", 5) == 0)
+                                               sprintf(promptbuf,"mdb>");
+                                       if (strncmp(reply, "mdb>#EOD", 7) == 0){
+                                               setPrompt();
+                                               continue;
                                        }
-                                       while ((reply = mapi_fetch_line(hdl)) 
!= NULL && *reply) {
-                                               if ((mode == XQUERY || mode == 
MAL) && *reply == '=')
-                                                       reply++;
-                                               /* we know when the MAL 
debugger becomes active  and finishes*/
-                                               if (strncmp(reply, "mdb>#", 5) 
== 0)
-                                                       
sprintf(promptbuf,"mdb>");
-                                               if (strncmp(reply, "mdb>#EOD", 
7) == 0){
-                                                       setPrompt();
-                                                       continue;
-                                               }
 #ifdef HAVE_POPEN
-                                               if (pagerFD)
-                                                       fprintf(pagerFD, 
"%s\n", reply);
-                                               else
+                                       if (pagerFD)
+                                               fprintf(pagerFD, "%s\n", reply);
+                                       else
 #endif
-                                                       fprintf(toConsole, 
"%s\n", reply);
-                                       }
+                                               fprintf(toConsole, "%s\n", 
reply);
                                }
-                       } while ((rc = mapi_needmore(hdl)) == MOK && (rc = 
mapi_next_result(hdl)) == 1);
-                       if (rc == MMORE && (line != NULL || 
mapi_query_done(hdl) != MOK))
-                               continue;       /* get more data */
+                       }
+               } while ((rc = mapi_needmore(hdl)) == MOK && (rc = 
mapi_next_result(hdl)) == 1);
+               if (rc == MMORE && (line != NULL || mapi_query_done(hdl) != 
MOK))
+                       continue;       /* get more data */
 
-                       CHECK_RESULT(mid, hdl, buf, continue);
+               CHECK_RESULT(mid, hdl, buf, continue);
 
 #ifdef HAVE_POPEN
-                       if (pagerFD) {
-                               pclose(pagerFD);
-                               pagerFD = NULL;
-                       }
-#endif
-                       timerEnd();
-                       mapi_close_handle(hdl);
-                       hdl = NULL;
+               if (pagerFD) {
+                       pclose(pagerFD);
+                       pagerFD = NULL;
                }
+#endif
+               timerEnd();
+               mapi_close_handle(hdl);
+               hdl = NULL;
+       
                /* for XQuery, only exit when end-of-file and we
                   didn't send any data */
        } while (line != NULL || (mode == XQUERY && sent));
@@ -1473,7 +1455,6 @@
        int trace = 0;
        int guest = 1;
        int dump = 0;
-       int linemode = 1;
        int c = 0;
        Mapi mid;
        int save_history = 0;
@@ -1773,7 +1754,7 @@
                        mapi_stream_into(mid, input, colname);
                        c = doFile(mid, NULL);
                } else
-                       c = doFileByLines(mid, stdin, prompt, linemode);
+                       c = doFileByLines(mid, stdin, prompt);
 
 #ifdef HAVE_LIBREADLINE
                if (interactive_stdin) {


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to