PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include "commands/copy.h"
#include "commands/copyfrom_internal.h"
#include "commands/progress.h"
#include "executor/executor.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "port/pg_bswap.h"
#include "utils/memutils.h"
#include "utils/rel.h"
Go to the source code of this file.
Macros | |
#define | ISOCTAL(c) (((c) >= '0') && ((c) <= '7')) |
#define | OCTVALUE(c) ((c) - '0') |
#define | IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(extralen) |
#define | IF_NEED_REFILL_AND_EOF_BREAK(extralen) |
#define | REFILL_LINEBUF |
#define | NO_END_OF_COPY_GOTO |
Functions | |
static bool | CopyReadLine (CopyFromState cstate) |
static bool | CopyReadLineText (CopyFromState cstate) |
static int | CopyReadAttributesText (CopyFromState cstate) |
static int | CopyReadAttributesCSV (CopyFromState cstate) |
static Datum | CopyReadBinaryAttribute (CopyFromState cstate, FmgrInfo *flinfo, Oid typioparam, int32 typmod, bool *isnull) |
static int | CopyGetData (CopyFromState cstate, void *databuf, int minread, int maxread) |
static bool | CopyGetInt32 (CopyFromState cstate, int32 *val) |
static bool | CopyGetInt16 (CopyFromState cstate, int16 *val) |
static bool | CopyLoadRawBuf (CopyFromState cstate) |
static int | CopyReadBinaryData (CopyFromState cstate, char *dest, int nbytes) |
void | ReceiveCopyBegin (CopyFromState cstate) |
void | ReceiveCopyBinaryHeader (CopyFromState cstate) |
bool | NextCopyFromRawFields (CopyFromState cstate, char ***fields, int *nfields) |
bool | NextCopyFrom (CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls) |
static int | GetDecimalFromHex (char hex) |
Variables | |
static const char | BinarySignature [11] = "PGCOPY\n\377\r\n\0" |
#define IF_NEED_REFILL_AND_EOF_BREAK | ( | extralen | ) |
Definition at line 65 of file copyfromparse.c.
Referenced by CopyReadLineText().
#define IF_NEED_REFILL_AND_NOT_EOF_CONTINUE | ( | extralen | ) |
Definition at line 53 of file copyfromparse.c.
Referenced by CopyReadLineText().
Definition at line 34 of file copyfromparse.c.
Referenced by CopyReadAttributesText().
#define NO_END_OF_COPY_GOTO |
Definition at line 95 of file copyfromparse.c.
Referenced by CopyReadLineText().
Definition at line 35 of file copyfromparse.c.
Referenced by CopyReadAttributesText().
#define REFILL_LINEBUF |
Definition at line 82 of file copyfromparse.c.
Referenced by CopyReadLineText().
|
static |
Definition at line 216 of file copyfromparse.c.
References COPY_CALLBACK, COPY_FILE, CopyFromStateData::copy_file, COPY_NEW_FE, COPY_OLD_FE, CopyFromStateData::copy_src, StringInfoData::cursor, CopyFromStateData::data_source_cb, ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, CopyFromStateData::fe_msgbuf, HOLD_CANCEL_INTERRUPTS, StringInfoData::len, pq_copymsgbytes(), pq_getbyte(), pq_getbytes(), pq_getmessage(), pq_getmsgstring(), pq_startmsgread(), CopyFromStateData::reached_eof, and RESUME_CANCEL_INTERRUPTS.
Referenced by CopyLoadRawBuf().
|
inlinestatic |
Definition at line 349 of file copyfromparse.c.
References buf, CopyReadBinaryData(), and pg_ntoh16.
Referenced by NextCopyFrom().
|
inlinestatic |
Definition at line 332 of file copyfromparse.c.
References buf, CopyReadBinaryData(), and pg_ntoh32.
Referenced by CopyReadBinaryAttribute(), and ReceiveCopyBinaryHeader().
|
static |
Definition at line 373 of file copyfromparse.c.
References CopyFromStateData::bytes_processed, CopyGetData(), pgstat_progress_update_param(), PROGRESS_COPY_BYTES_PROCESSED, CopyFromStateData::raw_buf, RAW_BUF_BYTES, CopyFromStateData::raw_buf_index, CopyFromStateData::raw_buf_len, and RAW_BUF_SIZE.
Referenced by CopyReadBinaryData(), CopyReadLine(), and CopyReadLineText().
|
static |
Definition at line 1404 of file copyfromparse.c.
References Assert, CopyFromStateData::attribute_buf, StringInfoData::data, CopyFormatOptions::delim, enlargeStringInfo(), ereport, errcode(), errmsg(), ERROR, CopyFormatOptions::escape, StringInfoData::len, CopyFromStateData::line_buf, CopyFromStateData::max_fields, StringInfoData::maxlen, CopyFormatOptions::null_print, CopyFormatOptions::null_print_len, CopyFromStateData::opts, CopyFormatOptions::quote, CopyFromStateData::raw_fields, repalloc(), and resetStringInfo().
Referenced by NextCopyFromRawFields().
|
static |
Definition at line 1176 of file copyfromparse.c.
References Assert, CopyFromStateData::attribute_buf, StringInfoData::data, CopyFormatOptions::delim, enlargeStringInfo(), ereport, errcode(), errmsg(), ERROR, GetDecimalFromHex(), IS_HIGHBIT_SET, ISOCTAL, StringInfoData::len, CopyFromStateData::line_buf, CopyFromStateData::max_fields, StringInfoData::maxlen, CopyFormatOptions::null_print, CopyFormatOptions::null_print_len, OCTVALUE, CopyFromStateData::opts, pg_verifymbstr(), CopyFromStateData::raw_fields, repalloc(), resetStringInfo(), and val.
Referenced by NextCopyFromRawFields().
|
static |
Definition at line 1573 of file copyfromparse.c.
References CopyFromStateData::attribute_buf, CopyGetInt32(), CopyReadBinaryData(), StringInfoData::cursor, StringInfoData::data, enlargeStringInfo(), ereport, errcode(), errmsg(), ERROR, StringInfoData::len, ReceiveFunctionCall(), and resetStringInfo().
Referenced by NextCopyFrom().
|
static |
Definition at line 402 of file copyfromparse.c.
References CopyLoadRawBuf(), Min, CopyFromStateData::raw_buf, RAW_BUF_BYTES, and CopyFromStateData::raw_buf_index.
Referenced by CopyGetInt16(), CopyGetInt32(), CopyReadBinaryAttribute(), NextCopyFrom(), and ReceiveCopyBinaryHeader().
|
static |
Definition at line 695 of file copyfromparse.c.
References appendBinaryStringInfo(), Assert, COPY_NEW_FE, CopyFromStateData::copy_src, CopyLoadRawBuf(), CopyReadLineText(), StringInfoData::data, EOL_CR, EOL_CRNL, EOL_NL, CopyFromStateData::eol_type, EOL_UNKNOWN, CopyFromStateData::file_encoding, StringInfoData::len, CopyFromStateData::line_buf, CopyFromStateData::line_buf_converted, CopyFromStateData::line_buf_valid, CopyFromStateData::need_transcoding, pfree(), pg_any_to_server(), CopyFromStateData::raw_buf_index, CopyFromStateData::raw_buf_len, and resetStringInfo().
Referenced by NextCopyFromRawFields().
|
static |
Definition at line 784 of file copyfromparse.c.
References appendBinaryStringInfo(), CopyLoadRawBuf(), CopyFormatOptions::csv_mode, CopyFromStateData::cur_lineno, CopyFromStateData::encoding_embeds_ascii, EOL_CR, EOL_CRNL, EOL_NL, CopyFromStateData::eol_type, EOL_UNKNOWN, ereport, errcode(), errhint(), errmsg(), ERROR, CopyFormatOptions::escape, CopyFromStateData::file_encoding, IF_NEED_REFILL_AND_EOF_BREAK, IF_NEED_REFILL_AND_NOT_EOF_CONTINUE, IS_HIGHBIT_SET, CopyFromStateData::line_buf, NO_END_OF_COPY_GOTO, CopyFromStateData::opts, pg_encoding_mblen(), CopyFormatOptions::quote, CopyFromStateData::raw_buf, CopyFromStateData::raw_buf_index, CopyFromStateData::raw_buf_len, and REFILL_LINEBUF.
Referenced by CopyReadLine().
|
static |
Definition at line 1148 of file copyfromparse.c.
Referenced by CopyReadAttributesText().
bool NextCopyFrom | ( | CopyFromState | cstate, |
ExprContext * | econtext, | ||
Datum * | values, | ||
bool * | nulls | ||
) |
Definition at line 505 of file copyfromparse.c.
References Assert, attnum, CopyFromStateData::attnumlist, CopyFormatOptions::binary, CopyFromStateData::convert_select_flags, COPY_OLD_FE, CopyFromStateData::copy_src, CopyGetInt16(), CopyReadBinaryAttribute(), CopyReadBinaryData(), CopyFormatOptions::csv_mode, cur, CopyFromStateData::cur_attname, CopyFromStateData::cur_attval, CopyFromStateData::cur_lineno, CurrentMemoryContext, CopyFromStateData::defexprs, CopyFromStateData::defmap, ExprContext::ecxt_per_tuple_memory, ereport, errcode(), errmsg(), ERROR, ExecEvalExpr(), CopyFormatOptions::force_notnull_flags, CopyFormatOptions::force_null_flags, i, CopyFromStateData::in_functions, InputFunctionCall(), lfirst_int, list_length(), MemSet, NameStr, TupleDescData::natts, NextCopyFromRawFields(), CopyFormatOptions::null_print, CopyFromStateData::num_defaults, CopyFromStateData::opts, CopyFromStateData::rel, RelationGetDescr, TupleDescAttr, and CopyFromStateData::typioparams.
Referenced by CopyFrom(), file_acquire_sample_rows(), and fileIterateForeignScan().
bool NextCopyFromRawFields | ( | CopyFromState | cstate, |
char *** | fields, | ||
int * | nfields | ||
) |
Definition at line 454 of file copyfromparse.c.
References Assert, CopyFormatOptions::binary, CopyReadAttributesCSV(), CopyReadAttributesText(), CopyReadLine(), CopyFormatOptions::csv_mode, CopyFromStateData::cur_lineno, CopyFormatOptions::header_line, StringInfoData::len, CopyFromStateData::line_buf, CopyFromStateData::opts, and CopyFromStateData::raw_fields.
Referenced by NextCopyFrom().
void ReceiveCopyBegin | ( | CopyFromState | cstate | ) |
Definition at line 125 of file copyfromparse.c.
References CopyFromStateData::attnumlist, CopyFormatOptions::binary, buf, COPY_NEW_FE, COPY_OLD_FE, CopyFromStateData::copy_src, ereport, errcode(), errmsg(), ERROR, CopyFromStateData::fe_msgbuf, format, FrontendProtocol, i, list_length(), makeStringInfo(), CopyFromStateData::opts, PG_PROTOCOL_MAJOR, pq_beginmessage(), pq_endmessage(), pq_flush, pq_putemptymessage(), pq_sendbyte(), pq_sendint16(), and pq_startmsgread().
Referenced by BeginCopyFrom().
void ReceiveCopyBinaryHeader | ( | CopyFromState | cstate | ) |
Definition at line 161 of file copyfromparse.c.
References BinarySignature, CopyGetInt32(), CopyReadBinaryData(), ereport, errcode(), errmsg(), and ERROR.
Referenced by BeginCopyFrom().
|
static |
Definition at line 103 of file copyfromparse.c.
Referenced by ReceiveCopyBinaryHeader().