CFILE and APPEND
2 Message(s) by 2 Author(s) originally posted in cold fusion
| From: Chris |
Date: Friday, May 11, 2007
|
Hi everyone, I need your help with the following issue:
I am using Cold Fusion MX7:
Version 7,0,2,142559 on
Windows 2000 Server
--------------------------------------------
I am getting duplicate
line s written out to my Report.CSV
file .
...and here is an example of the
code in use:
<!--- First I create the file with its columns written out: --->
<CFFILE action="write " file="D:\Foo\Bar\#OutFile#" output="ColA, ColB, ColC, ColD, ColE">
<!--- Then I loop through the query and write out the corrosponding records: --->
<CFLOOP query="ResultsSet">
<CFSET TextLine = trim(numberformat(x.ColA,-99.999999)) & "," &
trim(numberformat(x.ColB,999.999999)) & "," &
#ColC# & "," & #ColD#&","&#ColE#>
<CFFILE action="append" file="D:\Foo\Bar\#OutFile#" output="#TextLine#"
addnewline="yes">
</CFLOOP>NOTE: The above query has been checked during its execution, in that
only a certain number of iterations are performed by the loop.
For example, if I print a line of
text from within the loop to the page,
i.e: Am here
</BR>, I get the correct number of lines printed out as HTML,
which corrosponds to the correct number of records retrieved by the query.
However, the resulting OutFile (report.CSV) file produced is twice the size
with duplicate records in it!
Is this a known bug, and if so, is there a fix for it?
Thanks in advance,
Chris
| From: Denard Springle |
Date: Monday, June 25, 2007
|
<!--- Then I loop through the query and write out the corrosponding records: --->
<CFLOOP query="ResultsSet">
<CFSET TextLine = trim(numberformat(x.ColA,-99.999999)) & "," &
trim(numberformat(x.ColB,999.999999)) & "," &
#ColC# & "," & #ColD#&","&#ColE#>
<CFFILE action="append" file="D:\Foo\Bar\#OutFile#" output="#TextLine#"
addnewline="yes">
</CFLOOP>Not sure why it's giving you double records without seeing all the
code, however, two things you can do:
1. Insert:
<CFOUTPUT>#TextLine#
</CFOUTPUT><br /> before CFFILE append
2. Comment out the CFFILE append (temporarily)
3. Run the script and see if you're getting duplicate results on
screen.
If yes, then there's something wrong with the way you're producing
TextLine.
If no, try creating a single
variable and writing the whole thing at
once, i.e.:
<CFSET textLine = "ColA,ColB,ColC,ColD,ColE" & chr(10)>
<CFLOOP query="ResultsSet">
<CFSET textLine = textLine & trim(numberformat(x.ColA,-99.999999)) &
"," &
trim(numberformat(x.ColB,999.999999)) & "," &
ColC & "," & ColD & "," & ColE & chr(10)>
</CFLOOP>
<CFFILE action="write" file="D:\Foo\Bar\#OutFile#"
output="#textLine#">
The chr(10) is the linefeed
character which should be suitable
for .csv creation, however you can also use chr(13) which is the
carriage return, which should also work for .csv creation (and may
make it easier to read on Windoze).
In short, I have never heard of
ColdFusion having any known issues that'd
cause this behavior (not that I'm the authority or anything
<g>) and
would lean more towards something awry in either the dataset, query or
the way you're constructing the .csv.
Hope this helps!
-- Denny
Next Message: On line vorting