MCPcopy Create free account
hub / github.com/apache/cloudberry / CopyConversionError

Function CopyConversionError

src/backend/commands/copyfromparse.c:501–550  ·  view source on GitHub ↗

* Report an encoding or conversion error. */

Source from the content-addressed store, hash-verified

499 * Report an encoding or conversion error.
500 */
501static void
502CopyConversionError(CopyFromState cstate)
503{
504 Assert(cstate->raw_buf_len > 0);
505 Assert(cstate->input_reached_error);
506
507 if (!cstate->need_transcoding)
508 {
509 /*
510 * Everything up to input_buf_len was successfully verified, and
511 * input_buf_len points to the invalid or incomplete character.
512 */
513 report_invalid_encoding(cstate->file_encoding,
514 cstate->raw_buf + cstate->input_buf_len,
515 cstate->raw_buf_len - cstate->input_buf_len);
516 }
517 else
518 {
519 /*
520 * raw_buf_index points to the invalid or untranslatable character. We
521 * let the conversion routine report the error, because it can provide
522 * a more specific error message than we could here. An earlier call
523 * to the conversion routine in CopyConvertBuf() detected that there
524 * is an error, now we call the conversion routine again with
525 * noError=false, to have it throw the error.
526 */
527 unsigned char *src;
528 int srclen;
529 unsigned char *dst;
530 int dstlen;
531
532 src = (unsigned char *) cstate->raw_buf + cstate->raw_buf_index;
533 srclen = cstate->raw_buf_len - cstate->raw_buf_index;
534 dst = (unsigned char *) cstate->input_buf + cstate->input_buf_len;
535 dstlen = INPUT_BUF_SIZE - cstate->input_buf_len + 1;
536
537 (void) pg_do_encoding_conversion_buf(cstate->conversion_proc,
538 cstate->file_encoding,
539 GetDatabaseEncoding(),
540 src, srclen,
541 dst, dstlen,
542 false);
543
544 /*
545 * The conversion routine should have reported an error, so this
546 * should not be reached.
547 */
548 elog(ERROR, "encoding conversion failed without error");
549 }
550}
551
552/*
553 * Load more data from data source to raw_buf.

Callers 2

CopyLoadInputBufFunction · 0.85
RemoveInvalidDataInBufFunction · 0.85

Calls 3

report_invalid_encodingFunction · 0.85
GetDatabaseEncodingFunction · 0.85

Tested by

no test coverage detected