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
4587547f
Commit
4587547f
authored
Sep 12, 1997
by
Vadim B. Mikheev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added: SPI_copytuple() & SPI_modifytuple()
parent
a40a546e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
7 deletions
+108
-7
src/backend/executor/spi.c
src/backend/executor/spi.c
+103
-6
src/include/executor/spi.h
src/include/executor/spi.h
+5
-1
No files found.
src/backend/executor/spi.c
View file @
4587547f
...
...
@@ -48,7 +48,7 @@ static void _SPI_fetch(FetchStmt * stmt);
#endif
static
int
_SPI_execute_plan
(
_SPI_plan
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
);
Datum
*
Values
,
char
*
Nulls
,
int
tcount
);
#define _SPI_CPLAN_CURCXT 0
#define _SPI_CPLAN_PROCXT 1
...
...
@@ -199,7 +199,7 @@ SPI_exec(char *src, int tcount)
}
int
SPI_execp
(
void
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
)
SPI_execp
(
void
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
)
{
int
res
;
...
...
@@ -278,11 +278,108 @@ SPI_saveplan(void *plan)
}
HeapTuple
SPI_copytuple
(
HeapTuple
tuple
)
{
MemoryContext
oldcxt
=
NULL
;
HeapTuple
ctuple
;
if
(
tuple
==
NULL
)
{
SPI_result
=
SPI_ERROR_ARGUMENT
;
return
(
NULL
);
}
if
(
_SPI_curid
+
1
==
_SPI_connected
)
/* connected */
{
if
(
_SPI_current
!=
&
(
_SPI_stack
[
_SPI_curid
+
1
]))
elog
(
FATAL
,
"SPI: stack corrupted"
);
oldcxt
=
MemoryContextSwitchTo
(
_SPI_current
->
savedcxt
);
}
ctuple
=
heap_copytuple
(
tuple
);
if
(
oldcxt
)
MemoryContextSwitchTo
(
oldcxt
);
return
(
ctuple
);
}
HeapTuple
SPI_modifytuple
(
Relation
rel
,
HeapTuple
tuple
,
int
natts
,
int
*
attnum
,
Datum
*
Values
,
char
*
Nulls
)
{
MemoryContext
oldcxt
=
NULL
;
HeapTuple
mtuple
;
int
numberOfAttributes
;
uint8
infomask
;
Datum
*
v
;
char
*
n
;
bool
isnull
;
int
i
;
if
(
rel
==
NULL
||
tuple
==
NULL
||
natts
<=
0
||
attnum
==
NULL
||
Values
==
NULL
)
{
SPI_result
=
SPI_ERROR_ARGUMENT
;
return
(
NULL
);
}
if
(
_SPI_curid
+
1
==
_SPI_connected
)
/* connected */
{
if
(
_SPI_current
!=
&
(
_SPI_stack
[
_SPI_curid
+
1
]))
elog
(
FATAL
,
"SPI: stack corrupted"
);
oldcxt
=
MemoryContextSwitchTo
(
_SPI_current
->
savedcxt
);
}
SPI_result
=
0
;
numberOfAttributes
=
rel
->
rd_att
->
natts
;
v
=
(
Datum
*
)
palloc
(
numberOfAttributes
*
sizeof
(
Datum
));
n
=
(
char
*
)
palloc
(
numberOfAttributes
*
sizeof
(
char
));
/* fetch old values and nulls */
for
(
i
=
0
;
i
<
numberOfAttributes
;
i
++
)
{
v
[
i
]
=
heap_getattr
(
tuple
,
InvalidBuffer
,
i
+
1
,
rel
->
rd_att
,
&
isnull
);
n
[
i
]
=
(
isnull
)
?
'n'
:
' '
;
}
/* replace values and nulls */
for
(
i
=
0
;
i
<
natts
;
i
++
)
{
if
(
attnum
[
i
]
<=
0
||
attnum
[
i
]
>
numberOfAttributes
)
break
;
v
[
attnum
[
i
]
-
1
]
=
Values
[
i
];
n
[
attnum
[
i
]
-
1
]
=
(
Nulls
&&
Nulls
[
i
]
==
'n'
)
?
'n'
:
' '
;
}
if
(
i
==
natts
)
/* no errors in attnum[] */
{
mtuple
=
heap_formtuple
(
rel
->
rd_att
,
v
,
n
);
infomask
=
mtuple
->
t_infomask
;
memmove
(
&
(
mtuple
->
t_ctid
),
&
(
tuple
->
t_ctid
),
((
char
*
)
&
(
tuple
->
t_hoff
)
-
(
char
*
)
&
(
tuple
->
t_ctid
)));
mtuple
->
t_infomask
=
infomask
;
mtuple
->
t_natts
=
numberOfAttributes
;
}
else
{
mtuple
=
NULL
;
SPI_result
=
SPI_ERROR_NOATTRIBUTE
;
}
pfree
(
v
);
pfree
(
n
);
if
(
oldcxt
)
MemoryContextSwitchTo
(
oldcxt
);
return
(
mtuple
);
}
int
SPI_fnumber
(
TupleDesc
tupdesc
,
char
*
fname
)
{
int
res
;
for
(
res
=
0
;
res
<
tupdesc
->
natts
;
res
++
)
{
if
(
strcasecmp
(
tupdesc
->
attrs
[
res
]
->
attname
.
data
,
fname
)
==
0
)
...
...
@@ -333,7 +430,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Datum
SPI_getbinval
(
HeapTuple
tuple
,
TupleDesc
tupdesc
,
int
fnumber
,
bool
*
isnull
)
{
Datum
val
;
Datum
val
;
*
isnull
=
true
;
SPI_result
=
0
;
...
...
@@ -539,7 +636,7 @@ _SPI_execute(char *src, int tcount, _SPI_plan * plan)
}
static
int
_SPI_execute_plan
(
_SPI_plan
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
)
_SPI_execute_plan
(
_SPI_plan
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
)
{
QueryTreeList
*
queryTree_list
=
plan
->
qtlist
;
List
*
planTree_list
=
plan
->
ptlist
;
...
...
@@ -591,7 +688,7 @@ _SPI_execute_plan(_SPI_plan * plan, Datum *Values, char *Nulls, int tcount)
{
paramLI
->
kind
=
PARAM_NUM
;
paramLI
->
id
=
k
+
1
;
paramLI
->
isnull
=
(
Nulls
!=
NULL
&&
Nulls
[
k
]
!
=
'n'
);
paramLI
->
isnull
=
(
Nulls
&&
Nulls
[
k
]
=
=
'n'
);
paramLI
->
value
=
Values
[
k
];
}
paramLI
->
kind
=
PARAM_INVALID
;
...
...
src/include/executor/spi.h
View file @
4587547f
...
...
@@ -73,10 +73,14 @@ extern int SPI_result;
extern
int
SPI_connect
(
void
);
extern
int
SPI_finish
(
void
);
extern
int
SPI_exec
(
char
*
src
,
int
tcount
);
extern
int
SPI_execp
(
void
*
plan
,
Datum
*
values
,
char
*
Nulls
,
int
tcount
);
extern
int
SPI_execp
(
void
*
plan
,
Datum
*
values
,
char
*
Nulls
,
int
tcount
);
extern
void
*
SPI_prepare
(
char
*
src
,
int
nargs
,
Oid
*
argtypes
);
extern
void
*
SPI_saveplan
(
void
*
plan
);
extern
HeapTuple
SPI_copytuple
(
HeapTuple
tuple
);
extern
HeapTuple
SPI_modifytuple
(
Relation
rel
,
HeapTuple
tuple
,
int
natts
,
int
*
attnum
,
Datum
*
Values
,
char
*
Nulls
);
extern
int
SPI_fnumber
(
TupleDesc
tupdesc
,
char
*
fname
);
extern
char
*
SPI_fname
(
TupleDesc
tupdesc
,
int
fnumber
);
extern
char
*
SPI_getvalue
(
HeapTuple
tuple
,
TupleDesc
tupdesc
,
int
fnumber
);
...
...
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