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
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide 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
...
@@ -48,7 +48,7 @@ static void _SPI_fetch(FetchStmt * stmt);
...
@@ -48,7 +48,7 @@ static void _SPI_fetch(FetchStmt * stmt);
#endif
#endif
static
int
static
int
_SPI_execute_plan
(
_SPI_plan
*
plan
,
_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_CURCXT 0
#define _SPI_CPLAN_PROCXT 1
#define _SPI_CPLAN_PROCXT 1
...
@@ -199,7 +199,7 @@ SPI_exec(char *src, int tcount)
...
@@ -199,7 +199,7 @@ SPI_exec(char *src, int tcount)
}
}
int
int
SPI_execp
(
void
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
)
SPI_execp
(
void
*
plan
,
Datum
*
Values
,
char
*
Nulls
,
int
tcount
)
{
{
int
res
;
int
res
;
...
@@ -278,11 +278,108 @@ SPI_saveplan(void *plan)
...
@@ -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
int
SPI_fnumber
(
TupleDesc
tupdesc
,
char
*
fname
)
SPI_fnumber
(
TupleDesc
tupdesc
,
char
*
fname
)
{
{
int
res
;
int
res
;
for
(
res
=
0
;
res
<
tupdesc
->
natts
;
res
++
)
for
(
res
=
0
;
res
<
tupdesc
->
natts
;
res
++
)
{
{
if
(
strcasecmp
(
tupdesc
->
attrs
[
res
]
->
attname
.
data
,
fname
)
==
0
)
if
(
strcasecmp
(
tupdesc
->
attrs
[
res
]
->
attname
.
data
,
fname
)
==
0
)
...
@@ -333,7 +430,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
...
@@ -333,7 +430,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Datum
Datum
SPI_getbinval
(
HeapTuple
tuple
,
TupleDesc
tupdesc
,
int
fnumber
,
bool
*
isnull
)
SPI_getbinval
(
HeapTuple
tuple
,
TupleDesc
tupdesc
,
int
fnumber
,
bool
*
isnull
)
{
{
Datum
val
;
Datum
val
;
*
isnull
=
true
;
*
isnull
=
true
;
SPI_result
=
0
;
SPI_result
=
0
;
...
@@ -539,7 +636,7 @@ _SPI_execute(char *src, int tcount, _SPI_plan * plan)
...
@@ -539,7 +636,7 @@ _SPI_execute(char *src, int tcount, _SPI_plan * plan)
}
}
static
int
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
;
QueryTreeList
*
queryTree_list
=
plan
->
qtlist
;
List
*
planTree_list
=
plan
->
ptlist
;
List
*
planTree_list
=
plan
->
ptlist
;
...
@@ -591,7 +688,7 @@ _SPI_execute_plan(_SPI_plan * plan, Datum *Values, char *Nulls, int tcount)
...
@@ -591,7 +688,7 @@ _SPI_execute_plan(_SPI_plan * plan, Datum *Values, char *Nulls, int tcount)
{
{
paramLI
->
kind
=
PARAM_NUM
;
paramLI
->
kind
=
PARAM_NUM
;
paramLI
->
id
=
k
+
1
;
paramLI
->
id
=
k
+
1
;
paramLI
->
isnull
=
(
Nulls
!=
NULL
&&
Nulls
[
k
]
!
=
'n'
);
paramLI
->
isnull
=
(
Nulls
&&
Nulls
[
k
]
=
=
'n'
);
paramLI
->
value
=
Values
[
k
];
paramLI
->
value
=
Values
[
k
];
}
}
paramLI
->
kind
=
PARAM_INVALID
;
paramLI
->
kind
=
PARAM_INVALID
;
...
...
This diff is collapsed.
Click to expand it.
src/include/executor/spi.h
+
5
−
1
View file @
4587547f
...
@@ -73,10 +73,14 @@ extern int SPI_result;
...
@@ -73,10 +73,14 @@ extern int SPI_result;
extern
int
SPI_connect
(
void
);
extern
int
SPI_connect
(
void
);
extern
int
SPI_finish
(
void
);
extern
int
SPI_finish
(
void
);
extern
int
SPI_exec
(
char
*
src
,
int
tcount
);
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_prepare
(
char
*
src
,
int
nargs
,
Oid
*
argtypes
);
extern
void
*
SPI_saveplan
(
void
*
plan
);
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
int
SPI_fnumber
(
TupleDesc
tupdesc
,
char
*
fname
);
extern
char
*
SPI_fname
(
TupleDesc
tupdesc
,
int
fnumber
);
extern
char
*
SPI_fname
(
TupleDesc
tupdesc
,
int
fnumber
);
extern
char
*
SPI_getvalue
(
HeapTuple
tuple
,
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