Concerning DB*ELEMENT

Joel Palmius <[email protected]>
Newsgroups gmane.comp.apache.mod-survey.general
Message-ID <[email protected]>
After the chat about data awareness, work has progressed steadily 
concerning implementation of dynamic array structures. Personally, I've 
been working on the Session/API and DB*ELEMENT structures, while BugAnt 
has sent a stream of patches for enhancing the IMPORT tag and breaking out 
DB operations to a more sane code structure.

Currently, support should be considered rather experimental, but some 
aspects of the data awareness already works in the CVS. These things can 
significanly shorten the source of a survey.

For example, imagine you want a list box with years ranging from 1900 to 
2000:

   <SURVEY TITLE="dbtest">

     {&
       my(@ylabels,@yvalues);
       for(my($i) = 1900; $i <= 2000; $i++)
       {
         push(@ylabels,"Year $i");
         push(@yvalues,$i-1900);
       }
       $session->setArrayValue("ylabels",\@ylabels);
       $session->setArrayValue("yvalues",\@yvalues);
     &}

     <LIST NAME="age" CAPTION="When were you born?">
       <DBLISTELEMENT CAPTIONARRAY="ylabels" VALUEARRAY="yvalues" />
     </LIST>

   </SURVEY>

Or that you have an array of options you want to use in several CHOICE 
blocks:

   <SURVEY TITLE="dbtest">

     {&
       my(@fruit) = ("Banana","Apple","Orange","Pear","Grape");
       $session->setArrayValue("fruit",\@fruit);
     &}

     <CHOICE NAME="like" CAPTION="Which fruit do you like the best?">
       <DBCHOICEELEMENT CAPTIONARRAY="fruit" />
     </CHOICE>

     <CHOICE NAME="notlike" CAPTION="Which fruit do you dislike the most?">
       <DBCHOICEELEMENT CAPTIONARRAY="fruit" />
     </CHOICE>

     <CHOICE NAME="often" CAPTION="Which fruit do you most often eat?">
       <DBCHOICEELEMENT CAPTIONARRAY="fruit" />
     </CHOICE>

   </SURVEY>

Of course, the real power of the DB*ELEMENT structures will be unveiled 
once BugAnt finishes the work with importing arrays from DBI databases.

As a side note, there are several things which do NOT work in the CVS too, 
so you should currently not try this on a production server.

   // Joel
Skickat av Joel Palmius <[email protected]>
till survey-discussion
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.