Skip to content

Commit

Permalink
Replace inputCallSafe function on OidCallSafe
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Dec 12, 2024
1 parent ec9deca commit 64950bf
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions contrib/try_convert/try_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "nodes/nodeFuncs.h"
#include "nodes/miscnodes.h"

#include "executor/spi.h"

#include "funcapi.h"

// #define USE_PG_TRY_CATCH
Expand Down Expand Up @@ -223,10 +225,11 @@ try_convert_from_function(Datum value, int32 typmod, Oid funcId, bool *is_failed
Datum
try_convert_via_io(Datum value, Oid sourceTypeId, Oid targetTypeId, int32 targetTypMod, bool *is_failed)
{
FmgrInfo outfunc;
FmgrInfo infunc;
FmgrInfo outfunc;

Oid infuncId = InvalidOid;
Oid outfuncId = InvalidOid;

Oid iofunc = InvalidOid;
bool outtypisvarlena = false;
Oid intypioparam = InvalidOid;

Expand All @@ -237,14 +240,14 @@ try_convert_via_io(Datum value, Oid sourceTypeId, Oid targetTypeId, int32 target
targetTypeId = getBaseType(targetTypeId);

/* lookup the input type's output function */
getTypeOutputInfo(sourceTypeId, &iofunc, &outtypisvarlena);
fmgr_info(iofunc, &outfunc);
getTypeOutputInfo(sourceTypeId, &outfuncId, &outtypisvarlena);
fmgr_info(outfuncId, &outfunc);

getTypeInputInfo(targetTypeId, &iofunc, &intypioparam);
fmgr_info(iofunc, &infunc);
getTypeInputInfo(targetTypeId, &infuncId, &intypioparam);

Datum res = 0;
char *string;
char* string;
bool pushed;

ErrorSaveContext escontext = {T_ErrorSaveContext, false};

Expand All @@ -256,11 +259,14 @@ try_convert_via_io(Datum value, Oid sourceTypeId, Oid targetTypeId, int32 target
// value cannot be null
string = OutputFunctionCall(&outfunc, value);

res = InputFunctionCallSafe(&infunc,
string,
intypioparam,
-1,
&escontext);
pushed = SPI_push_conditional();
res = OidFunctionCall3Safe(infuncId,
CStringGetDatum(string),
ObjectIdGetDatum(intypioparam),
Int32GetDatum(-1),

&escontext);
SPI_pop_conditional(pushed);

if (escontext.error_occurred) {
*is_failed = true;
Expand Down

0 comments on commit 64950bf

Please sign in to comment.