
/*     
 *      FILE
 *     	rules/linf/rvarious.l
 *     
 *      DESCRIPTION
 *     	"Various" routines.
 *     
 */
defvar (_RCS_rvarious_,"$Header: rvarious.l,v 1.2 89/02/21 01:24:08 hirohama Exp $");

/*     
 *      EXPORTS
 *     	substituteTupleIntoPlan
 *     	findValueAndType
 */

/*    
 *     substituteTupleIntoPlan
 *    
 *     Given a tuple and a plan with paramaeters of the type $.attname
 *     substitute the correct values into the plan.o 
 *    
 */
LispValue
substituteTupleIntoPlan (oldPlanoldPlan,tupletuple,relationrelation,relIdrelId,bufferPagebufferPage)
LispValue oldPlan,tuple,relation,relId,bufferPage ;
{
	/* XXX - prog form, maybe incorrect */
	LispValue param_list = LispNil;
	LispValue value_list = LispNil;
	LispValue do_res1 = LispNil;
	param_list = find_parameters (oldPlan);
	;
	value_list = nil;
	;
	do_res1 = foreach (oneParam, param_listvalue_list) {
		value_list = cons (findValueAndType (tuple,relation,relId,oneParam,bufferPage),value_list);
		;
		;
		/*    (if (not (null do-res1)) (return do-res1)) */
		;
		return (substitute_parameters (oldPlan,value_list));
		;
	}

	/*    
 *     findValueAndType
 *     Given a reldesc, a tuple and the name of an attribute of the tuple,
 *     returns a list with 3 elements:
 *    	1) the name of the attibute (exactly the same as the argument)
 *    	2) the type of the attribute
 *    	3) the value of the attribute
 *    
 */
	LispValue
	    findValueAndType (tupletuple,relDescrelDesc,relIdrelId,attrNameattrName,bufferPagebufferPage)
	    LispValue tuple,relDesc,relId,attrName,bufferPage ;
	{
		/* XXX - prog form, maybe incorrect */
		LispValue attrNumber = LispNil;
		LispValue attrType = LispNil;
		LispValue attrValue = LispNil;
		attrNumber = get_attnum (relId,attrName);
		;
		attrType = get_atttype (relId,attrNumber);
		;
		attrValue = amgetattr (tuple,bufferPage,attrNumber,ExecGetTypeInfo (relDesc),0);
		;
		return (list (attrName,attrType,attrValue));
		;
	}
