PostgreSQL Source Code: src/pl/plperl/plperl.h File Reference (original) (raw)

Go to the source code of this file.

Functions
HV * plperl_spi_exec (char *, int)
void plperl_return_next (SV *)
SV * plperl_spi_query (char *)
SV * plperl_spi_fetchrow (char *)
SV * plperl_spi_prepare (char *, int, SV **)
HV * plperl_spi_exec_prepared (char *, HV *, int, SV **)
SV * plperl_spi_query_prepared (char *, int, SV **)
void plperl_spi_freeplan (char *)
void plperl_spi_cursor_close (char *)
void plperl_spi_commit (void)
void plperl_spi_rollback (void)
char * plperl_sv_to_literal (SV *, char *)
void plperl_util_elog (int level, SV *msg)
static char * utf_u2e (char *utf8_str, size_t len)
static char * utf_e2u (const char *str)
static char * sv2cstr (SV *sv)
static SV * cstr2sv (const char *str)
static void croak_cstr (const char *str)

croak_cstr()

static void croak_cstr ( const char * str) inlinestatic

Definition at line 175 of file plperl.h.

176{

178

179#ifdef croak_sv

180

182#else

183

184

185

186

187

188

189

190

191 SV *errsv = get_sv("@", GV_ADD);

193 SV *ssv;

194

195 ssv = mess("%s", utf8_str);

196 SvUTF8_on(ssv);

197

199

200 sv_setsv(errsv, ssv);

201

202 croak(NULL);

203#endif

204}

void pfree(void *pointer)

static char * utf_e2u(const char *str)

static SV * cstr2sv(const char *str)

References croak_sv, cstr2sv(), dTHX, get_sv, pfree(), str, and utf_e2u().

Referenced by plperl_return_next(), plperl_spi_commit(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), plperl_spi_rollback(), and plperl_util_elog().

cstr2sv()

static SV * cstr2sv ( const char * str) inlinestatic

Definition at line 147 of file plperl.h.

148{

150 SV *sv;

151 char *utf8_str;

152

153

155 return newSVpv(str, 0);

156

158

159 sv = newSVpv(utf8_str, 0);

160 SvUTF8_on(sv);

162

163 return sv;

164}

int GetDatabaseEncoding(void)

References dTHX, GetDatabaseEncoding(), pfree(), PG_SQL_ASCII, str, and utf_e2u().

Referenced by croak_cstr(), hstore_to_plperl(), JsonbValue_to_SV(), make_array_ref(), plperl_call_perl_func(), plperl_call_perl_trigger_func(), plperl_create_sub(), plperl_event_trigger_build_args(), plperl_hash_from_tuple(), plperl_spi_execute_fetch_result(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), and plperl_trigger_build_args().

plperl_return_next()

void plperl_return_next ( SV * sv )

Definition at line 3246 of file plperl.c.

3247{

3249

3251

3253 {

3255 }

3257 {

3259

3260

3264

3265

3267 }

3269}

ErrorData * CopyErrorData(void)

void FlushErrorState(void)

MemoryContext CurrentMemoryContext

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

static void check_spi_usage_allowed(void)

static void plperl_return_next_internal(SV *sv)

static void croak_cstr(const char *str)

References check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), CurrentMemoryContext, FlushErrorState(), MemoryContextSwitchTo(), ErrorData::message, PG_CATCH, PG_END_TRY, PG_TRY, and plperl_return_next_internal().

plperl_spi_commit()

void plperl_spi_commit ( void )

Definition at line 3992 of file plperl.c.

3993{

3995

3997

3999 {

4001 }

4003 {

4005

4006

4010

4011

4013 }

4015}

References check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), CurrentMemoryContext, FlushErrorState(), MemoryContextSwitchTo(), ErrorData::message, PG_CATCH, PG_END_TRY, PG_TRY, and SPI_commit().

plperl_spi_cursor_close()

void plperl_spi_cursor_close ( char * cursor )

plperl_spi_exec()

HV * plperl_spi_exec ( char * query,
int limit
)

Definition at line 3134 of file plperl.c.

3135{

3136 HV *ret_hv;

3137

3138

3139

3140

3141

3144

3146

3148

3150

3152 {

3153 int spi_rv;

3154

3156

3158 limit);

3160 spi_rv);

3161

3162

3166 }

3168 {

3170

3171

3175

3176

3180

3181

3183

3184

3185 return NULL;

3186 }

3188

3189 return ret_hv;

3190}

bool pg_verifymbstr(const char *mbstr, int len, bool noError)

static HV * plperl_spi_execute_fetch_result(SPITupleTable *, uint64, int)

static plperl_call_data * current_call_data

ResourceOwner CurrentResourceOwner

SPITupleTable * SPI_tuptable

int SPI_execute(const char *src, bool read_only, long tcount)

plperl_proc_desc * prodesc

void BeginInternalSubTransaction(const char *name)

void RollbackAndReleaseCurrentSubTransaction(void)

void ReleaseCurrentSubTransaction(void)

References BeginInternalSubTransaction(), check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), current_call_data, CurrentMemoryContext, CurrentResourceOwner, FlushErrorState(), plperl_proc_desc::fn_readonly, MemoryContextSwitchTo(), ErrorData::message, PG_CATCH, PG_END_TRY, PG_TRY, pg_verifymbstr(), plperl_spi_execute_fetch_result(), plperl_call_data::prodesc, ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), SPI_execute(), SPI_processed, and SPI_tuptable.

plperl_spi_exec_prepared()

HV * plperl_spi_exec_prepared ( char * query,
HV * attr,
int argc,
SV ** argv
)

Definition at line 3716 of file plperl.c.

3717{

3718 HV *ret_hv;

3719 SV **sv;

3720 int i,

3721 limit,

3722 spi_rv;

3723 char *nulls;

3724 Datum *argvalues;

3727

3728

3729

3730

3731

3734

3736

3738

3740

3742 {

3744

3745

3746

3747

3750 if (hash_entry == NULL)

3751 elog(ERROR, "spi_exec_prepared: Invalid prepared query passed");

3752

3754 if (qdesc == NULL)

3755 elog(ERROR, "spi_exec_prepared: plperl query_hash value vanished");

3756

3757 if (qdesc->nargs != argc)

3758 elog(ERROR, "spi_exec_prepared: expected %d argument(s), %d passed",

3759 qdesc->nargs, argc);

3760

3761

3762

3763

3764 limit = 0;

3765 if (attr != NULL)

3766 {

3768 if (sv && *sv && SvIOK(*sv))

3769 limit = SvIV(*sv);

3770 }

3771

3772

3773

3774 if (argc > 0)

3775 {

3776 nulls = (char *) palloc(argc);

3778 }

3779 else

3780 {

3781 nulls = NULL;

3782 argvalues = NULL;

3783 }

3784

3785 for (i = 0; i < argc; i++)

3786 {

3787 bool isnull;

3788

3791 -1,

3792 NULL,

3795 &isnull);

3796 nulls[i] = isnull ? 'n' : ' ';

3797 }

3798

3799

3800

3801

3805 spi_rv);

3806 if (argc > 0)

3807 {

3808 pfree(argvalues);

3810 }

3811

3812

3816 }

3818 {

3820

3821

3825

3826

3830

3831

3833

3834

3835 return NULL;

3836 }

3838

3839 return ret_hv;

3840}

void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)

static plperl_interp_desc * plperl_active_interp

static Datum plperl_sv_to_datum(SV *sv, Oid typid, int32 typmod, FunctionCallInfo fcinfo, FmgrInfo *finfo, Oid typioparam, bool *isnull)

static SV ** hv_fetch_string(HV *hv, const char *key)

int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only, long tcount)

plperl_query_desc * query_data

References plperl_query_desc::arginfuncs, plperl_query_desc::argtypes, plperl_query_desc::argtypioparams, BeginInternalSubTransaction(), check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), current_call_data, CurrentMemoryContext, CurrentResourceOwner, dTHX, elog, ERROR, FlushErrorState(), plperl_proc_desc::fn_readonly, HASH_FIND, hash_search(), hv_fetch_string(), i, MemoryContextSwitchTo(), ErrorData::message, plperl_query_desc::nargs, palloc(), pfree(), PG_CATCH, PG_END_TRY, PG_TRY, plperl_query_desc::plan, plperl_active_interp, plperl_spi_execute_fetch_result(), plperl_sv_to_datum(), plperl_call_data::prodesc, plperl_query_entry::query_data, plperl_interp_desc::query_hash, ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), SPI_execute_plan(), SPI_processed, and SPI_tuptable.

plperl_spi_fetchrow()

SV * plperl_spi_fetchrow ( char * cursor )

Definition at line 3477 of file plperl.c.

3478{

3479 SV *row;

3480

3481

3482

3483

3484

3487

3489

3491

3493

3495 {

3498

3499 if (!p)

3500 {

3502 }

3503 else

3504 {

3507 {

3511 }

3512 else

3513 {

3516 true);

3517 }

3519 }

3520

3521

3525 }

3527 {

3529

3530

3534

3535

3539

3540

3542

3543

3544 return NULL;

3545 }

3547

3548 return row;

3549}

static SV * plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc, bool include_generated)

void SPI_cursor_fetch(Portal portal, bool forward, long count)

void SPI_freetuptable(SPITupleTable *tuptable)

References BeginInternalSubTransaction(), check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), CurrentMemoryContext, CurrentResourceOwner, dTHX, FlushErrorState(), MemoryContextSwitchTo(), ErrorData::message, PG_CATCH, PG_END_TRY, PG_TRY, PL_sv_undef, plperl_hash_from_tuple(), ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), SPI_cursor_close(), SPI_cursor_fetch(), SPI_cursor_find(), SPI_freetuptable(), SPI_processed, SPI_tuptable, SPITupleTable::tupdesc, UnpinPortal(), and SPITupleTable::vals.

plperl_spi_freeplan()

void plperl_spi_freeplan ( char * query )

Definition at line 3961 of file plperl.c.

3962{

3966

3968

3971 if (hash_entry == NULL)

3972 elog(ERROR, "spi_freeplan: Invalid prepared query passed");

3973

3975 if (qdesc == NULL)

3976 elog(ERROR, "spi_freeplan: plperl query_hash value vanished");

3978

3979

3980

3981

3982

3985

3987

3989}

void MemoryContextDelete(MemoryContext context)

int SPI_freeplan(SPIPlanPtr plan)

References check_spi_usage_allowed(), elog, ERROR, HASH_FIND, HASH_REMOVE, hash_search(), MemoryContextDelete(), plperl_query_desc::plan, plan, plperl_query_desc::plan_cxt, plperl_active_interp, plperl_query_entry::query_data, plperl_interp_desc::query_hash, and SPI_freeplan().

plperl_spi_prepare()

SV * plperl_spi_prepare ( char * query,
int argc,
SV ** argv
)

Definition at line 3568 of file plperl.c.

3569{

3577 bool found;

3578 int i;

3579

3581

3584

3586 {

3588

3589

3590

3591

3592

3593

3594

3596 "PL/Perl spi_prepare query",

3602 qdesc->nargs = argc;

3607

3608

3609

3610

3611

3613 "PL/Perl spi_prepare workspace",

3616

3617

3618

3619

3620

3621

3622 for (i = 0; i < argc; i++)

3623 {

3624 Oid typId,

3625 typInput,

3626 typIOParam;

3628 char *typstr;

3629

3633

3635

3639 }

3640

3641

3643

3644

3645

3646

3648

3649 if (plan == NULL)

3650 elog(ERROR, "SPI_prepare() failed:%s",

3652

3653

3654

3655

3656

3658 elog(ERROR, "SPI_keepplan() failed");

3660

3661

3662

3663

3668

3669

3671

3672

3676 }

3678 {

3680

3681

3685

3686

3687 if (hash_entry)

3691 if (plan_cxt)

3695

3696

3700

3701

3703

3704

3705 return NULL;

3706 }

3708

3709

3710

3711

3713}

void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)

void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)

void * palloc0(Size size)

MemoryContext TopMemoryContext

#define AllocSetContextCreate

#define ALLOCSET_DEFAULT_SIZES

#define ALLOCSET_SMALL_SIZES

#define CHECK_FOR_INTERRUPTS()

bool parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, Node *escontext)

static char * sv2cstr(SV *sv)

const char * SPI_result_code_string(int code)

SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)

int SPI_keepplan(SPIPlanPtr plan)

References ALLOCSET_DEFAULT_SIZES, ALLOCSET_SMALL_SIZES, AllocSetContextCreate, plperl_query_desc::arginfuncs, plperl_query_desc::argtypes, plperl_query_desc::argtypioparams, BeginInternalSubTransaction(), CHECK_FOR_INTERRUPTS, check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), cstr2sv(), CurrentMemoryContext, CurrentResourceOwner, elog, ERROR, FlushErrorState(), fmgr_info_cxt(), getTypeInputInfo(), HASH_ENTER, HASH_REMOVE, hash_search(), i, MemoryContextDelete(), MemoryContextSwitchTo(), ErrorData::message, plperl_query_desc::nargs, palloc(), palloc0(), parseTypeString(), pfree(), PG_CATCH, PG_END_TRY, PG_TRY, pg_verifymbstr(), plperl_query_desc::plan, plan, plperl_query_desc::plan_cxt, plperl_active_interp, plperl_query_desc::qname, plperl_query_entry::query_data, plperl_interp_desc::query_hash, ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), snprintf, SPI_freeplan(), SPI_keepplan(), SPI_prepare(), SPI_result, SPI_result_code_string(), sv2cstr(), and TopMemoryContext.

plperl_spi_query()

SV * plperl_spi_query ( char * query )

Definition at line 3405 of file plperl.c.

3406{

3408

3409

3410

3411

3412

3415

3417

3419

3421

3423 {

3426

3427

3429

3430

3432 if (plan == NULL)

3433 elog(ERROR, "SPI_prepare() failed:%s",

3435

3438 if (portal == NULL)

3439 elog(ERROR, "SPI_cursor_open() failed:%s",

3442

3444

3445

3449 }

3451 {

3453

3454

3458

3459

3463

3464

3466

3467

3468 return NULL;

3469 }

3471

3473}

void PinPortal(Portal portal)

Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only)

References BeginInternalSubTransaction(), check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), cstr2sv(), CurrentMemoryContext, CurrentResourceOwner, elog, ERROR, FlushErrorState(), MemoryContextSwitchTo(), ErrorData::message, PortalData::name, PG_CATCH, PG_END_TRY, PG_TRY, pg_verifymbstr(), PinPortal(), plan, ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), SPI_cursor_open(), SPI_freeplan(), SPI_prepare(), SPI_result, and SPI_result_code_string().

plperl_spi_query_prepared()

SV * plperl_spi_query_prepared ( char * query,
int argc,
SV ** argv
)

Definition at line 3843 of file plperl.c.

3844{

3845 int i;

3846 char *nulls;

3847 Datum *argvalues;

3851 Portal portal = NULL;

3852

3853

3854

3855

3856

3859

3861

3863

3865

3867 {

3868

3869

3870

3873 if (hash_entry == NULL)

3874 elog(ERROR, "spi_query_prepared: Invalid prepared query passed");

3875

3877 if (qdesc == NULL)

3878 elog(ERROR, "spi_query_prepared: plperl query_hash value vanished");

3879

3880 if (qdesc->nargs != argc)

3881 elog(ERROR, "spi_query_prepared: expected %d argument(s), %d passed",

3882 qdesc->nargs, argc);

3883

3884

3885

3886

3887 if (argc > 0)

3888 {

3889 nulls = (char *) palloc(argc);

3891 }

3892 else

3893 {

3894 nulls = NULL;

3895 argvalues = NULL;

3896 }

3897

3898 for (i = 0; i < argc; i++)

3899 {

3900 bool isnull;

3901

3904 -1,

3905 NULL,

3908 &isnull);

3909 nulls[i] = isnull ? 'n' : ' ';

3910 }

3911

3912

3913

3914

3917 if (argc > 0)

3918 {

3919 pfree(argvalues);

3921 }

3922 if (portal == NULL)

3923 elog(ERROR, "SPI_cursor_open() failed:%s",

3925

3927

3929

3930

3934 }

3936 {

3938

3939

3943

3944

3948

3949

3951

3952

3953 return NULL;

3954 }

3956

3958}

References plperl_query_desc::arginfuncs, plperl_query_desc::argtypes, plperl_query_desc::argtypioparams, BeginInternalSubTransaction(), check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), cstr2sv(), current_call_data, CurrentMemoryContext, CurrentResourceOwner, elog, ERROR, FlushErrorState(), plperl_proc_desc::fn_readonly, HASH_FIND, hash_search(), i, MemoryContextSwitchTo(), ErrorData::message, PortalData::name, plperl_query_desc::nargs, palloc(), pfree(), PG_CATCH, PG_END_TRY, PG_TRY, PinPortal(), plperl_query_desc::plan, plperl_active_interp, plperl_sv_to_datum(), plperl_call_data::prodesc, plperl_query_entry::query_data, plperl_interp_desc::query_hash, ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), SPI_cursor_open(), SPI_result, and SPI_result_code_string().

plperl_spi_rollback()

void plperl_spi_rollback ( void )

Definition at line 4018 of file plperl.c.

4019{

4021

4023

4025 {

4027 }

4029 {

4031

4032

4036

4037

4039 }

4041}

References check_spi_usage_allowed(), CopyErrorData(), croak_cstr(), CurrentMemoryContext, FlushErrorState(), MemoryContextSwitchTo(), ErrorData::message, PG_CATCH, PG_END_TRY, PG_TRY, and SPI_rollback().

plperl_sv_to_literal()

char * plperl_sv_to_literal ( SV * sv,
char * fqtypename
)

Definition at line 1446 of file plperl.c.

1447{

1448 Oid typid;

1449 Oid typoutput;

1451 bool typisvarlena,

1452 isnull;

1453

1455

1459 (errcode(ERRCODE_UNDEFINED_OBJECT),

1460 errmsg("lookup failed for type %s", fqtypename)));

1461

1463 typid, -1,

1465 &isnull);

1466

1467 if (isnull)

1468 return NULL;

1469

1471 &typoutput, &typisvarlena);

1472

1474}

#define OidIsValid(objectId)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

char * OidOutputFunctionCall(Oid functionId, Datum val)

#define DirectFunctionCall1(func, arg1)

void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)

static Datum CStringGetDatum(const char *X)

Datum regtypein(PG_FUNCTION_ARGS)

References check_spi_usage_allowed(), CStringGetDatum(), DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, getTypeOutputInfo(), InvalidOid, OidIsValid, OidOutputFunctionCall(), plperl_sv_to_datum(), and regtypein().

plperl_util_elog()

void plperl_util_elog ( int level,
SV * msg
)

Definition at line 4055 of file plperl.c.

4056{

4058 char *volatile cmsg = NULL;

4059

4060

4061

4062

4063

4064

4066 {

4068 elog(level, "%s", cmsg);

4070 }

4072 {

4074

4075

4079

4080 if (cmsg)

4082

4083

4085 }

4087}

References CopyErrorData(), croak_cstr(), CurrentMemoryContext, elog, FlushErrorState(), MemoryContextSwitchTo(), ErrorData::message, pfree(), PG_CATCH, PG_END_TRY, PG_TRY, and sv2cstr().

sv2cstr()

static char * sv2cstr ( SV * sv) inlinestatic

Definition at line 89 of file plperl.h.

90{

92 char *val,

93 *res;

94 STRLEN len;

95

96

97

98

99

100

101

102

103

104

105

106

107 if (SvREADONLY(sv) ||

109 (SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM))

110 sv = newSVsv(sv);

111 else

112 {

113

114

115

116

118 }

119

120

121

122

123

124

127 else

128 val = SvPVutf8(sv, len);

129

130

131

132

133

135

136

137 SvREFCNT_dec(sv);

138

139 return res;

140}

static char * utf_u2e(char *utf8_str, size_t len)

#define SvREFCNT_inc_simple_void(sv)

References dTHX, GetDatabaseEncoding(), isGV_with_GP, len, PG_SQL_ASCII, SvREFCNT_inc_simple_void, utf_u2e(), and val.

Referenced by hek2cstr(), plperl_call_perl_event_trigger_func(), plperl_call_perl_func(), plperl_call_perl_trigger_func(), plperl_create_sub(), plperl_init_interp(), plperl_spi_prepare(), plperl_sv_to_datum(), plperl_to_hstore(), plperl_trigger_handler(), plperl_trusted_init(), plperl_untrusted_init(), plperl_util_elog(), select_perl_context(), and SV_to_JsonbValue().

utf_e2u()

static char * utf_e2u ( const char * str) inlinestatic

utf_u2e()

static char * utf_u2e ( char * utf8_str, size_t len ) inlinestatic