Skip to main content
November 13, 2006
Question

QuerySetCell

  • November 13, 2006
  • 2 replies
  • 531 views
QuerySetCell issues......
It's converting strings to timestamps. Really undesireable behavior. Anyway around this? It's converting a string like 9-3 to {ts '2005-09-03 00:00:00'}.
    This topic has been closed for replies.

    2 replies

    November 14, 2006
    I am using CFMX 7
    Code Snippet....
    <cfquery name="Results.PortsFull" datasource="xxx">
    SELECT Name, ItineraryID, PortDay,PortArrival , PortDeparture, PortID FROM Itinerary_Ports WHERE (ItineraryID = #Request.ItineraryID#) Order By PortDay
    </cfquery>
    <cfset REsults.Ports = QueryNew("Name, ItineraryID, PortDay, PortArrival, PortDeparture, PortID")>
    <cfloop index="i" from="1" to="#Results.PortsFUll.RecordCount#">
    <cfif isDate(#Results.PortsFull.PortDay #)>
    <cfset tmp = REReplaceNoCase(results.portsfull.PortDay
    ,"\w*day,","","ALL")>
    <cfset PortDay = Dateformat(tmp,"m/d/yy")>
    <cfelse>
    <cfset PortDay = numberformat(i,"__")>
    </cfif>
    <cfscript>
    QueryAddRow(Results.Ports,1);
    CurrentRow = Results.Ports.RecordCount;
    QuerySetCell(Results.Ports,"Name",Results.PortsFull.Name ,CurrentRow);
    QuerySetCell(Results.Ports,"ItineraryID",Results.PortsFull.ItineraryID
    ,CurrentRow);
    QuerySetCell(Results.Ports,"PortArrival",Results.PortsFull.PortArrival ,CurrentRow);
    <!--- this is the problem line --->QuerySetCell(Results.Ports,"PortDeparture",Results.PortsFull.PortDeparture
    ,CurrentRow);
    QuerySetCell(Results.Ports,"PortID",Results.PortsFull.PortID ,CurrentRow);
    QuerySetCell(Results.Ports,"PortDay",PortDay,CurrentRow);
    </cfscript>
    </cfloop>

    Thanks.
    November 14, 2006
    Galloping Gargoyles! That looks like an awfully painful way to manipulate PortDay.
    Did you know that you can most likely get portday the way you want it in the original query?
    (Or just format the DISPLAY later.)

    There does not seem to be any need for looping through the query like this. (In fact, looping a query for data manipulation purposes is never, ever, a good idea.)

    Anyhow... You can probably fix the existing code by changing the QueryNew line to something like:

    <CFSET Results.Ports = QueryNew ("Name, ItineraryID, PortDay, PortArrival, PortDeparture, PortID",
    "VarChar,Integer,VarChar,VarChar,VarChar,Integer")
    >

    November 14, 2006
    The code is messy! I am trying to clean another persons website code. I thought it worked but no luck. I even tried......

    QuerySetCell(Results.Ports,"PortArrival","#JavaCast('string',Results.PortsFull.PortArrival )#",CurrentRow);
    November 14, 2006
    QuerySetCell does not do this. Your code does this.

    Post your code (or better yet self contained demo code), and state what version of CF you are using.