Skip to main content
Participant
February 15, 2021
Question

How to display sql query in web browser

  • February 15, 2021
  • 2 replies
  • 210 views

Please let me know how to display the query written in cold fusion page on web browser.

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    February 16, 2021

    ColdFusion comes with a built-in datasource called cfartgallery. So, if  you open the following page, it will display the query in the browser.

     

    testPage.cfm

    <cfquery datasource="cfartgallery" name="testQuery">
    select *
    from artists
    </cfquery>
    
    <cfdump var="#testQuery#">

     

    Sai5FCDAuthor
    Participant
    February 18, 2021

    Thank a lot BKBK and others for the solutions provided by you all.  I am trying to print the dynamic query which i will writing in my .cfm page on to the browser.  Will test the sample code provided by BKBK.

    Community Expert
    February 15, 2021

    I'm not entirely clear what you're asking. If you want to output the actual SQL statement, it's a property of the CFQUERY resultset, like so:

     

    <cfquery name="sample" result="sampleResult" ...>

    select * from tblSample

    </cfquery>

     

    <cfoutput>#sampleResult.sql#</cfoutput>

     

    If on the other hand, you want to output the resultset itself, you use the QUERY attribute of CFOUTPUT:

     

    <cfquery name="books" ...>

    select bookId, name, author from tblBooks

    </cfquery>

     

    <cfoutput query="books">

    #name#, #author#<br>

    </cfoutput>

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC