Update of /cvsroot/monetdb/clients/src/mapiclient
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv578
Modified Files:
Tag: Clients_1-20
MapiClient.mx
Log Message:
make XQuery work again after the last batch of changes (admittedly some time
ago):
- show only relevant help text
- make \t timer do send mapi_profile event
- make \f output formats work again (XQuery uses server-side formatting only)
- fix bug in timing (should start just before mapi_query_done(hdl), otherwise
you are measuring user think time).
- <> alone should not end a XQuery session
Index: MapiClient.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/MapiClient.mx,v
retrieving revision 1.88.2.2
retrieving revision 1.88.2.3
diff -u -d -r1.88.2.2 -r1.88.2.3
--- MapiClient.mx 22 Oct 2007 07:18:44 -0000 1.88.2.2
+++ MapiClient.mx 18 Dec 2007 16:07:05 -0000 1.88.2.3
@@ -247,6 +247,8 @@
}
}
+char *output = NULL; /* output format is a global variable */
+
static void
SQLsetSpecial(const char *command)
{
@@ -1114,16 +1116,20 @@
fprintf(toConsole, "\\h - show the readline history\n");
#endif
fprintf(toConsole, "\\t - toggle timer\n");
- fprintf(toConsole, "\\e - echo the query in sql formatting
mode\n");
if (mode == SQL) {
fprintf(toConsole, "\\D table- dumps the table, or the complete
database if none given.\n");
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");
}
- fprintf(toConsole, "\\f - format using a built-in renderer
{csv,tab,raw,sql,xml} \n");
- fprintf(toConsole, "\\w# - set maximal page width (-1=raw,0=no
limit, >0 max char)\n");
- fprintf(toConsole, "\\r# - set maximum rows per page (-1=raw)\n");
+ if (mode == XQUERY) {
+ fprintf(toConsole, "\\f - result format: dm or
xml[-noheader][-typed|-noroot|-root-FOOBAR] \n");
+ } else {
+ fprintf(toConsole, "\\e - echo the query in sql formatting
mode\n");
+ fprintf(toConsole, "\\f - format using a built-in renderer
{csv,tab,raw,sql,xml} \n");
+ fprintf(toConsole, "\\w# - set maximal page width
(-1=raw,0=no limit, >0 max char)\n");
+ fprintf(toConsole, "\\r# - set maximum rows per page
(-1=raw)\n ");
+ }
fprintf(toConsole, "\\L file - save client/server interaction\n");
fprintf(toConsole, "\\X - trace mclient code\n");
fprintf(toConsole, "\\q - terminate session\n");
@@ -1134,10 +1140,9 @@
{
char *line = NULL;
char *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)
@@ -1180,14 +1185,13 @@
line = fgets(buf, BUFSIZ, fp);
}
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') {
@@ -1213,6 +1217,8 @@
if (mark2)
free(mark2);
mark2 = strdup(line + 2);
+ if (mode == XQUERY)
+ mapi_profile(mid, mark != NULL);
continue;
case 'X':
/* toggle interaction trace */
@@ -1371,7 +1377,9 @@
;
if (*line == 0) {
fprintf(toConsole, "Current
formatter: ");
- switch (formatter) {
+ if (mode == XQUERY)
+ fprintf(toConsole,
"%s\n", output);
+ else switch (formatter) {
case RAWformatter:
fprintf(toConsole,
"raw\n");
break;
@@ -1391,7 +1399,9 @@
fprintf(toConsole,
"none\n");
break;
}
- } else
+ } else if (mode == XQUERY)
+ mapi_output(mid, line);
+ else
setFormatter(line);
continue;
default:
@@ -1402,37 +1412,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 */
}
@@ -1452,7 +1459,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;
@@ -1466,7 +1473,7 @@
fprintf(stderr, " -d database | --database=database database to
connect to\n");
fprintf(stderr, " -e | --echo echo the query\n");
- 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");
@@ -1506,7 +1513,6 @@
char *host = NULL;
char *command = NULL;
char *dbname = NULL;
- char *output = NULL;
char *input = NULL;
char *colname = NULL;
int trace = 0;
@@ -1597,6 +1603,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);
@@ -1719,6 +1726,7 @@
mapi_profile(mid, mark != NULL);
mapi_trace(mid, trace);
+
if (output) {
if (mode == XQUERY)
mapi_output(mid, output);
@@ -1726,7 +1734,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