gpcloud: fix compiling issue due to pg_exttable removal
@@ -15,6 +15,7 @@ extern "C" {
#include "access/xact.h"
#include "catalog/pg_exttable.h"
#include "catalog/pg_proc.h"
+#include "commands/defrem.h"
#include "fmgr.h"
#include "funcapi.h"
#include "utils/array.h"
@@ -128,44 +129,41 @@ static void parseFormatOpts(FunctionCallInfo fcinfo) {
ExtTableEntry *exttbl = GetExtTableEntry(rel->rd_id);
const char fmtcode = exttbl->fmtcode;
- const char *fmtopts = exttbl->fmtopts;
+ const List *fmtopts = exttbl->options;
+ char *newline_str = NULL;
// only TEXT and CSV have detailed options
if (fmttype_is_csv(fmtcode) || fmttype_is_text(fmtcode)) {
- if (strstr(fmtopts, "header") != NULL) {
- hasHeader = true;
- } else {
- hasHeader = false;
+ ListCell *option;
+
+ foreach (option, fmtopts) {
+ DefElem *defel = (DefElem *)lfirst(option);
+ if (strcmp(defel->defname, "header") == 0) {
+ hasHeader = defGetBoolean(defel);
+ } else if (strcmp(defel->defname, "newline") == 0) {
+ newline_str = defGetString(defel);
+ }
}
- // detect end-of-line terminator
- const char *newline_str = strstr(fmtopts, "newline");
+ // default end-of-line terminator
eolString[0] = '\n';
eolString[1] = '\0';
if (newline_str != NULL) {
- const char *first = strchr(newline_str, '\'');
- const char *second = strchr(first + 1, '\'');
- size_t len = second - first - 1;
- char newline[EOL_STRING_MAX_LEN + 1];
- len = len > EOL_STRING_MAX_LEN ? EOL_STRING_MAX_LEN : len; // defensive line
-
- strncpy(newline, first + 1, len);
- newline[len] = '\0';
- if (pg_strcasecmp(newline, "crlf") == 0) {
+ if (pg_strcasecmp(newline_str, "crlf") == 0) {
eolString[0] = '\r';
eolString[1] = '\n';
eolString[2] = '\0';
- } else if (pg_strcasecmp(newline, "cr") == 0) {
+ } else if (pg_strcasecmp(newline_str, "cr") == 0) {
eolString[0] = '\r';
eolString[1] = '\0';
- } else if (pg_strcasecmp(newline, "lf") == 0) {
+ } else if (pg_strcasecmp(newline_str, "lf") == 0) {
eolString[0] = '\n';
eolString[1] = '\0';
} else { // should never come here
ereport(ERROR, (0, errmsg("invalid value for NEWLINE (%s), "
"valid options are: 'LF', 'CRLF', 'CR'",
- newline)));
+ newline_str)));
}
}
}
