On 5 Jul 2009, at 12:31am, BareFeet wrote: > Hi Simon, > >>> How can I get just the column headers without all the result rows? >> >> Turn headers on, then perform a search which gives no results. > > Unfortunately, the sqlite3 command line tool does not show the headers > when there are no result rows.
Whoops. You're right. If the query returns no rows, there are no columns, so there are no column headers. > In any case, it's nit 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. >> 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. 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'. But if no rows are returned even that will fail. 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. 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. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users