Get SQL From Query Object

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Get SQL From Query Object

    I was wondering if you can get the SQL string out of a query object, or any way
    of seeing the SQL once the query has been run. I do not have access to the SQL
    where it is entered in the cfquery tag, just the resulting query object. Thanks

    Tim

    twkatadin Guest

  2. Similar Questions and Discussions

    1. Query Object Limitations
      I believe this is one of those bugs that you create while trying to make thing better then actualy possible! Why can't we access the query objects...
    2. Is this a BUG?!? - Query Object?
      I too have this same exact problem. I'm returning an LDAP query from a CFC into an application variable. When I cfdump the var it is displayed in...
    3. looping over a query object
      hi. i have a method with a query. this query returns a series of ids ( strings ). within this same method i want to loop over the query object and...
    4. ixsso.Query object and characterization
      Hi, We use this object for the search engine and it's been working great until recently. Now, the excerpt portion of the found document is not...
    5. one db query object literally kills another!
      I have a very simple mySqlQuery object that takes two parameters: 1) the string query 2) the db connection resource I tested and was certain...
  3. #2

    Default Re: Get SQL From Query Object

    Turn on debugging and then it will show up.
    Dan Bracuk Guest

  4. #3

    Default Re: Get SQL From Query Object

    Yes, I know that it shows up in the debugging information, but is there any
    other way to get the SQL in code? I can't turn debugging on in my production
    enviornment. I want to log the SQL that was run, but the code that creates and
    runs the query is invisible to my code. I was hoping the query object would
    have a sql property, but it doesn't look like it does.

    Thanks for the help
    Tim


    twkatadin Guest

  5. #4

    Default Re: Get SQL From Query Object

    Originally posted by: twkatadin
    ... ... but the code that creates and runs the query is invisible to my
    code.... ... I hope you're not trying to bypass some security.


    Anyway, there is no reliable way to get this information when debugging is off.

    You can use the admin API to turn debugging on and off programmatically and
    then use undocumented service factory functions to get the SQL.

    Or you can have the source page build the query using Java and setStatement().
    Then you could retrieve the SQL with getStatement().

    Finally, I think that if you revert to ODBC drivers (NOT recommended), you can
    use getStatement() without having to do any of the above. BUT I haven't (and
    won't) tested this.

    Finally, just about anything you do along these lines is pretty much going to
    be unsupported and subject to breakage with every change to CF.

    MikerRoo Guest

  6. #5

    Default Re: Get SQL From Query Object

    Assuming that your query is myQuery ,



    <!---
    <cfquery name="myQuery" datasource="myDSN">
    select myCol
    from myTable
    </cfquery>
    --->

    <cfscript>
    adminDbugObj = createObject("component","cfide.adminapi.debugging ");
    // getDebugRecordset() returns a query object.
    // "name", "datasource" and "body" are three of its columns.
    q = #adminDbugObj.getDebugRecordset()#;
    </cfscript>
    <!--- <cfdump var="#q#"> --->
    <cfloop query="q">
    <cfif name EQ "myQuery" and datasource EQ "myDSN">
    <cfoutput>#body#</cfoutput>
    <cfabort>
    </cfif>
    </cfloop>

    BKBK Guest

  7. #6

    Default Re: Get SQL From Query Object

    Originally posted by: BKBK
    Assuming that your query is myQuery ,
    ... ...

    Well that's better than using the service factory but it still doesn't work if
    debugging is turned off.

    getDebugRecordset() will return null.


    MikerRoo Guest

  8. #7

    Default Re: Get SQL From Query Object

    Thanks for all the help

    Tim
    twkatadin Guest

  9. #8

    Default Re: Get SQL From Query Object

    Well that's better than using the service factory but it still doesn't work if
    debugging is turned off.
    We should not presume that, because Twkatadin cannot see any debugging, it has
    been turned off. Admins usually have debugging on, but just for several Admin
    IPs. I'll leave it to someone else to check whether the code works in that
    case.

    BKBK Guest

  10. #9

    Default Re: Get SQL From Query Object

    Let me make this clear.

    That code does not work unless BOTH of the following are true:
    1) Debugging is ON.
    2) The client PC's IP is on the debug info list.

    Furthermore the admin API approach has one disadvantage that the service
    factory does not:

    If an admin password is required, then every time a session is started, that
    uses the API, then the admin or RDS password must be provided.

    This either precludes use in production or requires the coder to expose key
    passwords in his CFML.


    MikerRoo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139