Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c2fca1

Browse files
committed
Un-break exec_move_row() for case that a NULL tuple and tupdesc are
passed, which occurs when no rows are retrieved by a SELECT.Mea maxima culpa ... I should have caught this.
1 parent7d7ab8a commit8c2fca1

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.41 2001/04/30 20:05:40 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.41.2.1 2001/05/08 01:02:03 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1344,6 +1344,8 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt)
13441344
*/
13451345
exec_run_select(estate,stmt->query,0);
13461346
n=SPI_processed;
1347+
tuptab=SPI_tuptable;
1348+
SPI_tuptable=NULL;
13471349

13481350
/*
13491351
* If the query didn't return any row, set the target to NULL and
@@ -1363,9 +1365,6 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt)
13631365
/*
13641366
* Now do the loop
13651367
*/
1366-
tuptab=SPI_tuptable;
1367-
SPI_tuptable=NULL;
1368-
13691368
for (i=0;i<n;i++)
13701369
{
13711370

@@ -1445,6 +1444,8 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt)
14451444
*/
14461445
exec_run_select(estate,stmt->query,1);
14471446
n=SPI_processed;
1447+
tuptab=SPI_tuptable;
1448+
SPI_tuptable=NULL;
14481449

14491450
/*
14501451
* If the query didn't return any row, set the target to NULL and
@@ -1459,9 +1460,6 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt)
14591460
/*
14601461
* Put the result into the target and set found to true
14611462
*/
1462-
tuptab=SPI_tuptable;
1463-
SPI_tuptable=NULL;
1464-
14651463
exec_move_row(estate,rec,row,tuptab->vals[0],tuptab->tupdesc);
14661464

14671465
exec_set_found(estate, true);
@@ -2053,6 +2051,8 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
20532051
pfree(querystr);
20542052

20552053
n=SPI_processed;
2054+
tuptab=SPI_tuptable;
2055+
SPI_tuptable=NULL;
20562056

20572057
/*
20582058
* If the query didn't return any row, set the target to NULL and
@@ -2072,9 +2072,6 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
20722072
/*
20732073
* Now do the loop
20742074
*/
2075-
tuptab=SPI_tuptable;
2076-
SPI_tuptable=NULL;
2077-
20782075
for (i=0;i<n;i++)
20792076
{
20802077

@@ -2322,9 +2319,9 @@ exec_eval_expr(PLpgSQL_execstate * estate,
23222319
* Check that the expression returned one single Datum
23232320
*/
23242321
if (SPI_processed>1)
2325-
elog(ERROR,"query \"%s\"didn't return a single value",expr->query);
2322+
elog(ERROR,"query \"%s\"returned more than one row",expr->query);
23262323
if (SPI_tuptable->tupdesc->natts!=1)
2327-
elog(ERROR,"query \"%s\"didn't return a single value",expr->query);
2324+
elog(ERROR,"query \"%s\"returned more than one column",expr->query);
23282325

23292326
/*
23302327
* Return the result and its type
@@ -2630,14 +2627,14 @@ exec_move_row(PLpgSQL_execstate * estate,
26302627
if (i<t_natts)
26312628
{
26322629
value=SPI_getbinval(tup,tupdesc,i+1,&isnull);
2630+
valtype=SPI_gettypeid(tupdesc,i+1);
26332631
}
26342632
else
26352633
{
26362634
value= (Datum)0;
26372635
isnull= true;
2636+
valtype=InvalidOid;
26382637
}
2639-
/* tupdesc should have entries for all columns I expect... */
2640-
valtype=SPI_gettypeid(tupdesc,i+1);
26412638

26422639
exec_assign_value(estate,estate->datums[row->varnos[i]],
26432640
value,valtype,&isnull);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp