Hi Simon,

>> In any case, it's not possible to convert an ad hoc query (ie not  
>> known beforehand) into one that returns no rows.
>
> Sure it is.  Just add 'WHERE 1=2' to it if there's no WHERE clause,  
> or 'AND 1=2' if there is.

Increasing potential complexity of the "ad hoc" SQL command would  
require increasingly complex parsing to know what to append. eg we'd  
have to check for "begin/commit" and "union" and an existing "limit"  
etc. It is not practical.

>>> It's difficult in the command-line tool, but easy using function
>>> calls
>>> since there's a function call specially intended for it:
>>>
>>> <http://www.sqlite.org/c3ref/column_name.html>
>>
>> It would be great to see a pragma or built in SQL function that
>> returned the column headers of a given query.
>
> There is one: the one you just quoted my giving the URL for.

Sorry, let me clarify. I mean that I would like to see a pragma or  
function that can be used in an SQL expression (not a C function), so  
it can be used from the command line.

> If you want the smallest fastest possible query that will return at  
> least one row, do not use 'ORDER BY' and do use 'LIMIT 1'.

As mentioned in my other email, this doesn't lend itself to ad hoc (ie  
unknown beforehand) SQL commands.

> What are you trying to do ?  Find all the columns in a TABLE or find  
> all the columns in an arbitrary SELECT ?  If it's the former use  
> PRAGMA table_info for the table.

Thanks, yes, I am familiar with pragma table_info to return the column  
headers of a table or view. But I need the same functionality for the  
result of an arbitrary sequence of SQL commands.

> If the latter, replacing your 'WHERE' and 'ORDER BY' clauses with  
> LIMIT 1 will give you the right result if there's any data at all.

That will only work if it's a simple select, but not if it contains  
begin/commit, some inserts before the select, an existing limit etc.

Thanks for the thoughts,
Tom
BareFeet

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to