There is no way to get the real query (unless you want to cast your way around). Heck, it is not even guaranteed that there is a query in the end after all. A TableDataFactory has no query, it has the data hardcoded in. A scriptable datasource has no query, but a script, and you cant even tell what is executed unless you also see the parameters and/or run it.
So it basically comes to:
- you have to know what data-source you are using
- you have to have code that knows the internals of each data-source type you wan to handle
Oh, and there can be more than one datasource. Each subreport can have its own datasources in addition to the ones inherited from the master.
However, from *within* a report-function you are not able to get to the datasources declared on the report. We do not want anyone to mess with the datasources while we are working with them. So there are a lot of barriers in place to prevent that to happen. And if you dig your way through it and we hear about it, we will add another layer of barriers - that's promised
