* is copied into 'line_buf', with quotes and escape characters still
* intact.
*
- * 4. CopyReadAttributesText/CSV() function takes the input line from
- * 'line_buf', and splits it into fields, unescaping the data as required.
- * The fields are stored in 'attribute_buf', and 'raw_fields' array holds
- * pointers to each field.
+ * 4. CopyReadAttributesText/CSV() function (via copy_read_attribute) takes
+ * the input line from 'line_buf', and splits it into fields, unescaping
+ * the data as required. The fields are stored in 'attribute_buf', and
+ * 'raw_fields' array holds pointers to each field.
*
* If encoding conversion is not required, a shortcut is taken in step 2 to
* avoid copying the data unnecessarily. The 'input_buf' pointer is set to
/* non-export function prototypes */
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);
{
int fldnum;
- if (cstate->opts.csv_mode)
- fldct = CopyReadAttributesCSV(cstate);
- else
- fldct = CopyReadAttributesText(cstate);
+ fldct = cstate->copy_read_attributes(cstate);
if (fldct != list_length(cstate->attnumlist))
ereport(ERROR,
return false;
/* Parse the line into de-escaped field values */
- if (cstate->opts.csv_mode)
- fldct = CopyReadAttributesCSV(cstate);
- else
- fldct = CopyReadAttributesText(cstate);
+ fldct = cstate->copy_read_attributes(cstate);
*fields = cstate->raw_fields;
*nfields = fldct;
*
* The return value is the number of fields actually read.
*/
-static int
+int
CopyReadAttributesText(CopyFromState cstate)
{
char delimc = cstate->opts.delim[0];
* CopyReadAttributesText, except we parse the fields according to
* "standard" (i.e. common) CSV usage.
*/
-static int
+int
CopyReadAttributesCSV(CopyFromState cstate)
{
char delimc = cstate->opts.delim[0];
* ExecForeignBatchInsert only if valid */
} CopyInsertMethod;
+/*
+ * Per-format callback to parse a line into separate fields.
+ *
+ * Returns the number of fields read.
+ */
+typedef int (*CopyReadAttributes) (CopyFromState cstate);
+
/*
* This struct contains all the state variables used throughout a COPY FROM
* operation.
int max_fields;
char **raw_fields;
+ /*
+ * Per-format callback to parse lines, then fill raw_fields and
+ * attribute_buf.
+ */
+ CopyReadAttributes copy_read_attributes;
+
/*
* Similarly, line_buf holds the whole input line being processed. The
* input cycle is first to read the whole line into line_buf, and then
extern void ReceiveCopyBegin(CopyFromState cstate);
extern void ReceiveCopyBinaryHeader(CopyFromState cstate);
+/* Callbacks for copy_read_attributes */
+extern int CopyReadAttributesCSV(CopyFromState cstate);
+extern int CopyReadAttributesText(CopyFromState cstate);
+
#endif /* COPYFROM_INTERNAL_H */