summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-05-09 21:19:50 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-05-09 21:19:50 +0000
commitb1ee615a7f9b645d72ee560b74e4621ed5936cf8 (patch)
tree9ef1ab11c2ef687a6870138110c5618fc6bd4ce0 /src/backend/utils
parent38d9919d1ac22ca39b18acc4b8df457995101517 (diff)
downloadpostgresql-b1ee615a7f9b645d72ee560b74e4621ed5936cf8.tar.gz
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')
-rw-r--r--src/backend/utils/adt/float.c61
-rw-r--r--src/backend/utils/adt/geo_ops.c34
-rw-r--r--src/backend/utils/adt/name.c69
3 files changed, 131 insertions, 33 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index 4f770a2e97..e954e7e949 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -8,16 +8,18 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.86 2003/05/09 16:31:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.87 2003/05/09 21:19:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*----------
* OLD COMMENTS
* Basic float4 ops:
- * float4in, float4out, float4abs, float4um, float4up
+ * float4in, float4out, float4recv, float4send
+ * float4abs, float4um, float4up
* Basic float8 ops:
- * float8in, float8out, float8abs, float8um, float8up
+ * float8in, float8out, float8recv, float8send
+ * float8abs, float8um, float8up
* Arithmetic operators:
* float4pl, float4mi, float4mul, float4div
* float8pl, float8mi, float8mul, float8div
@@ -63,6 +65,7 @@
#include "catalog/pg_type.h"
#include "fmgr.h"
+#include "libpq/pqformat.h"
#include "utils/array.h"
#include "utils/builtins.h"
@@ -243,6 +246,31 @@ float4out(PG_FUNCTION_ARGS)
}
/*
+ * float4recv - converts external binary format to float4
+ */
+Datum
+float4recv(PG_FUNCTION_ARGS)
+{
+ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
+
+ PG_RETURN_FLOAT4(pq_getmsgfloat4(buf));
+}
+
+/*
+ * float4send - converts float4 to binary format
+ */
+Datum
+float4send(PG_FUNCTION_ARGS)
+{
+ float4 num = PG_GETARG_FLOAT4(0);
+ StringInfoData buf;
+
+ pq_begintypsend(&buf);
+ pq_sendfloat4(&buf, num);
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
+}
+
+/*
* float8in - converts "num" to float8
* restricted syntax:
* {<sp>} [+|-] {digit} [.{digit}] [<exp>]
@@ -280,7 +308,6 @@ float8in(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(val);
}
-
/*
* float8out - converts float8 number to a string
* using a standard output format
@@ -310,6 +337,32 @@ float8out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(ascii);
}
+/*
+ * float8recv - converts external binary format to float8
+ */
+Datum
+float8recv(PG_FUNCTION_ARGS)
+{
+ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
+
+ PG_RETURN_FLOAT8(pq_getmsgfloat8(buf));
+}
+
+/*
+ * float8send - converts float8 to binary format
+ */
+Datum
+float8send(PG_FUNCTION_ARGS)
+{
+ float8 num = PG_GETARG_FLOAT8(0);
+ StringInfoData buf;
+
+ pq_begintypsend(&buf);
+ pq_sendfloat8(&buf, num);
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
+}
+
+
/* ========== PUBLIC ROUTINES ========== */
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index d8d1f7c3af..956bd1753f 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.75 2003/03/11 21:01:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.76 2003/05/09 21:19:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -19,11 +19,11 @@
#include <float.h>
#include <ctype.h>
+#include "libpq/pqformat.h"
#include "utils/builtins.h"
#include "utils/geo_decls.h"
#ifndef M_PI
-/* from my RH5.2 gcc math.h file - thomas 2000-04-03 */
#define M_PI 3.14159265358979323846
#endif
@@ -1589,6 +1589,36 @@ point_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(path_encode(-1, 1, pt));
}
+/*
+ * point_recv - converts external binary format to point
+ */
+Datum
+point_recv(PG_FUNCTION_ARGS)
+{
+ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
+ Point *point;
+
+ point = (Point *) palloc(sizeof(Point));
+ point->x = pq_getmsgfloat8(buf);
+ point->y = pq_getmsgfloat8(buf);
+ PG_RETURN_POINT_P(point);
+}
+
+/*
+ * point_send - converts point to binary format
+ */
+Datum
+point_send(PG_FUNCTION_ARGS)
+{
+ Point *pt = PG_GETARG_POINT_P(0);
+ StringInfoData buf;
+
+ pq_begintypsend(&buf);
+ pq_sendfloat8(&buf, pt->x);
+ pq_sendfloat8(&buf, pt->y);
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
+}
+
static Point *
point_construct(double x, double y)
diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c
index 607f7876a8..b7a56cb1cb 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