|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.11 1996/12/07 04:38:10 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.12 1997/01/22 01:43:19 momjian Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -367,10 +367,50 @@ make_op(char *opname, Node *ltree, Node *rtree) |
367 | 367 | left=NULL; |
368 | 368 |
|
369 | 369 | }else { |
370 | | - |
| 370 | +char*outstr; |
| 371 | +Oidinfunc,outfunc; |
| 372 | +Typenewtype; |
| 373 | + |
| 374 | +#defineCONVERTABLE_TYPE(t) ((t) == INT2OID || \ |
| 375 | +(t) == INT4OID || \ |
| 376 | +(t) == OIDOID || \ |
| 377 | +(t) == FLOAT4OID || \ |
| 378 | +(t) == FLOAT8OID) |
| 379 | + |
371 | 380 | /* binary operator */ |
372 | 381 | ltypeId= (ltree==NULL) ?UNKNOWNOID :exprType(ltree); |
373 | 382 | rtypeId= (rtree==NULL) ?UNKNOWNOID :exprType(rtree); |
| 383 | + |
| 384 | +/* convert constant when using a const of a numeric type |
| 385 | + and a non-const of another numeric type */ |
| 386 | +if (CONVERTABLE_TYPE(ltypeId)&&nodeTag(ltree)!=T_Const&& |
| 387 | +CONVERTABLE_TYPE(rtypeId)&&nodeTag(rtree)==T_Const&& |
| 388 | + !((Const*)rtree)->constiscast) { |
| 389 | +outfunc=typeid_get_retoutfunc(rtypeId); |
| 390 | +infunc=typeid_get_retinfunc(ltypeId); |
| 391 | +outstr= (char*)fmgr(outfunc, ((Const*)rtree)->constvalue); |
| 392 | + ((Const*)rtree)->constvalue= (Datum)fmgr(infunc,outstr); |
| 393 | +pfree(outstr); |
| 394 | + ((Const*)rtree)->consttype=rtypeId=ltypeId; |
| 395 | +newtype=get_id_type(rtypeId); |
| 396 | + ((Const*)rtree)->constlen=tlen(newtype); |
| 397 | + ((Const*)rtree)->constbyval=tbyval(newtype); |
| 398 | +} |
| 399 | + |
| 400 | +if (CONVERTABLE_TYPE(rtypeId)&&nodeTag(rtree)!=T_Const&& |
| 401 | +CONVERTABLE_TYPE(ltypeId)&&nodeTag(ltree)==T_Const&& |
| 402 | + !((Const*)ltree)->constiscast) { |
| 403 | +outfunc=typeid_get_retoutfunc(ltypeId); |
| 404 | +infunc=typeid_get_retinfunc(rtypeId); |
| 405 | +outstr= (char*)fmgr(outfunc, ((Const*)ltree)->constvalue); |
| 406 | + ((Const*)ltree)->constvalue= (Datum)fmgr(infunc,outstr); |
| 407 | +pfree(outstr); |
| 408 | + ((Const*)ltree)->consttype=ltypeId=rtypeId; |
| 409 | +newtype=get_id_type(ltypeId); |
| 410 | + ((Const*)ltree)->constlen=tlen(newtype); |
| 411 | + ((Const*)ltree)->constbyval=tbyval(newtype); |
| 412 | +} |
| 413 | + |
374 | 414 | temp=oper(opname,ltypeId,rtypeId); |
375 | 415 | opform= (OperatorTupleForm)GETSTRUCT(temp); |
376 | 416 | left=make_operand(opname,ltree,ltypeId,opform->oprleft); |
@@ -654,17 +694,18 @@ make_const(Value *value) |
654 | 694 | elog(NOTICE,"unknown type : %d\n",nodeTag(value)); |
655 | 695 |
|
656 | 696 | /* null const */ |
657 | | -con=makeConst(0,0, (Datum)NULL,TRUE,0, FALSE); |
| 697 | +con=makeConst(0,0, (Datum)NULL,true, false, false, false); |
658 | 698 | returncon; |
659 | 699 | } |
660 | 700 | } |
661 | 701 |
|
662 | 702 | con=makeConst(typeid(tp), |
663 | 703 | tlen(tp), |
664 | 704 | val, |
665 | | -FALSE, |
| 705 | +false, |
666 | 706 | tbyval(tp), |
667 | | - FALSE);/* not a set */ |
| 707 | + false,/* not a set */ |
| 708 | + false); |
668 | 709 |
|
669 | 710 | return (con); |
670 | 711 | } |
|