Commit 0ac6298b authored by Tom Lane's avatar Tom Lane

Implement new-protocol binary I/O support in DataRow, Bind, and FunctionCall

messages.  Binary I/O is now up and working, but only for a small set
of datatypes (integers, text, bytea).
parent d85a0a6b
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.198 2003/05/08 18:16:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.199 2003/05/09 18:08:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -828,11 +828,9 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
int attnum = lfirsti(cur);
Oid out_func_oid;
if (!getTypeOutputInfo(attr[attnum - 1]->atttypid,
&out_func_oid, &elements[attnum - 1],
&isvarlena[attnum - 1]))
elog(ERROR, "COPY: couldn't lookup info for type %u",
attr[attnum - 1]->atttypid);
getTypeOutputInfo(attr[attnum - 1]->atttypid,
&out_func_oid, &elements[attnum - 1],
&isvarlena[attnum - 1]);
fmgr_info(out_func_oid, &out_functions[attnum - 1]);
if (binary && attr[attnum - 1]->attlen == -2)
elog(ERROR, "COPY BINARY: cstring not supported");
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.97 2003/05/08 18:16:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.98 2003/05/09 18:08:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -546,11 +546,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
typmod = -1;
}
if (!getTypeOutputInfo(typoid, &foutoid, &typelem, &typisvarlena))
{
SPI_result = SPI_ERROR_NOOUTFUNC;
return NULL;
}
getTypeOutputInfo(typoid, &foutoid, &typelem, &typisvarlena);
/*
* If we have a toasted datum, forcibly detoast it here to avoid
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.341 2003/05/09 15:57:24 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.342 2003/05/09 18:08:48 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
......@@ -1342,8 +1342,21 @@ exec_bind_message(StringInfo input_message)
}
else if (pformat == 1)
{
/* XXX something similar to above */
elog(ERROR, "Binary BIND not implemented yet");
Oid typReceive;
Oid typElem;
/* Call the parameter type's binary input converter */
getTypeBinaryInputInfo(ptype, &typReceive, &typElem);
params[i].value =
OidFunctionCall2(typReceive,
PointerGetDatum(&pbuf),
ObjectIdGetDatum(typElem));
/* Trouble if it didn't eat the whole buffer */
if (pbuf.cursor != pbuf.len)
elog(ERROR, "Improper binary format in BIND parameter %d",
i + 1);
}
else
{
......@@ -2511,7 +2524,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.341 $ $Date: 2003/05/09 15:57:24 $\n");
puts("$Revision: 1.342 $ $Date: 2003/05/09 18:08:48 $\n");
}
/*
......@@ -2771,6 +2784,9 @@ PostgresMain(int argc, char *argv[], const char *username)
/* start an xact for this function invocation */
start_xact_command();
/* switch back to message context */
MemoryContextSwitchTo(MessageContext);
if (HandleFunctionRequest(input_message) == EOF)
{
/* lost frontend connection during F message input */
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.92 2003/04/08 23:20:02 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.93 2003/05/09 18:08:48 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
......@@ -1361,11 +1361,15 @@ getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem)
ObjectIdGetDatum(type),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "getTypeInputInfo: Cache lookup of type %u failed", type);
elog(ERROR, "Cache lookup of type %u failed", type);
pt = (Form_pg_type) GETSTRUCT(typeTuple);
if (!pt->typisdefined)
elog(ERROR, "Type \"%s\" is only a shell", NameStr(pt->typname));
elog(ERROR, "Type %s is only a shell",
format_type_be(type));
if (!OidIsValid(pt->typinput))
elog(ERROR, "No input function available for type %s",
format_type_be(type));
*typInput = pt->typinput;
*typElem = pt->typelem;
......@@ -1377,10 +1381,8 @@ getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem)
* getTypeOutputInfo
*
* Get info needed for printing values of a type
*
* Returns true if data valid (a false result probably means it's a shell type)
*/
bool
void
getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
bool *typIsVarlena)
{
......@@ -1391,14 +1393,85 @@ getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
ObjectIdGetDatum(type),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "getTypeOutputInfo: Cache lookup of type %u failed", type);
elog(ERROR, "Cache lookup of type %u failed", type);
pt = (Form_pg_type) GETSTRUCT(typeTuple);
if (!pt->typisdefined)
elog(ERROR, "Type %s is only a shell",
format_type_be(type));
if (!OidIsValid(pt->typoutput))
elog(ERROR, "No output function available for type %s",
format_type_be(type));
*typOutput = pt->typoutput;
*typElem = pt->typelem;
*typIsVarlena = (!pt->typbyval) && (pt->typlen == -1);
ReleaseSysCache(typeTuple);
}
/*
* getTypeBinaryInputInfo
*
* Get info needed for binary input of values of a type
*/
void
getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typElem)
{
HeapTuple typeTuple;
Form_pg_type pt;
typeTuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(type),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "Cache lookup of type %u failed", type);
pt = (Form_pg_type) GETSTRUCT(typeTuple);
if (!pt->typisdefined)
elog(ERROR, "Type %s is only a shell",
format_type_be(type));
if (!OidIsValid(pt->typreceive))
elog(ERROR, "No binary input function available for type %s",
format_type_be(type));
*typReceive = pt->typreceive;
*typElem = pt->typelem;
ReleaseSysCache(typeTuple);
}
/*
* getTypeBinaryOutputInfo
*
* Get info needed for binary output of values of a type
*/
void
getTypeBinaryOutputInfo(Oid type, Oid *typSend, Oid *typElem,
bool *typIsVarlena)
{
HeapTuple typeTuple;
Form_pg_type pt;
typeTuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(type),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "Cache lookup of type %u failed", type);
pt = (Form_pg_type) GETSTRUCT(typeTuple);
if (!pt->typisdefined)
elog(ERROR, "Type %s is only a shell",
format_type_be(type));
if (!OidIsValid(pt->typsend))
elog(ERROR, "No binary output function available for type %s",
format_type_be(type));
*typSend = pt->typsend;
*typElem = pt->typelem;
*typIsVarlena = (!pt->typbyval) && (pt->typlen == -1);
ReleaseSysCache(typeTuple);
return OidIsValid(*typOutput);
}
......
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: lsyscache.h,v 1.68 2003/04/08 23:20:04 tgl Exp $
* $Id: lsyscache.h,v 1.69 2003/05/09 18:08:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -61,8 +61,11 @@ extern Oid get_typ_typrelid(Oid typid);
extern Oid get_element_type(Oid typid);
extern Oid get_array_type(Oid typid);
extern void getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem);
extern bool getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
extern void getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
bool *typIsVarlena);
extern void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typElem);
extern void getTypeBinaryOutputInfo(Oid type, Oid *typSend, Oid *typElem,
bool *typIsVarlena);
extern Oid getBaseType(Oid typid);
extern int32 get_typavgwidth(Oid typid, int32 typmod);
extern int32 get_attavgwidth(Oid relid, AttrNumber attnum);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment