You can do a lot towards that using <code>sqlite3_column_count()</code>. Using that before iterating columns gets rid of a bunch of situations where you would otherwise get <code>NULL</code>s. Anything left after that may well be unpredictable anyway.