PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 */
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,
41} EolType;
@ EOL_CR
@ EOL_CRNL
@ EOL_UNKNOWN
@ EOL_NL

Function Documentation

◆ ReceiveCopyBegin()

void ReceiveCopyBegin ( CopyFromState  cstate)

Definition at line 161 of file copyfromparse.c.

162{
164 int natts = list_length(cstate->attnumlist);
165 int16 format = (cstate->opts.binary ? 1 : 0);
166 int i;
167
169 pq_sendbyte(&buf, format); /* overall format */
170 pq_sendint16(&buf, natts);
171 for (i = 0; i < natts; i++)
172 pq_sendint16(&buf, format); /* per-column formats */
174 cstate->copy_src = COPY_FRONTEND;
175 cstate->fe_msgbuf = makeStringInfo();
176 /* We *must* flush here to ensure FE knows it can send. */
177 pq_flush();
178}
int16_t int16
Definition: c.h:480
@ COPY_FRONTEND
Definition: copyto.c:46
int i
Definition: isn.c:72
#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:72
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:38
bool binary
Definition: copy.h:64
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 181 of file copyfromparse.c.

182{
183 char readSig[11];
184 int32 tmp;
185
186 /* Signature */
187 if (CopyReadBinaryData(cstate, readSig, 11) != 11 ||
188 memcmp(readSig, BinarySignature, 11) != 0)
190 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
191 errmsg("COPY file signature not recognized")));
192 /* Flags field */
193 if (!CopyGetInt32(cstate, &tmp))
195 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
196 errmsg("invalid COPY file header (missing flags)")));
197 if ((tmp & (1 << 16)) != 0)
199 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
200 errmsg("invalid COPY file header (WITH OIDS)")));
201 tmp &= ~(1 << 16);
202 if ((tmp >> 16) != 0)
204 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
205 errmsg("unrecognized critical flags in COPY file header")));
206 /* Header extension length */
207 if (!CopyGetInt32(cstate, &tmp) ||
208 tmp < 0)
210 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
211 errmsg("invalid COPY file header (missing length)")));
212 /* Skip extension header, if present */
213 while (tmp-- > 0)
214 {
215 if (CopyReadBinaryData(cstate, readSig, 1) != 1)
217 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
218 errmsg("invalid COPY file header (wrong length)")));
219 }
220}
int32_t int32
Definition: c.h:481
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:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#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().