Update of /cvsroot/monetdb/clients/src/mapiclient
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24610/src/mapiclient
Modified Files:
MapiClient.mx
Log Message:
propagated changes of Tuesday Dec 18 2007
from the Clients_1-20 branch to the development trunk
[mainly to have them (also) tested on Windows to night]
Note:
There were numerous conflicts.
I hope I resolved them correctly.
Please double-check!
Index: MapiClient.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/MapiClient.mx,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- MapiClient.mx 13 Dec 2007 18:35:21 -0000 1.97
+++ MapiClient.mx 18 Dec 2007 21:42:19 -0000 1.98
@@ -309,6 +309,8 @@
return mapi_split_line(hdl);
}
+char *output = NULL; /* output format is a global variable */
+
static void
SQLsetSpecial(const char *command)
{
@@ -1161,16 +1163,20 @@
stream_printf(toConsole, "\\h - show the readline history\n");
#endif
stream_printf(toConsole, "\\t - toggle timer\n");
- stream_printf(toConsole, "\\e - echo the query in sql formatting
mode\n");
if (mode == SQL) {
stream_printf(toConsole, "\\D table- dumps the table, or the
complete database if none given.\n");
stream_printf(toConsole, "\\d table- describe the table, or the
complete database if none given.\n");
stream_printf(toConsole, "\\A - enable auto commit\n");
stream_printf(toConsole, "\\a - disable auto commit\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");
+ if (mode == XQUERY) {
+ 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, "\\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");
+ }
stream_printf(toConsole, "\\L file - save client/server interaction\n");
stream_printf(toConsole, "\\X - trace mclient code\n");
stream_printf(toConsole, "\\q - terminate session\n");
@@ -1181,10 +1187,9 @@
{
char *line = NULL;
char *oldbuf = NULL, *buf = NULL;
- size_t length;
+ ssize_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)
@@ -1245,14 +1250,13 @@
}
#endif
if (line == NULL || (mode == XQUERY && line[0] == '<' &&
line[1] == '>')) {
- /* end of file */
- if (hdl == NULL)
- /* nothing more to do */
- return 0;
-
+ length = 0;
+ if (line)
+ length = -1;
+ else if (hdl == NULL)
+ return 0; /* EOF: nothing more to do */
/* 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') {
@@ -1278,6 +1282,8 @@
if (mark2)
free(mark2);
mark2 = strdup(line + 2);
+ if (mode == XQUERY)
+ mapi_profile(mid, mark != NULL);
continue;
case 'X':
/* toggle interaction trace */
@@ -1439,7 +1445,9 @@
;
if (*line == 0) {
stream_printf(toConsole,
"Current formatter: ");
- switch (formatter) {
+ if (mode == XQUERY)
+
stream_printf(toConsole, "%s\n", output);
+ else switch (formatter) {
case RAWformatter:
stream_printf(toConsole, "raw\n");
break;
@@ -1459,7 +1467,9 @@
stream_printf(toConsole, "none\n");
break;
}
- } else
+ } else if (mode == XQUERY)
+ mapi_output(mid, line);
+ else
setFormatter(line);
continue;
default:
@@ -1470,37 +1480,34 @@
}
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.
-
- 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 */
+ 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) {
hdl = NULL;
continue; /* done */
}
@@ -1520,7 +1527,7 @@
/* for XQuery, only exit when end-of-file and we
didn't send any data */
- } while (line != NULL || (mode == XQUERY && sent));
+ } while (length != 0);
/* reached on end of file */
assert(hdl == NULL);
return 0;
@@ -1537,7 +1544,7 @@
#ifdef HAVE_ICONV
fprintf(stderr, " -E charset | --encoding=charset specify encoding
(character set) of the terminal\n");
#endif
- fprintf(stderr, " -f kind | --format=kind specify output
format {dm,xml} for Xquery, or {csv,tab,raw,sql,xml}\n");
+ fprintf(stderr, " -f kind | --format=kind specify output
format {xml,typed,dm} for XQuery, or {csv,tab,raw,sql,xml}\n");
fprintf(stderr, " -H | --history load/save cmdline
history (default off)\n");
fprintf(stderr, " -h hostname | --host=hostname host to connect
to\n");
fprintf(stderr, " -i | --interactive read stdin after
command line args\n");
@@ -1577,7 +1584,6 @@
char *host = NULL;
char *command = NULL;
char *dbname = NULL;
- char *output = NULL;
char *input = NULL;
char *colname = NULL;
int trace = 0;
@@ -1689,6 +1695,7 @@
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);
@@ -1832,6 +1839,7 @@
mapi_profile(mid, mark != NULL);
mapi_trace(mid, trace);
+
if (output) {
if (mode == XQUERY)
mapi_output(mid, output);
@@ -1839,7 +1847,6 @@
setFormatter(output);
}
-
c = 0;
/* we're interactive if explicit or if no files and no -s option
-------------------------------------------------------------------------
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