示例#1
0
文件: type.c 项目: plproxy/plproxy
/* Convert a libpq result to Datum */
Datum
plproxy_recv_type(ProxyType *type, char *val, int len, bool bin)
{
	Datum		res;
	StringInfoData buf;

	Assert(type->for_send == 0);

	if (bin)
	{
		if (!type->has_recv)
			elog(ERROR, "PL/Proxy: type %u recv not supported", type->type_oid);

		/* avoid unnecessary copy */
		setFixedStringInfo(&buf, val, len);

		res = ReceiveFunctionCall(&type->io.in.recv_func,
								  &buf, type->io_param, -1);
	}
	else
	{
		res = InputFunctionCall(&type->io.in.input_func,
								val, type->io_param, -1);
	}
	return res;
}
示例#2
0
文件: result.c 项目: comagic/plexor
static Datum
get_row(FunctionCallInfo fcinfo, PlxResult *plx_result, int nrow)
{
    StringInfoData  buf;
    PlxFn          *plx_fn = plx_result->plx_fn;
    PGresult       *pg_result = plx_result->pg_result;
    Datum           ret;

    if (PQgetisnull(pg_result, nrow, 0))
    {
        fcinfo->isnull = true;
        return (Datum)NULL;
    }

    setFixedStringInfo(&buf,
                       PQgetvalue(pg_result, nrow, 0),
                       PQgetlength(pg_result, nrow, 0));

    PG_TRY();
    {
        if (plx_fn->is_binary)
            ret = ReceiveFunctionCall(&plx_fn->ret_type->receive_fn,
                                      &buf,
                                      plx_fn->ret_type->receive_io_params,
                                      plx_fn->ret_type_mod);
        else
            ret = InputFunctionCall(&plx_fn->ret_type->input_fn,
                                    buf.data,
                                    plx_fn->ret_type->receive_io_params,
                                    plx_fn->ret_type_mod);
    }
    PG_CATCH();
    {
        plx_result_cache_delete(fcinfo);
        PQclear(pg_result);
        pfree(plx_result);
        PG_RE_THROW();
    }
    PG_END_TRY();
    return ret;
}