cf7: cfhttp to create a query from a file

Discussion in 'Programming' started by gesangbaer, May 27, 2010.

  1. #1
    Hey there. I can't seem to figure out an issue I'm having with cfhttp to make a query.

    I've got a very short tab delimited file (as a test) as follows

    Number   Text
    0       text for question one
    1       Some ext for question 2, and more
    ...
    Code (markup):
    My cfhttp command is as follows

    <cfhttp 
                    	method="Get" 
                        url="thefile.txt" 
                        textqualifier="" 
                        delimiter="#chr(9)#"
                        name="questions"
                        >
    Code (markup):
    I get the following error

     The column name "
    Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
     
    Code (markup):
    If I remove the name="" then I get an error later when trying to reference the query I've made.
    If I add in a columns specifier, then I get an error about having the wrong number of columns, no matter how many columns I specify.

    Any ideas would be appreciated.

    I'm using coldfusion 7. This is my frist real experience with CF here at work. Normally I'm using javascript.

    Thanks!
     
    gesangbaer, May 27, 2010 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Error messages aren't always 100% accurate. But does your file follow the rules above? Usually you see that error when the file column headers contain bad characters. Examples of bad headers....

    _Number Text
    Num(ber Text
    #umber T ext

    Also, it doesn't look like you need the "textqualifier" attribute. Since the values in your test file aren't quoted or anything.
     
    cfStarlight, May 27, 2010 IP
  3. gesangbaer

    gesangbaer Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm using the exact headers I listed above. The first line of the file is

    Number Text

    I thought I needed to specify textqualifier="" since the default is a " and it might then expect

    "1" "Text for the first question, and such"

    Anyone else? Does this make sense?
     
    gesangbaer, May 27, 2010 IP
  4. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    My bad, I just double checked, and what I said about the qualifier is wrong.
     
    Last edited: May 27, 2010
    cfStarlight, May 27, 2010 IP
  5. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    cfStarlight, May 27, 2010 IP
  6. gesangbaer

    gesangbaer Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I did use the full url, I edited it out for posting on here..
     
    gesangbaer, May 28, 2010 IP
  7. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I don't know what to tell you then. The code works perfectly for me with the full url. That is assuming the sample data you posted is really tab delimited and is an accurate representation of your real file..

    <cfhttp
    method="Get"
    url="http://localhost/test/testFile.txt"
    textqualifier=""
    delimiter="#chr(9)#"
    name="questions"
    >
    <cfdump var="#questions#">
     
    cfStarlight, May 30, 2010 IP
  8. gesangbaer

    gesangbaer Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well, here is the exact error message, I've only edited out path and URL details. Maybe this will help someone help me?

     The column name "
    Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
     
    The error occurred in /directory/test.cfm: line 52
    
    50 :                     url="http://www.myurl.com/reqquestions.txt"
    51 :                     textqualifier=""
    52 :                     delimiter="#chr(9)#"
    53 :                     name="questions"
    54 :                     >
    
    Code (markup):
    edit ...

    Also, for formatting the file, I only need a tab between each column, right? I shouldn't need a tab before the first column or after the last column, right?
     
    Last edited: Jun 1, 2010
    gesangbaer, Jun 1, 2010 IP
  9. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yep, you only need the tab between columns. Not before or after.

    I'm pretty sure your input file is messed up or is not really tab delimited. Because the code works perfectly with a correctly formatted file.

    
    <!--- generate a tab delimited file ...--->
    <cfsavecontent variable="fileText"><cfoutput>
    Number#chr(9)#Text
    0#chr(9)#text for question one
    1#chr(9)#Some ext for question 2, and more</cfoutput>
    </cfsavecontent>
    
    <!--- overwrite/save to disk --->
    <cfset filePath = ExpandPath("/test/testFile.txt")>
    <cffile action="write" file="#filePath#" output="#fileText#">
    
    <cfhttp method="get" url="http://localhost/test/testFile.txt" textqualifier="" delimiter="#chr(9)#" name="questions">
    <cfdump var="#questions#"> 
    
    Code (markup):
     
    cfStarlight, Jun 1, 2010 IP
  10. gesangbaer

    gesangbaer Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    well, I've made more than one test file, and none of them are working. I'm using windows, so the end line characters might be different than those on a Unix server, which is what's running our ColdFusion. Would that be a problem for CF?

    I mean, if manually typing the text into notepad with tabs included, or saving a tab delineated file from Excel isn't good enough for CF then I'll push for some other technology. This problem has been was more trouble than it should be.

    Do you know of any other cold fusion forums I could post this question on? This was the only one I could find via google. More heads working on this might see something else.
     
    Last edited: Jun 1, 2010
    gesangbaer, Jun 1, 2010 IP
  11. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I don't know what search phrase you were using, but the very 1st result on google for ColdFusion is adobe's own forums ... Though fyi, ColdFusion is one word (not two).
    forums.adobe.com/community/coldfusion
     
    cfStarlight, Jun 1, 2010 IP
  12. gesangbaer

    gesangbaer Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thanks for all your help!
     
    gesangbaer, Jun 2, 2010 IP
  13. gesangbaer

    gesangbaer Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    FYI Update

    So, I went to the adobe forums and started using a workaround where I just imported the file s text and then tried to convert it to a query. While dumping the text, I saw that I was actually getting my 404 page instead of the test file. I read the url again, and of course there was one character off.

    Having entered the correct url, my original code works just fine.

    Glad for resolution, but man do I feel like an idiot. :eek:

    Thanks again!
     
    gesangbaer, Jun 2, 2010 IP
  14. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    That makes two of us. I feel like an idiot for not suggesting you dump the chttp response in the first place ;-) Glad everything's copacetic now.
     
    cfStarlight, Jun 2, 2010 IP