;;;;
;;;; 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;
;;;
(defun substituteTupleIntoPlan (oldPlan tuple relation relId bufferPage)
  (prog (param-list value-list do-res1)
	(setq param-list (find-parameters oldPlan))
	(setq value-list nil)
	(setq do-res1 (dolist (oneParam param-list value-list)
			      (setq 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
;;;
(defun findValueAndType (tuple relDesc relId attrName bufferPage)
  (prog (attrNumber attrType attrValue)
	(setq attrNumber (get_attnum relId attrName))
	(setq attrType (get_atttype relId attrNumber))
	(setq attrValue (amgetattr tuple
				   bufferPage
				   attrNumber
				   (ExecGetTypeInfo relDesc)
				   0))
	(return (list attrName attrType attrValue))))
