|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.109 2002/11/15 02:50:06 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.110 2002/11/25 21:29:35 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -392,123 +392,89 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull) |
392 | 392 | *Returns the value of a parameter. A param node contains |
393 | 393 | *something like ($.name) and the expression context contains |
394 | 394 | *the current parameter bindings (name = "sam") (age = 34)... |
395 | | - *so our job is to replace the param node with the datum |
396 | | - *containing the appropriate information ("sam"). |
| 395 | + *so our job is to find and return the appropriate datum ("sam"). |
397 | 396 | * |
398 | 397 | *Q: if we have a parameter ($.foo) without a binding, i.e. |
399 | 398 | * there is no (foo = xxx) in the parameter list info, |
400 | 399 | * is this a fatal error or should this be a "not available" |
401 | | - * (in which case we shoud return a Const node with the |
402 | | - *isnull flag) ?-cim 10/13/89 |
403 | | - * |
404 | | - *Minor modification: Param nodes now have an extra field, |
405 | | - *`paramkind' which specifies the type of parameter |
406 | | - *(see params.h). So while searching the paramList for |
407 | | - *a paramname/value pair, we have also to check for `kind'. |
408 | | - * |
409 | | - *NOTE: The last entry in `paramList' is always an |
410 | | - *entry with kind == PARAM_INVALID. |
| 400 | + * (in which case we could return NULL)?-cim 10/13/89 |
411 | 401 | * ---------------------------------------------------------------- |
412 | 402 | */ |
413 | 403 | Datum |
414 | 404 | ExecEvalParam(Param*expression,ExprContext*econtext,bool*isNull) |
415 | 405 | { |
416 | | -char*thisParameterName; |
417 | | -intthisParameterKind=expression->paramkind; |
418 | | -AttrNumberthisParameterId=expression->paramid; |
419 | | -intmatchFound; |
420 | | -ParamListInfoparamList; |
| 406 | +intthisParamKind=expression->paramkind; |
| 407 | +AttrNumberthisParamId=expression->paramid; |
421 | 408 |
|
422 | | -if (thisParameterKind==PARAM_EXEC) |
| 409 | +if (thisParamKind==PARAM_EXEC) |
423 | 410 | { |
| 411 | +/* |
| 412 | + * PARAM_EXEC params (internal executor parameters) are stored in |
| 413 | + * the ecxt_param_exec_vals array, and can be accessed by array index. |
| 414 | + */ |
424 | 415 | ParamExecData*prm; |
425 | 416 |
|
426 | | -prm=&(econtext->ecxt_param_exec_vals[thisParameterId]); |
| 417 | +prm=&(econtext->ecxt_param_exec_vals[thisParamId]); |
427 | 418 | if (prm->execPlan!=NULL) |
428 | 419 | { |
| 420 | +/* Parameter not evaluated yet, so go do it */ |
429 | 421 | ExecSetParamPlan(prm->execPlan,econtext); |
430 | 422 | /* ExecSetParamPlan should have processed this param... */ |
431 | 423 | Assert(prm->execPlan==NULL); |
432 | 424 | } |
433 | 425 | *isNull=prm->isnull; |
434 | 426 | returnprm->value; |
435 | 427 | } |
436 | | - |
437 | | -thisParameterName=expression->paramname; |
438 | | -paramList=econtext->ecxt_param_list_info; |
439 | | - |
440 | | -*isNull= false; |
441 | | - |
442 | | -/* |
443 | | - * search the list with the parameter info to find a matching name. An |
444 | | - * entry with an InvalidName denotes the last element in the array. |
445 | | - */ |
446 | | -matchFound=0; |
447 | | -if (paramList!=NULL) |
| 428 | +else |
448 | 429 | { |
449 | 430 | /* |
450 | | - * search for an entry in 'paramList' that matches the |
451 | | - * `expression'. |
| 431 | + * All other parameter types must be sought in ecxt_param_list_info. |
| 432 | + * NOTE: The last entry in the param array is always an |
| 433 | + * entry with kind == PARAM_INVALID. |
452 | 434 | */ |
453 | | -while (paramList->kind!=PARAM_INVALID&& !matchFound) |
| 435 | +ParamListInfoparamList=econtext->ecxt_param_list_info; |
| 436 | +char*thisParamName=expression->paramname; |
| 437 | +boolmatchFound= false; |
| 438 | + |
| 439 | +if (paramList!=NULL) |
454 | 440 | { |
455 | | -switch (thisParameterKind) |
| 441 | +while (paramList->kind!=PARAM_INVALID&& !matchFound) |
456 | 442 | { |
457 | | -casePARAM_NAMED: |
458 | | -if (thisParameterKind==paramList->kind&& |
459 | | -strcmp(paramList->name,thisParameterName)==0) |
460 | | -matchFound=1; |
461 | | -break; |
462 | | -casePARAM_NUM: |
463 | | -if (thisParameterKind==paramList->kind&& |
464 | | -paramList->id==thisParameterId) |
465 | | -matchFound=1; |
466 | | -break; |
467 | | -casePARAM_OLD: |
468 | | -casePARAM_NEW: |
469 | | -if (thisParameterKind==paramList->kind&& |
470 | | -paramList->id==thisParameterId) |
| 443 | +if (thisParamKind==paramList->kind) |
| 444 | +{ |
| 445 | +switch (thisParamKind) |
471 | 446 | { |
472 | | -matchFound=1; |
473 | | - |
474 | | -/* |
475 | | - * sanity check |
476 | | - */ |
477 | | -if (strcmp(paramList->name,thisParameterName)!=0) |
478 | | -{ |
479 | | -elog(ERROR, |
480 | | -"ExecEvalParam: new/old params with same id & diff names"); |
481 | | -} |
| 447 | +casePARAM_NAMED: |
| 448 | +if (strcmp(paramList->name,thisParamName)==0) |
| 449 | +matchFound= true; |
| 450 | +break; |
| 451 | +casePARAM_NUM: |
| 452 | +if (paramList->id==thisParamId) |
| 453 | +matchFound= true; |
| 454 | +break; |
| 455 | +default: |
| 456 | +elog(ERROR,"ExecEvalParam: invalid paramkind %d", |
| 457 | +thisParamKind); |
482 | 458 | } |
483 | | -break; |
484 | | -default: |
| 459 | +} |
| 460 | +if (!matchFound) |
| 461 | +paramList++; |
| 462 | +}/* while */ |
| 463 | +}/* if */ |
485 | 464 |
|
486 | | -/* |
487 | | - * oops! this is not supposed to happen! |
488 | | - */ |
489 | | -elog(ERROR,"ExecEvalParam: invalid paramkind %d", |
490 | | -thisParameterKind); |
491 | | -} |
492 | | -if (!matchFound) |
493 | | -paramList++; |
494 | | -}/* while */ |
495 | | -}/* if */ |
| 465 | +if (!matchFound) |
| 466 | +{ |
| 467 | +if (thisParamKind==PARAM_NAMED) |
| 468 | +elog(ERROR,"ExecEvalParam: Unknown value for parameter %s", |
| 469 | +thisParamName); |
| 470 | +else |
| 471 | +elog(ERROR,"ExecEvalParam: Unknown value for parameter %d", |
| 472 | +thisParamId); |
| 473 | +} |
496 | 474 |
|
497 | | -if (!matchFound) |
498 | | -{ |
499 | | -/* |
500 | | - * ooops! we couldn't find this parameter in the parameter list. |
501 | | - * Signal an error |
502 | | - */ |
503 | | -elog(ERROR,"ExecEvalParam: Unknown value for parameter %s", |
504 | | -thisParameterName); |
| 475 | +*isNull=paramList->isnull; |
| 476 | +returnparamList->value; |
505 | 477 | } |
506 | | - |
507 | | -/* |
508 | | - * return the value. |
509 | | - */ |
510 | | -*isNull=paramList->isnull; |
511 | | -returnparamList->value; |
512 | 478 | } |
513 | 479 |
|
514 | 480 |
|
|