7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.58 1999/07/19 00 :26:15 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.59 1999/09/18 23 :26:37 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -616,8 +616,7 @@ ExecEvalFuncArgs(FunctionCachePtr fcache,
616
616
bool * argIsDone )
617
617
{
618
618
int i ;
619
- bool argIsNull ,
620
- * nullVect ;
619
+ bool * nullVect ;
621
620
List * arg ;
622
621
623
622
nullVect = fcache -> nullVect ;
@@ -631,23 +630,17 @@ ExecEvalFuncArgs(FunctionCachePtr fcache,
631
630
* as arguments but we make an exception in the case of nested dot
632
631
* expressions. We have to watch out for this case here.
633
632
*/
634
- argV [i ]= (Datum )
635
- ExecEvalExpr ((Node * )lfirst (arg ),
636
- econtext ,
637
- & argIsNull ,
638
- argIsDone );
639
-
633
+ argV [i ]= ExecEvalExpr ((Node * )lfirst (arg ),
634
+ econtext ,
635
+ & nullVect [i ],
636
+ argIsDone );
640
637
641
638
if (!(* argIsDone ))
642
639
{
643
640
Assert (i == 0 );
644
641
fcache -> setArg = (char * )argV [0 ];
645
642
fcache -> hasSetArg = true;
646
643
}
647
- if (argIsNull )
648
- nullVect [i ]= true;
649
- else
650
- nullVect [i ]= false;
651
644
i ++ ;
652
645
}
653
646
}
@@ -1108,7 +1101,7 @@ ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull)
1108
1101
*ExecEvalCase
1109
1102
*
1110
1103
*Evaluate a CASE clause. Will have boolean expressions
1111
- *inside the WHEN clauses, and will haveconstants
1104
+ *inside the WHEN clauses, and will haveexpressions
1112
1105
*for results.
1113
1106
*- thomas 1998-11-09
1114
1107
* ----------------------------------------------------------------
@@ -1118,7 +1111,6 @@ ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
1118
1111
{
1119
1112
List * clauses ;
1120
1113
List * clause ;
1121
- CaseWhen * wclause ;
1122
1114
Datum const_value = 0 ;
1123
1115
bool isDone ;
1124
1116
@@ -1127,34 +1119,33 @@ ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
1127
1119
/*
1128
1120
* we evaluate each of the WHEN clauses in turn, as soon as one is
1129
1121
* true we return the corresponding result. If none are true then we
1130
- * return the value of the default clause, or NULL.
1122
+ * return the value of the default clause, or NULL if there is none .
1131
1123
*/
1132
1124
foreach (clause ,clauses )
1133
1125
{
1126
+ CaseWhen * wclause = lfirst (clause );
1134
1127
1135
1128
/*
1136
1129
* We don't iterate over sets in the quals, so pass in an isDone
1137
1130
* flag, but ignore it.
1138
1131
*/
1139
-
1140
- wclause = lfirst (clause );
1141
1132
const_value = ExecEvalExpr ((Node * )wclause -> expr ,
1142
1133
econtext ,
1143
1134
isNull ,
1144
1135
& isDone );
1145
1136
1146
1137
/*
1147
1138
* if we have a true test, then we return the result, since the
1148
- * case statement is satisfied.
1139
+ * case statement is satisfied. A NULL result from the test is
1140
+ * not considered true.
1149
1141
*/
1150
- if (DatumGetInt32 (const_value )!= 0 )
1142
+ if (DatumGetInt32 (const_value )!= 0 && ! * isNull )
1151
1143
{
1152
1144
const_value = ExecEvalExpr ((Node * )wclause -> result ,
1153
1145
econtext ,
1154
1146
isNull ,
1155
1147
& isDone );
1156
1148
return (Datum )const_value ;
1157
-
1158
1149
}
1159
1150
}
1160
1151
@@ -1318,28 +1309,22 @@ ExecQualClause(Node *clause, ExprContext *econtext)
1318
1309
bool isNull ;
1319
1310
bool isDone ;
1320
1311
1321
- /* when there is a null clause, consider the qualification tobe true */
1312
+ /* when there is a null clause, consider the qualification tofail */
1322
1313
if (clause == NULL )
1323
1314
return true;
1324
1315
1325
1316
/*
1326
1317
* pass isDone, but ignore it.We don't iterate over multiple returns
1327
1318
* in the qualifications.
1328
1319
*/
1329
- expr_value = (Datum )
1330
- ExecEvalExpr (clause ,econtext ,& isNull ,& isDone );
1320
+ expr_value = ExecEvalExpr (clause ,econtext ,& isNull ,& isDone );
1331
1321
1332
1322
/*
1333
- * this is interesting behaviour here.When a clause evaluates to
1334
- * null, then we consider this as passing the qualification. it seems
1335
- * kind of like, if the qual is NULL, then there's no qual..
1323
+ * remember, we return true when the qualification fails;
1324
+ * NULL is considered failure.
1336
1325
*/
1337
1326
if (isNull )
1338
1327
return true;
1339
-
1340
- /*
1341
- * remember, we return true when the qualification fails..
1342
- */
1343
1328
if (DatumGetInt32 (expr_value )== 0 )
1344
1329
return true;
1345
1330