|
25 | 25 | * is copied into 'line_buf', with quotes and escape characters still
|
26 | 26 | * intact.
|
27 | 27 | *
|
28 |
| - * 4. CopyReadAttributesText/CSV() function (via copy_read_attribute) takes |
29 |
| - * the input line from 'line_buf', and splits it into fields, unescaping |
30 |
| - * the data as required. The fields are stored in 'attribute_buf', and |
31 |
| - * 'raw_fields' array holds pointers to each field. |
| 28 | + * 4. CopyReadAttributesText/CSV() function takes the input line from |
| 29 | + * 'line_buf', and splits it into fields, unescaping the data as required. |
| 30 | + * The fields are stored in 'attribute_buf', and 'raw_fields' array holds |
| 31 | + * pointers to each field. |
32 | 32 | *
|
33 | 33 | * If encoding conversion is not required, a shortcut is taken in step 2 to
|
34 | 34 | * avoid copying the data unnecessarily. The 'input_buf' pointer is set to
|
@@ -152,6 +152,8 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0";
|
152 | 152 | /* non-export function prototypes */
|
153 | 153 | static bool CopyReadLine(CopyFromState cstate);
|
154 | 154 | static bool CopyReadLineText(CopyFromState cstate);
|
| 155 | +static int CopyReadAttributesText(CopyFromState cstate); |
| 156 | +static int CopyReadAttributesCSV(CopyFromState cstate); |
155 | 157 | static Datum CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo,
|
156 | 158 | Oid typioparam, int32 typmod,
|
157 | 159 | bool *isnull);
|
@@ -773,7 +775,10 @@ NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
|
773 | 775 | {
|
774 | 776 | int fldnum;
|
775 | 777 |
|
776 |
| - fldct = cstate->copy_read_attributes(cstate); |
| 778 | + if (cstate->opts.csv_mode) |
| 779 | + fldct = CopyReadAttributesCSV(cstate); |
| 780 | + else |
| 781 | + fldct = CopyReadAttributesText(cstate); |
777 | 782 |
|
778 | 783 | if (fldct != list_length(cstate->attnumlist))
|
779 | 784 | ereport(ERROR,
|
@@ -825,7 +830,10 @@ NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
|
825 | 830 | return false;
|
826 | 831 |
|
827 | 832 | /* Parse the line into de-escaped field values */
|
828 |
| - fldct = cstate->copy_read_attributes(cstate); |
| 833 | + if (cstate->opts.csv_mode) |
| 834 | + fldct = CopyReadAttributesCSV(cstate); |
| 835 | + else |
| 836 | + fldct = CopyReadAttributesText(cstate); |
829 | 837 |
|
830 | 838 | *fields = cstate->raw_fields;
|
831 | 839 | *nfields = fldct;
|
@@ -1494,7 +1502,7 @@ GetDecimalFromHex(char hex)
|
1494 | 1502 | *
|
1495 | 1503 | * The return value is the number of fields actually read.
|
1496 | 1504 | */
|
1497 |
| -int |
| 1505 | +static int |
1498 | 1506 | CopyReadAttributesText(CopyFromState cstate)
|
1499 | 1507 | {
|
1500 | 1508 | char delimc = cstate->opts.delim[0];
|
@@ -1748,7 +1756,7 @@ CopyReadAttributesText(CopyFromState cstate)
|
1748 | 1756 | * CopyReadAttributesText, except we parse the fields according to
|
1749 | 1757 | * "standard" (i.e. common) CSV usage.
|
1750 | 1758 | */
|
1751 |
| -int |
| 1759 | +static int |
1752 | 1760 | CopyReadAttributesCSV(CopyFromState cstate)
|
1753 | 1761 | {
|
1754 | 1762 | char delimc = cstate->opts.delim[0];
|
|
0 commit comments