Changeset: 944aaec29de6 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=944aaec29de6 Modified Files: Branch: default Log Message:
merged Dec2011 diffs (truncated from 462 to 300 lines): diff --git a/clients/ChangeLog.Dec2011 b/clients/ChangeLog.Dec2011 --- a/clients/ChangeLog.Dec2011 +++ b/clients/ChangeLog.Dec2011 @@ -1,6 +1,18 @@ # ChangeLog file for clients # This file is updated with Maddlog +* Wed Nov 9 2011 Sjoerd Mullender <sjo...@acm.org> +- mclient: The exact interpretation of the -i (--interactive) option + and the - filename argument have changed. The - filename argument + means read from standard input and no longer implies that no \ + interpretation is done on the input. Instead, \ interpretation is done + if either standard input is a terminal, or if the -i option is given. + The -i option no longer causes mclient to read from standard input. + It only means to do \ interpretation when reading from standard input. + Use the - filename argument to read from standard input. Note that + if no -s option is specified and no filename arguments are present, + mclient still reads from standard input. + * Wed Nov 2 2011 Sjoerd Mullender <sjo...@acm.org> - ODBC: Improved internal query for SQLSpecialColumns. Before, the query returned all columns taking part in a PRIMARY KEY *and* all columns diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1 --- a/clients/mapiclient/mclient.1 +++ b/clients/mapiclient/mclient.1 @@ -25,42 +25,34 @@ is the command-line interface to the Mon If the .BI \-\-statement= query .RB ( \-s -.IR query) -option is given, the query is executed as if it were given in a file. +.IR query ) +option is given, the query is executed. If any files are listed after the options, queries are read from the files and executed. -In either case, +The special filename +.B \- +refers to standard input. +Note that if there is both a +.B \-\-statement +option and filename arguments, the query given with +.B \-\-statement +is executed first. +If no +.B \-\-statement +option is given and no files are specified on the command line, .I mclient -exits after executing the query or queries, unless the +reads queries from standard input. +.PP +When reading from standard input, if standard input is a terminal +or if the .B \-\-interactive .RB ( \-i ) -option is given, in which case it continues reading queries from -standard input. -The file name -.B \- -refers to the standard input. -If -.I mclient -is started without any non-option arguments and without the -.B \-\-statement -.RB ( \-s ) -option, it reads queries from standard input. -.PP -When reading from standard input because no file arguments and no -.B \-\-statement -.RB ( \-s ) -option were passed on the command line, or because the -.B \-\-interactive -.RB ( \-i ) -option was given, +option is given, .I mclient interprets lines starting with .B \e (backslash) specially. See the section BACKSLASH COMMANDS below. -Note that this is not done when reading from standard input when the -.B \- -file argument is given. .PP Before .I mclient @@ -102,7 +94,9 @@ and to the argument of the .B \-\-statement .RB ( \-s ) option but not to the contents of files specified on the command line -or files specified using the +(except for +.B \- +which refers to standard input) or files specified using the .B \e< command (those must be encoded using UTF-8). The default encoding is taken from the locale. @@ -134,14 +128,19 @@ platforms where these are supported. \fB\-\-port=\fP\fIportnr\fP (\fB\-p\fP \fIportnr\fP) Specify the portnumber of the server (default: 50000). .TP -\fB\-\-interactive[=\fP\fItimermode\fP\fB]\fP (\fB\-i[\fP\fItimermode\fP\fB]\fP) -After executing the queries from the -.B \-\-statement -option (if given) and any file specified on the command -line, read queries from standard input. When this option is set, all -files are read line by line, like if it were entered on mclient's -console. The optional \fItimermode\fP argument controls the -format of the time reported for queries. The default mode is +\fB\-\-interactive\fP[\fB=\fP\fItimermode\fP] (\fB\-i\fP[\fItimermode\fP]) +When reading from standard input, interpret lines starting with +.B \e +(backslash) specially. +See the section BACKSLASH COMMANDS below. +This is the default if standard input is a terminal. +The optional \fItimermode\fP argument controls the +format of the time reported for queries. Note that no space is +allowed between +.B \-i +and +.IR timermode . +The default mode is \fBhuman\fP which adjusts the time precision to the measured value. The modes \fBms\fP, \fBs\fP and \fBm\fP force millisecond, second and minute + second precision respectively. @@ -174,11 +173,12 @@ is a pretty format which is meant for hu is a valid (in the XML sense) document. In addition to plain \fBcsv\fP, two other forms are possible. \fBcsv=\fP\fIc\fP uses \fIc\fP as column separator; \fBcsv+\fP\fIc\fP -uses \fIc\fP as column separator, but produces a single header line in +uses \fIc\fP as column separator and produces a single header line in addition to the data. .TP \fB\-\-echo\fP (\fB\-e\fP) Echo the query. +Note that using this option slows down processing. .TP \fB\-\-history\fP (\fB\-H\fP) Load and save the command line history (default off). @@ -188,9 +188,7 @@ Save client/server interaction in the sp .TP \fB\-\-statement=\fP\fIstmt\fP (\fB\-s\fP \fIstmt\fP) Execute the specified query. The query is run before any queries from -files specified on the command line are run, and before the -interactive session is started (if the \fB\-\-interactive\fP option is -given). +files specified on the command line are run. .TP \fB\--timezone\fP (\fB\-z\fP) Do not tell the client's timezone to the server. diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -150,7 +150,6 @@ static char *pager = 0; /* use external static int rowsperpage = 0; /* for SQL pagination */ static int pagewidth = -1; /* -1: take whatever is necessary, >0: limit */ static int pagewidthset = 0; /* whether the user set the width explicitly */ -static int interactive_stdin = 0; static int croppedfields = 0; /* whatever got cropped/truncated */ static char firstcrop = 1; /* first time we see cropping/truncation */ @@ -1554,7 +1553,7 @@ format_result(Mapi mid, MapiHdl hdl, cha } static int -doRequest(Mapi mid, const char *buf, int interactive) +doRequest(Mapi mid, const char *buf) { MapiHdl hdl; @@ -1569,7 +1568,7 @@ doRequest(Mapi mid, const char *buf, int format_result(mid, hdl, 0); - if (mapi_get_active(mid) == NULL || !interactive) + if (mapi_get_active(mid) == NULL) mapi_close_handle(hdl); return 0; } @@ -1604,9 +1603,8 @@ doRequest(Mapi mid, const char *buf, int } static int -doFile(Mapi mid, const char *file) +doFileBulk(Mapi mid, FILE *fp) { - FILE *fp; char *buf = NULL; size_t length; MapiHdl hdl = mapi_get_active(mid); @@ -1615,18 +1613,11 @@ doFile(Mapi mid, const char *file) int first = 1; /* first line processing */ size_t skip; - if (file == NULL || strcmp(file, "-") == 0) - fp = stdin; - else if ((fp = fopen(file, "r")) == NULL) { - fprintf(stderr, "%s: cannot open\n", file); - return 1; - } - bufsize = BLOCK - 1; buf = malloc(bufsize + 1); if (!buf) { fprintf(stderr, "cannot allocate memory for send buffer\n"); - if (file != NULL) + if (fp != stdin) fclose(fp); return 1; } @@ -1636,9 +1627,9 @@ doFile(Mapi mid, const char *file) timerPause(); if ((length = fread(buf, 1, bufsize, fp)) == 0) { /* end of file */ - if (file != NULL) { + if (fp != stdin) { fclose(fp); - file = NULL; + fp = NULL; } if (hdl == NULL) break; /* nothing more to do */ @@ -1706,7 +1697,7 @@ doFile(Mapi mid, const char *file) timerEnd(); free(buf); - if (file != NULL) + if (fp != NULL && fp != stdin) fclose(fp); mnstr_flush(toConsole); return errseen; @@ -1759,7 +1750,7 @@ enum hmyesno { UNKNOWN, YES, NO }; #define READBLOCK 8192 static int -doFileByLines(Mapi mid, FILE *fp, const char *prompt, const char useinserts) +doFile(Mapi mid, const char *file, int useinserts, int interactive, int save_history) { char *line = NULL; char *oldbuf = NULL, *buf = NULL; @@ -1769,6 +1760,30 @@ doFileByLines(Mapi mid, FILE *fp, const MapiMsg rc = MOK; int lineno = 1; enum hmyesno hassysfuncs = UNKNOWN; + FILE *fp; + char *prompt = NULL; + + (void) save_history; /* not used if no readline */ + if (strcmp(file, "-") == 0) { + fp = stdin; + if (isatty(fileno(fp))) { + interactive = 1; + setPrompt(); + prompt = promptbuf; +#ifdef HAVE_LIBREADLINE + init_readline(mid, language, save_history); +#endif + fromConsole = stdin; + } + } else if ((fp = fopen(file, "r")) == NULL) { + fprintf(stderr, "%s: cannot open\n", file); + return 1; + } + + if (!interactive && !echoquery) + return doFileBulk(mid, fp); + + hdl = mapi_get_active(mid); #ifdef HAVE_LIBREADLINE if (prompt == NULL) @@ -1858,7 +1873,8 @@ doFileByLines(Mapi mid, FILE *fp, const } } #ifdef HAVE_ICONV - if (line != NULL && encoding != NULL && cd_in != (iconv_t) -1) { + if (line != NULL && fp == stdin && + encoding != NULL && cd_in != (iconv_t) -1) { ICONV_CONST char *from = line; size_t fromlen = strlen(from); int factor = 4; @@ -1915,7 +1931,7 @@ doFileByLines(Mapi mid, FILE *fp, const if (line != NULL) continue; /* nothing more to do */ - return errseen; + goto bailout; } /* hdl != NULL, we should finish the current query */ @@ -1927,7 +1943,7 @@ doFileByLines(Mapi mid, FILE *fp, const special for files that were passed on the command line with -e in effect (see near the bottom of main()) */ - if (hdl == NULL && length > 0 && line[length - 1] == '\n' && fp == stdin) { + if (hdl == NULL && length > 0 && line[length - 1] == '\n' && interactive) { /* test for special commands */ if (mode != MAL) while (length > 0 && @@ -1947,7 +1963,7 @@ doFileByLines(Mapi mid, FILE *fp, const _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list