1

I am using cpp and -lsqlite3 to handle some data. I just wanted to ask about a query that will return the number of columns of a specific table in sqlite. Is it possible to find out?

Hard work
  • 45
  • 3

1 Answers1

2

With sufficiently recent SQLite version:

select count(*)
from pragma_table_info('tableName')

If it doesn't have to be a SQL query but could be an API call, then a) prepare a query select * from tableName (just prepare, you don't need to actually execute it), then call sqlite3_column_count on the resulting statement handle.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85