diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-05-09 21:19:50 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-05-09 21:19:50 +0000 |
commit | b1ee615a7f9b645d72ee560b74e4621ed5936cf8 (patch) | |
tree | 9ef1ab11c2ef687a6870138110c5618fc6bd4ce0 /src/backend/utils/adt/name.c | |
parent | 38d9919d1ac22ca39b18acc4b8df457995101517 (diff) |
COPY BINARY uses the new binary I/O routines. Update a few more datatypes
so that COPY BINARY regression test passes.
Diffstat (limited to 'src/backend/utils/adt/name.c')
-rw-r--r-- | src/backend/utils/adt/name.c | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index 607f7876a85..b7a56cb1cb1 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -2,8 +2,10 @@ * * name.c * Functions for the built-in type "name". + * * name replaces char16 and is carefully implemented so that it - * is a string of length NAMEDATALEN. DO NOT use hard-coded constants anywhere + * is a string of physical length NAMEDATALEN. + * DO NOT use hard-coded constants anywhere * always use NAMEDATALEN as the symbolic constant! - jolly 8/21/95 * * @@ -12,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.44 2003/04/27 23:22:13 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.45 2003/05/09 21:19:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -20,11 +22,13 @@ #include "catalog/namespace.h" #include "catalog/pg_type.h" +#include "libpq/pqformat.h" +#include "mb/pg_wchar.h" #include "miscadmin.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/lsyscache.h" -#include "mb/pg_wchar.h" + /***************************************************************************** * USER I/O ROUTINES (none) * @@ -53,9 +57,7 @@ namein(PG_FUNCTION_ARGS) len = pg_mbcliplen(s, len, NAMEDATALEN - 1); - result = (NameData *) palloc(NAMEDATALEN); - /* always keep it null-padded */ - memset(result, 0, NAMEDATALEN); + result = (NameData *) palloc0(NAMEDATALEN); memcpy(NameStr(*result), s, len); PG_RETURN_NAME(result); @@ -72,6 +74,40 @@ nameout(PG_FUNCTION_ARGS) PG_RETURN_CSTRING(pstrdup(NameStr(*s))); } +/* + * namerecv - converts external binary format to name + */ +Datum +namerecv(PG_FUNCTION_ARGS) +{ + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + Name result; + char *str; + int nbytes; + + str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); + if (nbytes >= NAMEDATALEN) + elog(ERROR, "namerecv: input name too long"); + result = (NameData *) palloc0(NAMEDATALEN); + memcpy(result, str, nbytes); + pfree(str); + PG_RETURN_NAME(result); +} + +/* + * namesend - converts name to binary format + */ +Datum +namesend(PG_FUNCTION_ARGS) +{ + Name s = PG_GETARG_NAME(0); + StringInfoData buf; + + pq_begintypsend(&buf); + pq_sendtext(&buf, NameStr(*s), strlen(NameStr(*s))); + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} + /***************************************************************************** * PUBLIC ROUTINES * @@ -283,24 +319,3 @@ current_schemas(PG_FUNCTION_ARGS) PG_RETURN_POINTER(array); } - - -/***************************************************************************** - * PRIVATE ROUTINES * - *****************************************************************************/ - -#ifdef NOT_USED -uint32 -NameComputeLength(Name name) -{ - char *charP; - int length; - - for (length = 0, charP = NameStr(*name); - length < NAMEDATALEN && *charP != '\0'; - length++, charP++) - ; - return (uint32) length; -} - -#endif |