In our application a user can enter SQL code to retrieve data from a NexusDB database. We want to determine the metadata of the result of such a query without actually executing the query. We use the metadata to i.e. determine the number of fields and the datatype of each resulting field.
[addition] We use this functionality as part of a user-defined conversion process. The actual conversion is done later on in a batch-like process, but we need the meta data beforehand, so the user can specify in the conversion additional field characteristics or modifications like applying plugins, creating parent-child relations, etc. [/addition]
Until now we do this by basically adding WHERE FALSE
to the SQL query or replacing all already present WHERE
statements by WHERE FALSE AND
. But of course we have to parse the whole SQL to determine the exact location of the correct where clause to adjust, taking comments, nested SELECTS, JOINs and other clauses into account. Its getting quite complicated this way :-(
And another downside of this is, that most of the time the execution of the query can still take a long time, even though we know beforehand that the resultset will be empty.
We were wondering if there is another way of achieving this.
i.e. The TQuery object must have a parser of its own, splitting the SQL statement in its different clauses. If we could change the where clause just before execution, we wouldn't have to do the parsing ourselves. But we are a bit anxious of diving into the internals of the TQuery object, just to find out there is no way to use it the way we want to.
Anyone have any advise on this?