Changeset: 92fc6b9ce83d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/92fc6b9ce83d
Modified Files:
clients/mapiclient/mclient.1
clients/mapiclient/mclient.c
Branch: default
Log Message:
Add -fcsv-noquote formatting, useful for sys.dump_database.
diffs (89 lines):
diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1
--- a/clients/mapiclient/mclient.1
+++ b/clients/mapiclient/mclient.1
@@ -204,6 +204,7 @@ The possible values are
.BR expanded ,
.BR x ,
.BR csv ,
+.BR csv-noquote ,
.BR tab ,
.BR raw ,
.BR xml ,
@@ -212,6 +213,8 @@ and
.BR rowcount .
.B csv
is comma-separated values;
+.B csv-noquote
+is comma-separated values without escaping any quotes;
.B tab
is tab-separated values;
.B raw
@@ -235,6 +238,10 @@ and
is a variation on
.B trash
where only the number of affected rows is printed.
+Normal \fBcsv\fP and \fBtab\fP formatting will use double quotes
+around any fields that contain double quotes, white space or the
+separator. The \fBcsv-noquote\fP format will prevent that and dump
+the contents of the field without any interpretation.
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 and produces a single header line in
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -95,6 +95,7 @@ enum formatters {
static enum formatters formatter = NOformatter;
char *separator = NULL; /* column separator for CSV/TAB format
*/
bool csvheader = false; /* include header line in CSV format */
+bool noquote = false; /* don't use quotes in CSV format */
#define DEFWIDTH 80
@@ -942,7 +943,7 @@ CSVrenderer(MapiHdl hdl)
while (!mnstr_errnr(toConsole) && (fields = fetch_row(hdl)) != 0) {
for (i = 0; i < fields; i++) {
s = mapi_fetch_field(hdl, i);
- if (s != NULL && s[strcspn(s, specials)] != '\0') {
+ if (!noquote && s != NULL && s[strcspn(s, specials)] !=
'\0') {
mnstr_printf(toConsole, "%s\"",
i == 0 ? "" : separator);
while (*s) {
@@ -1647,6 +1648,7 @@ setFormatter(const char *s)
free(separator);
separator = NULL;
csvheader = false;
+ noquote = false;
#ifdef _TWO_DIGIT_EXPONENT
if (formatter == TESTformatter)
_set_output_format(0);
@@ -1673,6 +1675,29 @@ setFormatter(const char *s)
} else
separator = strdup(s + 4);
csvheader = true;
+ } else if (strcmp(s, "csv-noquote") == 0) {
+ noquote = true;
+ formatter = CSVformatter;
+ separator = strdup(",");
+ } else if (strncmp(s, "csv-noquote=", 4) == 0) {
+ noquote = true;
+ formatter = CSVformatter;
+ if (s[4] == '"') {
+ separator = strdup(s + 5);
+ if (separator[strlen(separator) - 1] == '"')
+ separator[strlen(separator) - 1] = 0;
+ } else
+ separator = strdup(s + 4);
+ } else if (strncmp(s, "csv-noquote+", 4) == 0) {
+ noquote = true;
+ formatter = CSVformatter;
+ if (s[4] == '"') {
+ separator = strdup(s + 5);
+ if (separator[strlen(separator) - 1] == '"')
+ separator[strlen(separator) - 1] = 0;
+ } else
+ separator = strdup(s + 4);
+ csvheader = true;
} else if (strcmp(s, "tab") == 0) {
formatter = CSVformatter;
separator = strdup("\t");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list