|
25 | 25 | * is copied into 'line_buf', with quotes and escape characters still
|
26 | 26 | * intact.
|
27 | 27 | *
|
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. |
| 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. |
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,8 +152,6 @@ 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); |
157 | 155 | static Datum CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo,
|
158 | 156 | Oid typioparam, int32 typmod,
|
159 | 157 | bool *isnull);
|
@@ -775,10 +773,7 @@ NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
|
775 | 773 | {
|
776 | 774 | int fldnum;
|
777 | 775 |
|
778 |
| - if (cstate->opts.csv_mode) |
779 |
| - fldct = CopyReadAttributesCSV(cstate); |
780 |
| - else |
781 |
| - fldct = CopyReadAttributesText(cstate); |
| 776 | + fldct = cstate->copy_read_attributes(cstate); |
782 | 777 |
|
783 | 778 | if (fldct != list_length(cstate->attnumlist))
|
784 | 779 | ereport(ERROR,
|
@@ -830,10 +825,7 @@ NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
|
830 | 825 | return false;
|
831 | 826 |
|
832 | 827 | /* Parse the line into de-escaped field values */
|
833 |
| - if (cstate->opts.csv_mode) |
834 |
| - fldct = CopyReadAttributesCSV(cstate); |
835 |
| - else |
836 |
| - fldct = CopyReadAttributesText(cstate); |
| 828 | + fldct = cstate->copy_read_attributes(cstate); |
837 | 829 |
|
838 | 830 | *fields = cstate->raw_fields;
|
839 | 831 | *nfields = fldct;
|
@@ -1502,7 +1494,7 @@ GetDecimalFromHex(char hex)
|
1502 | 1494 | *
|
1503 | 1495 | * The return value is the number of fields actually read.
|
1504 | 1496 | */
|
1505 |
| -static int |
| 1497 | +int |
1506 | 1498 | CopyReadAttributesText(CopyFromState cstate)
|
1507 | 1499 | {
|
1508 | 1500 | char delimc = cstate->opts.delim[0];
|
@@ -1756,7 +1748,7 @@ CopyReadAttributesText(CopyFromState cstate)
|
1756 | 1748 | * CopyReadAttributesText, except we parse the fields according to
|
1757 | 1749 | * "standard" (i.e. common) CSV usage.
|
1758 | 1750 | */
|
1759 |
| -static int |
| 1751 | +int |
1760 | 1752 | CopyReadAttributesCSV(CopyFromState cstate)
|
1761 | 1753 | {
|
1762 | 1754 | char delimc = cstate->opts.delim[0];
|
|
0 commit comments