macromedia.coldfusion.cfml_general_discussion
[Top] [All Lists]

Re: Cffunction and how to ? can someone explain the code to me line by

Subject: Re: Cffunction and how to ? can someone explain the code to me line by line
From: Ian Skinner
Date: Thu, 23 Aug 2007 10:16:02 -0700
Newsgroups: macromedia.coldfusion.cfml_general_discussion


silviasalsa wrote:
thanks

 but line by line

what is if(ArrayLen(Arguments) GTE 2) qualifier = Arguments[2];
   if(ArrayLen(Arguments) GTE 3 AND Len(Arguments[3])) columns = Arguments[3];
   returnValue[1] = ListQualify(columns, qualifier);
   ArrayResize(returnValue, query.recordcount + 1);
   columns = ListToArray(columns);
   for(i = 1; i LTE query.recordcount; i = i + 1)
   {
     rowValue = ArrayNew(1);
     ArrayResize(rowValue, ArrayLen(columns));
     for(j = 1; j LTE ArrayLen(columns); j = j + 1)
       rowValue[j] = qualifier & query[columns[j]][i] & qualifier;
     returnValue[i + 1] = ArrayToList(rowValue);
   }            
   returnValue = ArrayToList(returnValue, Chr(13));
   return returnValue;
 }

 thanks

Apparently this UDF takes two optional parameters so that one can define (A) a text "qualifier" to use in the CSV file, this is usually the single quote|tick ['] mark - but sometimes one wants this to be a different character and (B) what columns to use in the output in case one does not want to use all the columns in the record set in the outputted CSV file.

The if statements are checking for these optional parameters and if found setting the values in them to internal variables. These variables are then used in the rest of the logic to create the CSV output.

HTH
Ian

<Prev in Thread] Current Thread [Next in Thread>