diff options
author | Neil Conway <neilc@samurai.com> | 2007-03-03 19:32:55 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2007-03-03 19:32:55 +0000 |
commit | 90d76525c5cc2f3f4781351a1d99be839dfa2874 (patch) | |
tree | 75ee2db58298898533663d779d711879c43edb8d /src/backend/commands/copy.c | |
parent | 053981f4054f6dfcda0ce65566605b49ca366a97 (diff) | |
download | postgresql-90d76525c5cc2f3f4781351a1d99be839dfa2874.tar.gz postgresql-90d76525c5cc2f3f4781351a1d99be839dfa2874.zip |
Add resetStringInfo(), which clears the content of a StringInfo, and
fixup various places in the tree that were clearing a StringInfo by hand.
Making this function a part of the API simplifies client code slightly,
and avoids needlessly peeking inside the StringInfo interface.
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 30118d5237b..17f0135981e 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.276 2007/02/20 17:32:13 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.277 2007/03/03 19:32:54 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -466,9 +466,7 @@ CopySendEndOfRow(CopyState cstate) break; } - /* Reset fe_msgbuf to empty */ - fe_msgbuf->len = 0; - fe_msgbuf->data[0] = '\0'; + resetStringInfo(fe_msgbuf); } /* @@ -2193,9 +2191,7 @@ CopyReadLine(CopyState cstate) { bool result; - /* Reset line_buf to empty */ - cstate->line_buf.len = 0; - cstate->line_buf.data[0] = '\0'; + resetStringInfo(&cstate->line_buf); /* Mark that encoding conversion hasn't occurred yet */ cstate->line_buf_converted = false; @@ -2262,8 +2258,7 @@ CopyReadLine(CopyState cstate) if (cvt != cstate->line_buf.data) { /* transfer converted data back to line_buf */ - cstate->line_buf.len = 0; - cstate->line_buf.data[0] = '\0'; + resetStringInfo(&cstate->line_buf); appendBinaryStringInfo(&cstate->line_buf, cvt, strlen(cvt)); pfree(cvt); } @@ -2686,9 +2681,7 @@ CopyReadAttributesText(CopyState cstate, int maxfields, char **fieldvals) return 0; } - /* reset attribute_buf to empty */ - cstate->attribute_buf.len = 0; - cstate->attribute_buf.data[0] = '\0'; + resetStringInfo(&cstate->attribute_buf); /* * The de-escaped attributes will certainly not be longer than the input @@ -2886,9 +2879,7 @@ CopyReadAttributesCSV(CopyState cstate, int maxfields, char **fieldvals) return 0; } - /* reset attribute_buf to empty */ - cstate->attribute_buf.len = 0; - cstate->attribute_buf.data[0] = '\0'; + resetStringInfo(&cstate->attribute_buf); /* * The de-escaped attributes will certainly not be longer than the input @@ -3040,12 +3031,9 @@ CopyReadBinaryAttribute(CopyState cstate, errmsg("invalid field size"))); /* reset attribute_buf to empty, and load raw data in it */ - cstate->attribute_buf.len = 0; - cstate->attribute_buf.data[0] = '\0'; - cstate->attribute_buf.cursor = 0; + resetStringInfo(&cstate->attribute_buf); enlargeStringInfo(&cstate->attribute_buf, fld_size); - if (CopyGetData(cstate, cstate->attribute_buf.data, fld_size, fld_size) != fld_size) ereport(ERROR, |