Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
27bce577
Commit
27bce577
authored
Jun 20, 2002
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing SRF file.
parent
95712b15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
0 deletions
+122
-0
src/backend/utils/fmgr/funcapi.c
src/backend/utils/fmgr/funcapi.c
+122
-0
No files found.
src/backend/utils/fmgr/funcapi.c
0 → 100644
View file @
27bce577
/*-------------------------------------------------------------------------
*
* funcapi.c
* Utility and convenience functions for fmgr functions that return
* sets and/or composite types.
*
* Copyright (c) 2002, PostgreSQL Global Development Group
*
*-------------------------------------------------------------------------
*/
#include "funcapi.h"
#include "catalog/pg_type.h"
#include "utils/syscache.h"
/*
* init_MultiFuncCall
* Create an empty FuncCallContext data structure
* and do some other basic Multi-function call setup
* and error checking
*/
FuncCallContext
*
init_MultiFuncCall
(
PG_FUNCTION_ARGS
)
{
FuncCallContext
*
retval
;
/*
* Bail if we're called in the wrong context
*/
if
(
fcinfo
->
resultinfo
==
NULL
||
!
IsA
(
fcinfo
->
resultinfo
,
ReturnSetInfo
))
elog
(
ERROR
,
"function called in context that does not accept a set result"
);
if
(
fcinfo
->
flinfo
->
fn_extra
==
NULL
)
{
/*
* First call
*/
MemoryContext
oldcontext
;
/* switch to the appropriate memory context */
oldcontext
=
MemoryContextSwitchTo
(
fcinfo
->
flinfo
->
fn_mcxt
);
/*
* allocate space and zero it
*/
retval
=
(
FuncCallContext
*
)
palloc
(
sizeof
(
FuncCallContext
));
MemSet
(
retval
,
0
,
sizeof
(
FuncCallContext
));
/*
* initialize the elements
*/
retval
->
call_cntr
=
0
;
retval
->
max_calls
=
0
;
retval
->
slot
=
NULL
;
retval
->
fctx
=
NULL
;
retval
->
attinmeta
=
NULL
;
retval
->
fmctx
=
fcinfo
->
flinfo
->
fn_mcxt
;
/*
* save the pointer for cross-call use
*/
fcinfo
->
flinfo
->
fn_extra
=
retval
;
/* back to the original memory context */
MemoryContextSwitchTo
(
oldcontext
);
}
else
/* second and subsequent calls */
{
elog
(
ERROR
,
"init_MultiFuncCall may not be called more than once"
);
/* never reached, but keep compiler happy */
retval
=
NULL
;
}
return
retval
;
}
/*
* end_MultiFuncCall
* Clean up after init_MultiFuncCall
*/
void
end_MultiFuncCall
(
PG_FUNCTION_ARGS
,
FuncCallContext
*
funcctx
)
{
MemoryContext
oldcontext
;
/* unbind from fcinfo */
fcinfo
->
flinfo
->
fn_extra
=
NULL
;
/*
* Caller is responsible to free up memory for individual
* struct elements other than att_in_funcinfo and elements.
*/
oldcontext
=
MemoryContextSwitchTo
(
funcctx
->
fmctx
);
if
(
funcctx
->
attinmeta
!=
NULL
)
pfree
(
funcctx
->
attinmeta
);
pfree
(
funcctx
);
MemoryContextSwitchTo
(
oldcontext
);
}
void
get_type_metadata
(
Oid
typeid
,
Oid
*
attinfuncid
,
Oid
*
attelem
)
{
HeapTuple
typeTuple
;
Form_pg_type
typtup
;
typeTuple
=
SearchSysCache
(
TYPEOID
,
ObjectIdGetDatum
(
typeid
),
0
,
0
,
0
);
if
(
!
HeapTupleIsValid
(
typeTuple
))
elog
(
ERROR
,
"get_type_metadata: Cache lookup of type %u failed"
,
typeid
);
typtup
=
(
Form_pg_type
)
GETSTRUCT
(
typeTuple
);
*
attinfuncid
=
typtup
->
typinput
;
*
attelem
=
typtup
->
typelem
;
ReleaseSysCache
(
typeTuple
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment