| 57 | //===--------------------------------------------------------------------===// |
| 58 | |
| 59 | void BaseCSVData::Finalize() { |
| 60 | auto delimiter_string = options.dialect_options.state_machine_options.delimiter.GetValue(); |
| 61 | |
| 62 | // quote and delimiter must not be substrings of each other |
| 63 | SubstringDetection(options.dialect_options.state_machine_options.quote.GetValue(), delimiter_string, "QUOTE", |
| 64 | "DELIMITER"); |
| 65 | |
| 66 | // escape and delimiter must not be substrings of each other |
| 67 | SubstringDetection(options.dialect_options.state_machine_options.escape.GetValue(), delimiter_string, "ESCAPE", |
| 68 | "DELIMITER"); |
| 69 | |
| 70 | // escape and quote must not be substrings of each other (but can be the same) |
| 71 | if (options.dialect_options.state_machine_options.quote != options.dialect_options.state_machine_options.escape) { |
| 72 | AreOptionsEqual(options.dialect_options.state_machine_options.quote.GetValue(), |
| 73 | options.dialect_options.state_machine_options.escape.GetValue(), "QUOTE", "ESCAPE"); |
| 74 | } |
| 75 | |
| 76 | // comment and quote must not be substrings of each other |
| 77 | AreOptionsEqual(options.dialect_options.state_machine_options.comment.GetValue(), |
| 78 | options.dialect_options.state_machine_options.quote.GetValue(), "COMMENT", "QUOTE"); |
| 79 | |
| 80 | // delimiter and comment must not be substrings of each other |
| 81 | SubstringDetection(options.dialect_options.state_machine_options.comment.GetValue(), delimiter_string, "COMMENT", |
| 82 | "DELIMITER"); |
| 83 | |
| 84 | // quote and delimiter must not be substrings of each other |
| 85 | SubstringDetection(options.thousands_separator, options.decimal_separator, "THOUSANDS", "DECIMAL_SEPARATOR"); |
| 86 | |
| 87 | // null string and delimiter must not be substrings of each other |
| 88 | for (auto &null_str : options.null_str) { |
| 89 | if (!null_str.empty()) { |
| 90 | StringDetection(options.dialect_options.state_machine_options.delimiter.GetValue(), null_str, "DELIMITER", |
| 91 | "NULL"); |
| 92 | |
| 93 | // quote and nullstr must not be substrings of each other |
| 94 | SubstringDetection(options.dialect_options.state_machine_options.quote.GetValue(), null_str, "QUOTE", |
| 95 | "NULL"); |
| 96 | |
| 97 | // Validate the nullstr against the escape character |
| 98 | const char escape = options.dialect_options.state_machine_options.escape.GetValue(); |
| 99 | // Allow nullstr to be escape character + some non-special character, e.g., "\N" (MySQL default). |
| 100 | // In this case, only unquoted occurrences of the nullstr will be recognized as null values. |
| 101 | if (options.dialect_options.state_machine_options.strict_mode == false && null_str.size() == 2 && |
| 102 | null_str[0] == escape && null_str[1] != '\0') { |
| 103 | continue; |
| 104 | } |
| 105 | SubstringDetection(escape, null_str, "ESCAPE", "NULL"); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (!options.prefix.empty() || !options.suffix.empty()) { |
| 110 | if (options.prefix.empty() || options.suffix.empty()) { |
| 111 | throw BinderException("COPY ... (FORMAT CSV) must have both PREFIX and SUFFIX, or none at all"); |
| 112 | } |
| 113 | if (options.dialect_options.header.GetValue()) { |
| 114 | throw BinderException("COPY ... (FORMAT CSV)'s HEADER cannot be combined with PREFIX/SUFFIX"); |
| 115 | } |
| 116 | } |
no test coverage detected