Skip to main content
Participant
July 5, 2009
Question

cfx return variable vs. query

  • July 5, 2009
  • 1 reply
  • 916 views

Hi:

I am using c++ to write a custom coldfusion tag. There are two ways of returning values, one is to use:

request.setVariable(name, value);


The other one is to use queries:

pRequest->AddQuery(name, columns);

...

I do not understand the difference between them. Can someone make an example of the difference of what they will look like after returned. Or to demonstrate in anyway that I could understand.

Thanks.

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 5, 2009

    I am more familar with java CFX tags.  But I think the main difference is that they are used to add different types of variables to the calling page.  Response.AddQuery is specifically for creating a CF query object. Think of it as the equivalent of using QueryNew() in a cfm page:

    <cfset theQueryName = QueryNew("FirstName,LastName")>

    Response.SetVariable is used to create other types of variables like strings, datetime objects, structures, etc. (Update In java tags you can tweak the "name" value create structures and arrays.) It is the equivalent of using a cfset such as:

    pRequest->setVariable("firstName", "John");
    ...

    <!--- create a string --->

    <cfset firstName = "John">

    <!--- .. or a date/time object --->

    <cfset startDate = createDate(2009, 3, 1)>

    <!--- .. or a complex object like a structure --->


    <cfset prop = structNew()>

    cpthk0Author
    Participant
    July 5, 2009

    I checked some documentation other than adobe's. It seems like setVariable() is just like <cfset>, which only takes value of string. In our case is John.

    And query is like <cfquery>, which act like you communicate with a SQL server. A SQL server return you a set of data for instance containing a whole table of user information. So we need <cfloop> to fetch out each row, or use <cfoutput> to print out the whole table.

    Can anyone confirm this?

    Inspiring
    July 5, 2009

    cpthk0 wrote:

    I checked some documentation other than adobe's. It seems like setVariable() is just like <cfset>, which only takes value of string. In our case is John.

    Yes, but you can adjust the "name" value to implicitly create other types of objects like structures or arrays.

    And query is like <cfquery>, which act like you communicate with a SQL server. A SQL server return you a set of data for instance containing a whole table of user information. So we need <cfloop> to fetch out each row, or use <cfoutput> to print out the whole table.

    Are you asking about how cfquery is used within a ColdFusion page or how to populate query objects from a CFX tag?