PostgreSQL Source Code  git master
copyfrom_internal.h File Reference
#include "commands/copy.h"
#include "commands/trigger.h"
Include dependency graph for copyfrom_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CopyFromStateData
 

Macros

#define INPUT_BUF_SIZE   65536 /* we palloc INPUT_BUF_SIZE+1 bytes */
 
#define INPUT_BUF_BYTES(cstate)   ((cstate)->input_buf_len - (cstate)->input_buf_index)
 
#define RAW_BUF_SIZE   65536 /* we palloc RAW_BUF_SIZE+1 bytes */
 
#define RAW_BUF_BYTES(cstate)   ((cstate)->raw_buf_len - (cstate)->raw_buf_index)
 

Typedefs

typedef enum CopySource CopySource
 
typedef enum EolType EolType
 
typedef enum CopyInsertMethod CopyInsertMethod
 
typedef struct CopyFromStateData CopyFromStateData
 

Enumerations

enum  CopySource { COPY_FILE, COPY_FRONTEND, COPY_CALLBACK }
 
enum  EolType { EOL_UNKNOWN, EOL_NL, EOL_CR, EOL_CRNL }
 
enum  CopyInsertMethod { CIM_SINGLE, CIM_MULTI, CIM_MULTI_CONDITIONAL }
 

Functions

void ReceiveCopyBegin (CopyFromState cstate)
 
void ReceiveCopyBinaryHeader (CopyFromState cstate)
 

Macro Definition Documentation

◆ INPUT_BUF_BYTES

#define INPUT_BUF_BYTES (   cstate)    ((cstate)->input_buf_len - (cstate)->input_buf_index)

Definition at line 150 of file copyfrom_internal.h.

Referenced by CopyConvertBuf(), CopyLoadInputBuf(), and CopyReadLineText().

◆ INPUT_BUF_SIZE

#define INPUT_BUF_SIZE   65536 /* we palloc INPUT_BUF_SIZE+1 bytes */

◆ RAW_BUF_BYTES

#define RAW_BUF_BYTES (   cstate)    ((cstate)->raw_buf_len - (cstate)->raw_buf_index)

Definition at line 164 of file copyfrom_internal.h.

Referenced by CopyConvertBuf(), CopyLoadRawBuf(), and CopyReadBinaryData().

◆ RAW_BUF_SIZE

#define RAW_BUF_SIZE   65536 /* we palloc RAW_BUF_SIZE+1 bytes */

Definition at line 157 of file copyfrom_internal.h.

Referenced by BeginCopyFrom(), and CopyLoadRawBuf().

Typedef Documentation

◆ CopyFromStateData

◆ CopyInsertMethod

◆ CopySource

typedef enum CopySource CopySource

◆ EolType

typedef enum EolType EolType

Enumeration Type Documentation

◆ CopyInsertMethod

Enumerator
CIM_SINGLE 
CIM_MULTI 
CIM_MULTI_CONDITIONAL 

Definition at line 45 of file copyfrom_internal.h.

46 {
47  CIM_SINGLE, /* use table_tuple_insert or fdw routine */
48  CIM_MULTI, /* always use table_multi_insert */
49  CIM_MULTI_CONDITIONAL /* use table_multi_insert only if valid */
CopyInsertMethod

◆ CopySource

enum CopySource
Enumerator
COPY_FILE 
COPY_FRONTEND 
COPY_CALLBACK 

Definition at line 24 of file copyfrom_internal.h.

25 {
26  COPY_FILE, /* from file (or a piped program) */
27  COPY_FRONTEND, /* from frontend */
28  COPY_CALLBACK /* from callback function */
29 } CopySource;
CopySource

◆ EolType

enum EolType
Enumerator
EOL_UNKNOWN 
EOL_NL 
EOL_CR 
EOL_CRNL 

Definition at line 34 of file copyfrom_internal.h.

Function Documentation

◆ ReceiveCopyBegin()

void ReceiveCopyBegin ( CopyFromState  cstate)

Definition at line 169 of file copyfromparse.c.

References CopyFromStateData::attnumlist, CopyFormatOptions::binary, buf, COPY_FRONTEND, CopyFromStateData::copy_src, CopyFromStateData::fe_msgbuf, format, i, list_length(), makeStringInfo(), CopyFromStateData::opts, pq_beginmessage(), pq_endmessage(), pq_flush, pq_sendbyte(), and pq_sendint16().

Referenced by BeginCopyFrom().

170 {
172  int natts = list_length(cstate->attnumlist);
173  int16 format = (cstate->opts.binary ? 1 : 0);
174  int i;
175 
176  pq_beginmessage(&buf, 'G');
177  pq_sendbyte(&buf, format); /* overall format */
178  pq_sendint16(&buf, natts);
179  for (i = 0; i < natts; i++)
180  pq_sendint16(&buf, format); /* per-column formats */
181  pq_endmessage(&buf);
182  cstate->copy_src = COPY_FRONTEND;
183  cstate->fe_msgbuf = makeStringInfo();
184  /* We *must* flush here to ensure FE knows it can send. */
185  pq_flush();
186 }
signed short int16
Definition: c.h:428
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define pq_flush()
Definition: libpq.h:46
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:87
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
bool binary
Definition: copy.h:32
static char * buf
Definition: pg_test_fsync.c:68
static int list_length(const List *l)
Definition: pg_list.h:149
CopyFormatOptions opts
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:298
int i
static char format

◆ ReceiveCopyBinaryHeader()

void ReceiveCopyBinaryHeader ( CopyFromState  cstate)

Definition at line 189 of file copyfromparse.c.

References BinarySignature, CopyGetInt32(), CopyReadBinaryData(), ereport, errcode(), errmsg(), and ERROR.

Referenced by BeginCopyFrom().

190 {
191  char readSig[11];
192  int32 tmp;
193 
194  /* Signature */
195  if (CopyReadBinaryData(cstate, readSig, 11) != 11 ||
196  memcmp(readSig, BinarySignature, 11) != 0)
197  ereport(ERROR,
198  (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
199  errmsg("COPY file signature not recognized")));
200  /* Flags field */
201  if (!CopyGetInt32(cstate, &tmp))
202  ereport(ERROR,
203  (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
204  errmsg("invalid COPY file header (missing flags)")));
205  if ((tmp & (1 << 16)) != 0)
206  ereport(ERROR,
207  (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
208  errmsg("invalid COPY file header (WITH OIDS)")));
209  tmp &= ~(1 << 16);
210  if ((tmp >> 16) != 0)
211  ereport(ERROR,
212  (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
213  errmsg("unrecognized critical flags in COPY file header")));
214  /* Header extension length */
215  if (!CopyGetInt32(cstate, &tmp) ||
216  tmp < 0)
217  ereport(ERROR,
218  (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
219  errmsg("invalid COPY file header (missing length)")));
220  /* Skip extension header, if present */
221  while (tmp-- > 0)
222  {
223  if (CopyReadBinaryData(cstate, readSig, 1) != 1)
224  ereport(ERROR,
225  (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
226  errmsg("invalid COPY file header (wrong length)")));
227  }
228 }
static const char BinarySignature[11]
int errcode(int sqlerrcode)
Definition: elog.c:698
static bool CopyGetInt32(CopyFromState cstate, int32 *val)
signed int int32
Definition: c.h:429
static int CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909