gadjodilo77
Programmer
Hi,
I have a code wich uploads a csv file into a database table. It works fine if all the fields of the csv file are filled. However when there are a few empty fields it is not going good.
As you can see have I used this code:
<CFSET content=replace(content,";;;",";x;x;","ALL") >
<CFSET content=replace(content,";;",";x;","ALL") >
To fix this problem. It works fine if the empty fields are not fields of the last header. If there is an empty field in the las header it does not work.
(There are 18 expected headers: What if the last field is empty......
How could I make this work? Does anybody have an Idea?
Full code:
<CFFILE ACTION="READ"
VARIABLE="Content"
FILE="#attributes.fileupload_dirroot##Filename#">
<CFSET Nerrors=0>
<!--- --->
<CFSET content=replace(content,"""","","ALL")>
<!--- <CFSET content=replace(content,";;;;;",";x;x;x;x;","ALL") >
<CFSET content=replace(content,";;;;",";x;x;x;","ALL") > --->
<CFSET content=replace(content,";;;",";x;x;","ALL") >
<CFSET content=replace(content,";;",";x;","ALL") >
<!--- <CFSET content=replace(content,"x;#chr(10)##chr(13)#","x;zz#chr(10)##chr(13)#","ALL") > --->
<CFSET Totaan=ListLen(Content, "#attributes.recordscheiding#")>
<!--- Header inlezen --->
<CFLOOP INDEX="Teller" FROM="1" TO="1">
<CFSET Element=ListGetAt(Content, Teller,"#attributes.recordscheiding#")>
<CFSET Expectedlen=listlen(element,";")>
<CFLOOP index="offset" from="1" TO=#listlen(element,";")#>
<CFSET Input=ListGetAt(Element, offset, ";")>
<CFQUERY NAME="getconversie" DATASOURCE="rug">
Select * FROM importconversie_1
Where offset=#offset#
</CFQUERY>
<CFIF getconversie.recordcount>
<CFIF len(trim(getconversie.psnaam)) NEQ len(trim(input))>
<!--- <CFSET FoutIs="<B>Invoer header h=#getconversie.psnaam# i=#Input# niet correct.</B>">
<CFINCLUDE TEMPLATE="/systeem/foutmelding.cfm"> --->
</CFIF>
</cfif>
</cfloop>
</CFLOOP>
<CFQUERY NAME="conversie" DATASOURCE="rug">
SELECT * from importconversie_1
where readvar=1
order by offset
</CFQUERY>
<!--- Data inlezen --->
<CFLOOP INDEX="Teller" FROM=2 TO=#Totaan#>
<CFSET Element=ListGetAt(Content, Teller,"#attributes.recordscheiding#")>
<CFSET CurLen = ListLen(Element, ";")>
<CFIF curlen EQ Expectedlen-1>
<CFSET element="#element#;x">
</CFIF>
<CFSET CurLen = ListLen(Element, ";")>
<CFIF curlen EQ Expectedlen>
<!--- <CFOUTPUT>#curlen#<br></CFOUTPUT> --->
<CFLOOP query="conversie">
<CFSET temp=trim(pimsnaam)>
<CFSET "#temp#"=ListGetAt(Element, offset, ";")>
</cfloop>
<CFINCLUDE template="Fileuploadres.cfm">
<CFELSE>
<CFOUTPUT>len=#curlen#-#element#<br></CFOUTPUT>
</CFIF>
</CFLOOP>
<CFFILE ACTION="Delete"
FILE="#attributes.fileupload_dirroot##Filename#">
I have a code wich uploads a csv file into a database table. It works fine if all the fields of the csv file are filled. However when there are a few empty fields it is not going good.
As you can see have I used this code:
<CFSET content=replace(content,";;;",";x;x;","ALL") >
<CFSET content=replace(content,";;",";x;","ALL") >
To fix this problem. It works fine if the empty fields are not fields of the last header. If there is an empty field in the las header it does not work.
(There are 18 expected headers: What if the last field is empty......
How could I make this work? Does anybody have an Idea?
Full code:
<CFFILE ACTION="READ"
VARIABLE="Content"
FILE="#attributes.fileupload_dirroot##Filename#">
<CFSET Nerrors=0>
<!--- --->
<CFSET content=replace(content,"""","","ALL")>
<!--- <CFSET content=replace(content,";;;;;",";x;x;x;x;","ALL") >
<CFSET content=replace(content,";;;;",";x;x;x;","ALL") > --->
<CFSET content=replace(content,";;;",";x;x;","ALL") >
<CFSET content=replace(content,";;",";x;","ALL") >
<!--- <CFSET content=replace(content,"x;#chr(10)##chr(13)#","x;zz#chr(10)##chr(13)#","ALL") > --->
<CFSET Totaan=ListLen(Content, "#attributes.recordscheiding#")>
<!--- Header inlezen --->
<CFLOOP INDEX="Teller" FROM="1" TO="1">
<CFSET Element=ListGetAt(Content, Teller,"#attributes.recordscheiding#")>
<CFSET Expectedlen=listlen(element,";")>
<CFLOOP index="offset" from="1" TO=#listlen(element,";")#>
<CFSET Input=ListGetAt(Element, offset, ";")>
<CFQUERY NAME="getconversie" DATASOURCE="rug">
Select * FROM importconversie_1
Where offset=#offset#
</CFQUERY>
<CFIF getconversie.recordcount>
<CFIF len(trim(getconversie.psnaam)) NEQ len(trim(input))>
<!--- <CFSET FoutIs="<B>Invoer header h=#getconversie.psnaam# i=#Input# niet correct.</B>">
<CFINCLUDE TEMPLATE="/systeem/foutmelding.cfm"> --->
</CFIF>
</cfif>
</cfloop>
</CFLOOP>
<CFQUERY NAME="conversie" DATASOURCE="rug">
SELECT * from importconversie_1
where readvar=1
order by offset
</CFQUERY>
<!--- Data inlezen --->
<CFLOOP INDEX="Teller" FROM=2 TO=#Totaan#>
<CFSET Element=ListGetAt(Content, Teller,"#attributes.recordscheiding#")>
<CFSET CurLen = ListLen(Element, ";")>
<CFIF curlen EQ Expectedlen-1>
<CFSET element="#element#;x">
</CFIF>
<CFSET CurLen = ListLen(Element, ";")>
<CFIF curlen EQ Expectedlen>
<!--- <CFOUTPUT>#curlen#<br></CFOUTPUT> --->
<CFLOOP query="conversie">
<CFSET temp=trim(pimsnaam)>
<CFSET "#temp#"=ListGetAt(Element, offset, ";")>
</cfloop>
<CFINCLUDE template="Fileuploadres.cfm">
<CFELSE>
<CFOUTPUT>len=#curlen#-#element#<br></CFOUTPUT>
</CFIF>
</CFLOOP>
<CFFILE ACTION="Delete"
FILE="#attributes.fileupload_dirroot##Filename#">