SQLite Forum

Improve sqlite3_column_name() return value documentation
Login
Thank you for your comprehensive reply, Larry.

> I would agree that the treatment of invalid arguments could be better documented.

On this, we agree, however I do understand that this is a subjective matter; either you like explicit documentation, or you don't like it (keep it simple, exclude obvious stuff). I obviously (no pun intended) prefer the former.

> The doc need only say that the pointer must be a valid [...]

I agree.

> Passing an invalid column index into the API (as coded today) causes 0 to be returned [...] This should be documented [..]

I agree.

> This slight deficiency in the documentation has probably survived for so many years because most API users understand that random indexes are not going to lead to anything good and use sqlite3_column_count() to limit index values.

Yes, it is obvious. I am of the opinion that all behaviour should be documented, even if it is obvious.

> I think your mistrust is not well founded on the (present) fact that the contours of the "correct argument" space are not precisely or completely spelled out in the place(s) you expect.

I should also have chosen a less harsh wording. "There may be other discrepancies in the documentation" is a better description of how I feel about the matter.

> Probably. Can you point to a few important omissions?

I'm sorry, I cannot; I'm not familiar with the internals of the SQLite code base.

So, given valid a valid statement pointer and a valid column index, a `NULL` pointer is returned in case of memory allocation failure, and probably some other cases. IMHO, mentioning that would improve the documentation. Again, it's just a matter of preference. I prefer explicit docs, but that's just my opinion.

Since it is (unless I'm mistaken) not possible to differentiate between memory error and other errors, maybe the best improvement would be to remove the following sentence: _"If sqlite3_malloc() fails during the processing of either routine (for example during a conversion from UTF-8 to UTF-16) then a NULL pointer is returned."_

One could also consider altering the start of the first sentence from _"These routines return [...]"_  to _"If successful, these routines return"_, but based on the responses in this thread, I assume the current wording is preferred.

> The SQLite dev team is pretty good about improving doc defects that make it harder for SQLite library users to use it.

I'm glad to hear.