5 Replies Latest reply on Sep 20, 2010 11:31 AM by Dan Bracuk

    List of Queries Run?

    NewPrism

      I'm on a public server and cannot get debug information to show. Mostly I want to see the queries that have run on the page. Is there an existing structure I can reference to get a list of queries that have run on a page?

        • 1. Re: List of Queries Run?
          Owain North Level 4

          If they're just set within a page rather than nested within a function you might be able to see them by dumping out the VARIABLES scope.

           

          O.

          1 person found this helpful
          • 2. Re: List of Queries Run?
            Dan Bracuk Level 5

            If you want to fine tune this approach, you could loop through the variables collection and use isQuery to identify the queries.

            1 person found this helpful
            • 3. Re: List of Queries Run?
              NewPrism Level 1

              Thanks to both responses. I was able to parse a list of the variable names but how do I test or parse each individual structure? Assume that one screen has a query named getTerritories.

               

              <cfoutput>

              Variable List: <br />

              <cfloop list="#structKeyList(variables)#" index="ii">

              #ii# <br />

              </cfloop>

              </cfoutput>

              • 4. Re: List of Queries Run?
                Owain North Level 4

                I think in order to get the SQL from more than one query, you'll need to add the result="varname" attribute to all the queries on the page.

                 

                Here's an example page, using an Oracle DB:

                 

                <cfquery name="Query1" datasource="ds" username="user" password="pass" result="Query1Info" >
                    SELECT 1 FROM dual
                </cfquery>

                 

                <cfquery name="Query2" datasource="ds" username="user" password="pass" result="Query2Info" >
                    SELECT 1 FROM dual
                </cfquery>

                 

                <cfloop collection="#VARIABLES#" item="EachVar">
                    <cfif isQuery(VARIABLES[EachVar]) >
                        <cfdump var="#VARIABLES[EachVar]#" label="#EachVar#" />
                    </cfif>
                </cfloop>

                 

                Hope that helps.

                • 5. Re: List of Queries Run?
                  Dan Bracuk Level 5

                  With CF9 it is not necessary to have a result attribute in the query in order to see the sql.  The metainfo default is "yes" for queries.