| 1739 | } |
| 1740 | |
| 1741 | static void |
| 1742 | csv_print_field(const char *str, FILE *fout, char sep) |
| 1743 | { |
| 1744 | /*---------------- |
| 1745 | * Enclose and escape field contents when one of these conditions is met: |
| 1746 | * - the field separator is found in the contents. |
| 1747 | * - the field contains a CR or LF. |
| 1748 | * - the field contains a double quote. |
| 1749 | * - the field is exactly "\.". |
| 1750 | * - the field separator is either "\" or ".". |
| 1751 | * The last two cases prevent producing a line that the server's COPY |
| 1752 | * command would interpret as an end-of-data marker. We only really |
| 1753 | * need to ensure that the complete line isn't exactly "\.", but for |
| 1754 | * simplicity we apply stronger restrictions here. |
| 1755 | *---------------- |
| 1756 | */ |
| 1757 | if (strchr(str, sep) != NULL || |
| 1758 | strcspn(str, "\r\n\"") != strlen(str) || |
| 1759 | strcmp(str, "\\.") == 0 || |
| 1760 | sep == '\\' || sep == '.') |
| 1761 | csv_escaped_print(str, fout); |
| 1762 | else |
| 1763 | fputs(str, fout); |
| 1764 | } |
| 1765 | |
| 1766 | static void |
| 1767 | print_csv_text(const printTableContent *cont, FILE *fout) |
no test coverage detected