Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
4587547f
Commit
4587547f
authored
27 years ago
by
Vadim B. Mikheev
Browse files
Options
Downloads
Patches
Plain Diff
Added: SPI_copytuple() & SPI_modifytuple()
parent
a40a546e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/backend/executor/spi.c
+103
-6
103 additions, 6 deletions
src/backend/executor/spi.c
src/include/executor/spi.h
+5
-1
5 additions, 1 deletion
src/include/executor/spi.h
with
108 additions
and
7 deletions
src/backend/executor/spi.c
+
103
−
6
View file @
4587547f
...
...
@@ -278,6 +278,103 @@ 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
)
{
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
src/include/executor/spi.h
+
5
−
1
View file @
4587547f
...
...
@@ -77,6 +77,10 @@ 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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment