Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

csv array with gaps

Guest
Jun 09, 2008 Jun 09, 2008
I am inserting a csv into a table, but some of the csv "fields" are empty and need to be NULL so that it can move on to the next field. I've tried creating a cfparam with a default of "" but that doesnt work. not sure where to head now... the code works perfectly fine until there is an empty field.

any help here?
thanks.
580
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Jun 12, 2008 Jun 12, 2008
Try just using this.
Translate
Advocate ,
Jun 09, 2008 Jun 09, 2008
Replace this:
<cfloop index="csvCell" list="#csvRecord#" delimiters=",">
<cfset csvArray[variables.csvCellCount] = csvCell>
<cfset csvCellCount = csvCellCount + 1>
</cfloop>

with this:
<cfset csvArray = ListToArray(csvCell,",",true)>
<cfset csvCellCount = ArrayLen(csvArray)>

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_l_21.html#131626
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 10, 2008 Jun 10, 2008
I'm sorry i should have described my situation more clearly. I am using CF7 which ListToArray only takes 1 or 2 parameters. I tried doing ListToArray(csvCell,",")> But, i get the following error in the log...

quote:

Complex object types cannot be converted to simple values.The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values. <p> The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a &lt;CFIF&gt; tag. This was possible in ColdFusion 2.0 but creates an error in later versions.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 10, 2008 Jun 10, 2008
Actually, now that i have tweaked it alittle, it is still just skipping over the blank areas. since i am using cf7, i cannot use the includeEmptyFields parameter. does anyone know how to do this without the parameter.

Thanks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 12, 2008 Jun 12, 2008
Try just using this.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 13, 2008 Jun 13, 2008
LATEST
very cool. it worked better than i had expected... over 480,000 fields in less than 15seconds. thanks elDonrico.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2008 Jun 12, 2008
I approach these matters a bit more methodically. First, for every field that is allowed to be null, I'll do something like this:

if (something)
FieldxNull = true;
else
FieldxNull = false;

Then when I get to the query, I do this
<cfqueryparm null="#FieldxNull#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources