Hi, I'm looking for an ANSI-SQL method to do a Select query without returning any record, but fill a TDataSet's Fields structure.
The method I found is by adding a "where 1=0" in any query, for example:
Select Id, name, province
from customers
where 1=0
This is a fairly trivial example, it turns a little more complicated when I have to work with queries entered by the user, then parse them, remove the where clause if it already has one, and replace by "1=0".
If the last clause in the user-entered query is the where clause, then there's no problem at all, but what about more complicated queries like this:
select
c.lastname,
sum(cs.amount)
from customersales cs
join customers c on c.idcustomer=cs.idcustomer
/* where 1=0 */
group by c.idcustomer, c.lastname
By using the "where 1=0" method, the only way to insert it in the previous example is by having a rather powerful SQL parser (remember the user can enter complex queries, including Subqueries, and all that), who can understand where to include this string.
Does anyone knows a better way to do this? I cannot use "limit 1" because it must be in an ANSI way.