0

According to the documentation:

When empty-result-callbacks is set in this situation, the callback function
is invoked exactly once, with the third parameter set to 0 (NULL). This is to 
enable programs that use the sqlite3_exec() API to retrieve column-names even 
when a query returns no data.

I am in need of exactly this functionality in my program, but the documentation further goes on to say that this pragma is deprecated and should not be used in new applications. However it doesn't say what the alternative is. How am I supposed to get this functionality if this pragma is deprecated?

1 Answer 1

1

The easiest answer is to not use sqlite3_exec, which is just a convenience wrapper. Use sqlite3_prepare_v2, sqlite3_step, and sqlite3_column_* (including column_count and for your use, column_name) explicitly. (and sqlite3_finalize, of course).

If you're not sure exactly how to do this, the implementation of sqlite3_exec is easy to find in the source distribution, as src/legacy.c

2
  • That's the easiest answer, but not the easiest solution! But in other words, are you suggestion that the deprecation was made without anything in mind to replace it in a simple way? If so, I'm curious what the rational for deprecation was.
    – Michael
    Jun 25, 2014 at 23:55
  • You can easily write your own helper function that returns a list of columns.
    – CL.
    Jun 26, 2014 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.