diff options
author | Marc G. Fournier <scrappy@hub.org> | 1998-07-24 03:32:46 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1998-07-24 03:32:46 +0000 |
commit | bf00bbb0c4940b80b46b7e5b379cd64184f2262f (patch) | |
tree | bf32bf3bafe6f367ee97249c83afb4c9e9a637af /src/backend/commands/copy.c | |
parent | 6e66468f3a160878111578a93be2852635eb4f4d (diff) | |
download | postgresql-bf00bbb0c4940b80b46b7e5b379cd64184f2262f.tar.gz postgresql-bf00bbb0c4940b80b46b7e5b379cd64184f2262f.zip |
I really hope that I haven't missed anything in this one...
From: t-ishii@sra.co.jp
Attached are patches to enhance the multi-byte support. (patches are
against 7/18 snapshot)
* determine encoding at initdb/createdb rather than compile time
Now initdb/createdb has an option to specify the encoding. Also, I
modified the syntax of CREATE DATABASE to accept encoding option. See
README.mb for more details.
For this purpose I have added new column "encoding" to pg_database.
Also pg_attribute and pg_class are changed to catch up the
modification to pg_database. Actually I haved added pg_database_mb.h,
pg_attribute_mb.h and pg_class_mb.h. These are used only when MB is
enabled. The reason having separate files is I couldn't find a way to
use ifdef or whatever in those files. I have to admit it looks
ugly. No way.
* support for PGCLIENTENCODING when issuing COPY command
commands/copy.c modified.
* support for SQL92 syntax "SET NAMES"
See gram.y.
* support for LATIN2-5
* add UNICODE regression test case
* new test suite for MB
New directory test/mb added.
* clean up source files
Basic idea is to have MB's own subdirectory for easier maintenance.
These are include/mb and backend/utils/mb.
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 4ad772d0a38..23af759af4c 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.49 1998/07/15 18:53:40 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.50 1998/07/24 03:31:14 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -37,6 +37,10 @@ #include "commands/trigger.h" #include <storage/fd.h> +#ifdef MB +#include "mb/pg_wchar.h" +#endif + #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7')) #define VALUE(c) ((c) - '0') @@ -61,7 +65,7 @@ static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim); #endif -static void CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array); +static void CopyAttributeOut(FILE *fp, unsigned char *string, char *delim, int is_array); static int CountTuples(Relation relation); extern FILE *Pfout, @@ -277,7 +281,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim) { string = (char *) (*fmgr_faddr(&out_functions[i])) (value, elements[i], typmod[i]); - CopyAttributeOut(fp, string, delim, attr[i]->attnelems); + CopyAttributeOut(fp, (unsigned char*)string, delim, attr[i]->attnelems); pfree(string); } else @@ -1012,6 +1016,17 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim) char c; int done = 0; int i = 0; +#ifdef MB + int mblen; + int encoding; + unsigned char s[2]; + int j; +#endif + +#ifdef MB + encoding = pg_get_client_encoding(); + s[1] = 0; +#endif #ifdef COPY_PATCH /* if last delimiter was a newline return a NULL attribute */ @@ -1029,9 +1044,9 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim) while (!done) { c = getc(fp); - if (feof(fp)) return (NULL); + else if (c == '\\') { c = getc(fp); @@ -1112,21 +1127,55 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim) #endif done = 1; } - if (!done) + if (!done) { attribute[i++] = c; +#ifdef MB + s[0] = c; + mblen = pg_encoding_mblen(encoding, s); + mblen--; + for(j=0;j<mblen;j++) { + c = getc(fp); + if (feof(fp)) + return (NULL); + attribute[i++] = c; + } +#endif + } if (i == EXT_ATTLEN - 1) elog(ERROR, "CopyReadAttribute - attribute length too long. line: %d", lineno); } attribute[i] = '\0'; +#ifdef MB + return(pg_client_to_server((unsigned char*)attribute, strlen(attribute))); +#else return (&attribute[0]); +#endif } static void -CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array) +CopyAttributeOut(FILE *fp, unsigned char *server_string, char *delim, int is_array) { - char c; + unsigned char *string; + unsigned char c; +#ifdef MB + int mblen; + int encoding; + int i; +#endif + +#ifdef MB + string = pg_server_to_client(server_string, strlen(server_string)); + encoding = pg_get_client_encoding(); +#else + string = server_string; +#endif +#ifdef MB + for (; (mblen = pg_encoding_mblen(encoding, string)) && + ((c = *string) != '\0'); string += mblen) +#else for (; (c = *string) != '\0'; string++) +#endif { if (c == delim[0] || c == '\n' || (c == '\\' && !is_array)) @@ -1148,7 +1197,13 @@ CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array) fputc('\\', fp); } } +#ifdef MB + for (i=0;i<mblen;i++) { + fputc(*(string+i), fp); + } +#else fputc(*string, fp); +#endif } } |