When I dump a query, I get some metadata about it:...
# lucee
a
When I dump a query, I get some metadata about it:

https://i2.paste.pics/8c44dba63d3e573a17e9e4db1733d2d8.png

How do I extract that from the query object? I am specifically after the
cached
value.
getMetadata
only returns column info, not stuff about the query object itself. Note: I am not asking about the
result
option that one can pass to a
queryExecute
call. I only have the query object; I am not in control of the initial call, so I cannot use the
result
. Cheers.
Looks like I can call
isCached
on the object and that returns what I need. However I'm slightly hesitant to call something that might be considered "internal implementation" and not intended for use in CFML code..? I see it is documented @ https://javadoc.lucee.org/lucee/runtime/type/Query.html, so perhaps it's OK. (I'm coming from more exposure to CF, where Adobe advise not to use such methods, as they are not a documented / supported API; might be different with Lucee)
n
Here's a hilariously bad implementation: I don't recommend this, it was purely a "can it be done" experiment
Copy code
function dumpCachedValue(q) {
        var test = dumpStruct(q).comment;
        test = listFirst(test, "SQL");
        test = listLast(test, "Cached: ");
        return test;
    }
a
What is this
dumpStruct
you are using here? (and yes, I checked it on trycf and it is a thing. My question still stands 😉
That's literally the only mention of dumpStruct in the lucee codebase
As I said, comical implementation
Kinda surprised it's not in the list of lucee functions as it appears to be available everywhere
t
so its java underneath try
writeDump(qryResult.getClass());
which should give you a nice list of methods but be warned not all are implemented. e.g.
writeDump(qryResult.getSql().toString());
works,
writeDump(qryResult.getMetaData());
doesnt
Copy code
writeDump({
    "Sql" =  qryResult.getSql().getSQLString(),
    "ExecutionTime" = qryResult.getExecutionTime(),  
    "CacheType" = qryResult.getCacheType(),
    "isCached" = qryResult.isCached()
    });