![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Another followup, this time with the comment done right. |
#2
| |||
| |||
|
|
On Sun, 2006-01-29 at 17:03 -0800, David Fetter wrote: Another followup, this time with the comment done right. + /* Disallow the forbidden_delimiter strings */ + if (strcspn(cstate->delim, BADCHARS) != 1) + elog(ERROR, "COPY delimiter cannot be %#02x", + *cstate->delim); + The comment is still wrong: referencing "forbidden_delimiter" makes it sound like there is something named forbidden_delimiter, but there is not (at least in the patch as submitted). The patch should also use ereport rather than elog, because this error message might reasonably be encountered by the user. |

#3
| |||
| |||
|
|
+ /* Disallow BADCHARS characters */ + if (strcspn(cstate->delim, BADCHARS) != 1) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("COPY delimiter cannot be \"%#02x\"", + *cstate->delim))); + |
#4
| |||
| |||
|
| David Fetter wrote: + /* Disallow BADCHARS characters */ + if (strcspn(cstate->delim, BADCHARS) != 1) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("COPY delimiter cannot be \"%#02x\"", + *cstate->delim))); + Is ERRCODE_FEATURE_NOT_SUPPORTED the right errcode? This isn't a missing feature; we are performing a sanity check here. We can reasonably expect never to support CR, LF or \ as the text delimiter. |
|
Maybe ERRCODE_INVALID_PARAMETER_VALUE ? Or maybe we need a new one. Also, I would probably make the format %#.02x so the result would look like 0x0d (for a CR). (I bet David never thought there would so much fuss over a handful of lines of code) |

#5
| |||
| |||
|
|
Is ERRCODE_FEATURE_NOT_SUPPORTED the right errcode? This isn't a missing feature; we are performing a sanity check here. We can reasonably expect never to support CR, LF or \ as the text delimiter. |
|
Maybe ERRCODE_INVALID_PARAMETER_VALUE ? Or maybe we need a new one. |
#6
| |||
| |||
|
|
On Sun, Jan 29, 2006 at 10:20:47PM -0500, Neil Conway wrote: On Sun, 2006-01-29 at 17:03 -0800, David Fetter wrote: Another followup, this time with the comment done right. + /* Disallow the forbidden_delimiter strings */ + if (strcspn(cstate->delim, BADCHARS) != 1) + elog(ERROR, "COPY delimiter cannot be %#02x", + *cstate->delim); + The comment is still wrong: referencing "forbidden_delimiter" makes it sound like there is something named forbidden_delimiter, but there is not (at least in the patch as submitted). The patch should also use ereport rather than elog, because this error message might reasonably be encountered by the user. Patch with BADCHARS attached ![]() Cheers, D -- David Fetter david (AT) fetter (DOT) org http://fetter.org/ phone: +1 415 235 3778 Remember to vote! |
|
---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
#7
| |||
| |||
|
|
Uh, couldn't the delimiter be a backslash in CVS mode? |
|
+ #define BADCHARS "\r\n\\" Also, should we disable DELIMITER and NULL from sharing characters? |
#8
| |||
| |||
|
|
David Fetter said: On Tue, Jan 31, 2006 at 08:03:41PM -0500, Bruce Momjian wrote: Uh, couldn't the delimiter be a backslash in CVS mode? I don't think so. Folks? Using backslash as a delimiter in CSV would be odd, to say the least. As an escape char it is occasionally used, but not as a delimiter in my experience. Maybe we should apply the "be liberal in what you accept" rule, but I think this would be stretching it. |
|
Also, should we disable DELIMITER and NULL from sharing characters? That's on about line 916, post-patch: /* Don't allow the delimiter to appear in the null string. */ if (strchr(cstate->null_print, cstate->delim[0]) != NULL) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("COPY delimiter must not appear in the NULL specification"))); I suppose that a different error code might be The Right Thing™ here. ERRCODE_WHAT WERE_YOU_THINKING ? |

#9
| |||
| |||
|
|
On Tue, Jan 31, 2006 at 08:03:41PM -0500, Bruce Momjian wrote: Uh, couldn't the delimiter be a backslash in CVS mode? I don't think so. Folks? |
|
Anyhow, if there are different sets, I could do something like: #define BADCHARS "\r\n\\" #define BADCHARS_CSV "\r\n" and then check for csv_mode, etc. + #define BADCHARS "\r\n\\" Also, should we disable DELIMITER and NULL from sharing characters? That's on about line 916, post-patch: /* Don't allow the delimiter to appear in the null string. */ if (strchr(cstate->null_print, cstate->delim[0]) != NULL) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("COPY delimiter must not appear in the NULL specification"))); I suppose that a different error code might be The Right Thing™ here. |
![]() |
| Thread Tools | |
| Display Modes | |
| |