PostgreSQL Source Code  git master
copyfrom_internal.h File Reference
#include "commands/copy.h"
#include "commands/trigger.h"
#include "nodes/miscnodes.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 164 of file copyfrom_internal.h.

◆ INPUT_BUF_SIZE

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

Definition at line 157 of file copyfrom_internal.h.

◆ RAW_BUF_BYTES

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

Definition at line 178 of file copyfrom_internal.h.

◆ RAW_BUF_SIZE

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

Definition at line 171 of file copyfrom_internal.h.

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 46 of file copyfrom_internal.h.

47 {
48  CIM_SINGLE, /* use table_tuple_insert or ExecForeignInsert */
49  CIM_MULTI, /* always use table_multi_insert or
50  * ExecForeignBatchInsert */
51  CIM_MULTI_CONDITIONAL, /* use table_multi_insert or
52  * ExecForeignBatchInsert only if valid */
CopyInsertMethod
@ CIM_SINGLE
@ CIM_MULTI_CONDITIONAL
@ CIM_MULTI

◆ CopySource

enum CopySource
Enumerator
COPY_FILE 
COPY_FRONTEND 
COPY_CALLBACK 

Definition at line 25 of file copyfrom_internal.h.

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

◆ EolType

enum EolType
Enumerator
EOL_UNKNOWN 
EOL_NL 
EOL_CR 
EOL_CRNL 

Definition at line 35 of file copyfrom_internal.h.

36 {
38  EOL_NL,
39  EOL_CR,
40  EOL_CRNL,
41 } EolType;
@ EOL_CR
@ EOL_CRNL
@ EOL_UNKNOWN
@ EOL_NL

Function Documentation

◆ ReceiveCopyBegin()

void ReceiveCopyBegin ( CopyFromState  cstate)

Definition at line 170 of file copyfromparse.c.

171 {
173  int natts = list_length(cstate->attnumlist);
174  int16 format = (cstate->opts.binary ? 1 : 0);
175  int i;
176 
178  pq_sendbyte(&buf, format); /* overall format */
179  pq_sendint16(&buf, natts);
180  for (i = 0; i < natts; i++)
181  pq_sendint16(&buf, format); /* per-column formats */
182  pq_endmessage(&buf);
183  cstate->copy_src = COPY_FRONTEND;
184  cstate->fe_msgbuf = makeStringInfo();
185  /* We *must* flush here to ensure FE knows it can send. */
186  pq_flush();
187 }
signed short int16
Definition: c.h:493
@ COPY_FRONTEND
Definition: copyto.c:46
int i
Definition: isn.c:73
#define pq_flush()
Definition: libpq.h:46
static char format
static int list_length(const List *l)
Definition: pg_list.h:152
static char * buf
Definition: pg_test_fsync.c:73
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:296
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:160
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:136
#define PqMsg_CopyInResponse
Definition: protocol.h:45
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
bool binary
Definition: copy.h:62
CopyFormatOptions opts

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(), pq_sendint16(), and PqMsg_CopyInResponse.

Referenced by BeginCopyFrom().

◆ ReceiveCopyBinaryHeader()

void ReceiveCopyBinaryHeader ( CopyFromState  cstate)

Definition at line 190 of file copyfromparse.c.

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

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

Referenced by BeginCopyFrom().