Perplexed and Confused with CSV conversion from Query

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Perplexed and Confused with CSV conversion from Query

    I'm having a little trouble converting a query object into a CSV file.
    Everyplace I've ever seen it done, makes a loop and assumes that the COLUMN
    NAMES will always be the same. The column names in the query objects that I
    want to convert to a CSV file are NOT always the same. Is there a way that I
    can loop through the QUERY.ColumnList property and insert POUNDSIGNS around
    each word which can be utilized as a dynamic statement later-on in my code?

    Tomdogggg Guest

  2. Similar Questions and Discussions

    1. Confused with FCS And FMS
      I am little confused with the terminology FCS And FMS, I cant see which are the differences.
    2. Problem with this query string conversion script
      I read the article titled A Cure for Arachnophobia by Ben Forta in the CFDJ (http://coldfusion.sys-con.com/read/41702_p.htm). In it was this script...
    3. OT: :confused;
      I have been seeing this all over the board, what the heck is it? Is it an emoticon? Thanks, Drew
    4. "Operation must use an updateable query".- after conversion to NTFS
      You need to set NTFS permissions for IUSR (which weren't in place, obviously, when using FAT32). Right-click the folder, hit sharing and...
    5. Confused?
      Hi Everyone, I'm having a bit of a problem and was wondering if anyone would be able to tell me what I'm doing wrong. the URL to the site I'm...
  3. #2

    Default Re: Perplexed and Confused with CSV conversion fromQuery

    Everyplace I've ever seen it done, makes a loop and assumes that the COLUMN
    NAMES will always be the same.

    What do you mean by "assumes ...the column names will always be the same"?
    What are you trying to do exactly?

    mxstu Guest

  4. #3

    Default Re: Perplexed and Confused with CSV conversion fromQuery

    Ok, let's say I'm making a QUERY object into a comma-separated-text(we'll
    assume the query is called 'myQuery'):

    <cffile action="write"
    nameconflict="overwrite"
    file="file.csv'"
    output="#myQuery.ColumnList#">
    <cfloop query="myQuery">
    <cffile action="append"
    file="file.csv"
    output="#column1#, #column2#, #column3#, etc...">
    </cfloop>

    The problem I'm having, stems from the fact that the columns going into the
    comma-separated-text, are assumed to be column1, column2, and column3: What if
    this wasn't the case, what if there was NO column1? It would throw an error,
    and not make the file correctly. I need to have a dynamically created list of
    ALL of the columns in the query so that I can replace the partially dynamic,
    but not TOTALLY dynamic statement of 'output="#column1#, #column2#, #column3#,
    etc...">' into a comma separated list of the COLUMN NAMES with POUNDSIGNS
    around each name.

    Tomdogggg Guest

  5. #4

    Default Re: Perplexed and Confused with CSV conversion fromQuery

    Something along the lines of...



    <cfset filepath = "#GetDirectoryFromPath(ExpandPath("*.*"))#\file.cs v">
    <cfset columns = qEmployees.ColumnList>

    <cffile action="write"
    nameconflict="overwrite"
    file="#filepath#"
    output="#columns#">

    <cfoutput query="qEmployees">
    <cfset record = "">
    <cfloop list="#columns#" delimiters="," index="colName">
    <cfset colVal = qEmployees[VARIABLES.colName]>
    #colName#=#colVal#,
    <cfset record = record & "#colVal#,">
    </cfloop>
    <cffile action="append"
    file="#filepath#"
    output="#record#">
    </cfoutput>

    BSterner Guest

  6. #5

    Default Re: Perplexed and Confused with CSV conversion fromQuery

    Chr(35) Nice job.
    Tomdogggg Guest

  7. #6

    Default Re: Perplexed and Confused with CSV conversion fromQuery

    Actually, double pound signs would work too and be a better approach.

    <cfset record = record & "###colName###=#colVal#,">
    BSterner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139