[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reverse engineering SQL


On 26/3/25 11:21 am, T Lee Davidson wrote:

On 3/25/25 7:46 PM, BB wrote:
I think I have to manipulate the query string and eliminate the WHERE and ORDER BY clauses and add LIMIT=1 (to get a result back in my lifetime! several million records). Will reply if it works.

Could you execute the full query and simply append a "WHERE 1<>1" to the end? That gives the filed names (at least with the Sqlite driver).

Well, yes and no. Yes, it has the same effect as LIMIT=0 (which also works). No, I cant just stick it on the end as there may be other clauses following the WHERE. I like your idea better though as I think the database SQL optimiser wont object to LIMIT=0 and not return a cursor. I mean for postgres (and standard SQL) Limit=0 is a valid clause that is parsed, planned and returns an empty set, I don't know for other databases.

I have set up a form to display the query (i.e. the visible query at this end) and it works >90% of the time. It fails when the query uses stored functions that require real parameter values (as I'm not providing them). I have run it manually over ~50 known query examples on the live database with excellent outcomes. I will ask the DBA's if it possible that their functions could be set up with default values but I am not sure if I can convince them of the benefits. 😕 As a matter of fact, I'm not sure it is possible in SQL/pSQL.

continuing in the general direction of on

b


References:
Reverse engineering SQLBB <adamnt42@xxxxxxxxx>
Re: Reverse engineering SQLT Lee Davidson <t.lee.davidson@xxxxxxxxx>
Re: Reverse engineering SQLBB <adamnt42@xxxxxxxxx>
Re: Reverse engineering SQLT Lee Davidson <t.lee.davidson@xxxxxxxxx>