| 125 | char eolString[EOL_CHARS_MAX_LEN + 1] = "\n"; // LF by default |
| 126 | |
| 127 | static void parseFormatOpts(FunctionCallInfo fcinfo) { |
| 128 | Relation rel = EXTPROTOCOL_GET_RELATION(fcinfo); |
| 129 | ExtTableEntry *exttbl = GetExtTableEntry(rel->rd_id); |
| 130 | |
| 131 | const char fmtcode = exttbl->fmtcode; |
| 132 | const List *fmtopts = exttbl->options; |
| 133 | char *newline_str = NULL; |
| 134 | |
| 135 | // only TEXT and CSV have detailed options |
| 136 | if (fmttype_is_csv(fmtcode) || fmttype_is_text(fmtcode)) { |
| 137 | ListCell *option; |
| 138 | |
| 139 | foreach (option, fmtopts) { |
| 140 | DefElem *defel = (DefElem *)lfirst(option); |
| 141 | if (strcmp(defel->defname, "header") == 0) { |
| 142 | hasHeader = defGetBoolean(defel); |
| 143 | } else if (strcmp(defel->defname, "newline") == 0) { |
| 144 | newline_str = defGetString(defel); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // default end-of-line terminator |
| 149 | eolString[0] = '\n'; |
| 150 | eolString[1] = '\0'; |
| 151 | |
| 152 | if (newline_str != NULL) { |
| 153 | if (pg_strcasecmp(newline_str, "crlf") == 0) { |
| 154 | eolString[0] = '\r'; |
| 155 | eolString[1] = '\n'; |
| 156 | eolString[2] = '\0'; |
| 157 | } else if (pg_strcasecmp(newline_str, "cr") == 0) { |
| 158 | eolString[0] = '\r'; |
| 159 | eolString[1] = '\0'; |
| 160 | } else if (pg_strcasecmp(newline_str, "lf") == 0) { |
| 161 | eolString[0] = '\n'; |
| 162 | eolString[1] = '\0'; |
| 163 | } else { // should never come here |
| 164 | ereport(ERROR, errmsg("invalid value for NEWLINE (%s), " |
| 165 | "valid options are: 'LF', 'CRLF', 'CR'", |
| 166 | newline_str)); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | typedef struct gpcloudResHandle { |
| 173 | GPReader *gpreader; |
no test coverage detected