On Dec 24, 2004, at 9:56 AM, Dennis Cote wrote:
James Berry wrote:

I think I was most confused by was the use of the word "index" in the
documentation where associated with the bind calls. Index is a
misnomer. It should really be something like "parameter number" as
I've used it above, since index to me implies the index of the
parameter reference within the SQL.

Index was the correct term when it was first used, since SQLite only supported positional parameters at that time. The parameter number was the index of the parameter in the SQL statement.

Things have gotten more complicated since then. Now, the term index really refers to the internal array of parameter values that is maintained for each statement.

I don't think it means much to talk about the "parameter number" of a named parameter. They should be refered to by their name. To bind a value to a named parameter you need to ask SQLite for the index number to use for that variable when you make the bind call.
I agree that index makes a certain amount of sense if/once you understand the internal implementation. But unless you're looking at the code, there's nothing very "indexy" about it, particularly if you mix parameter types, or use numbered parameters indiscriminately. Not that I would suggest someone do so. And also that indexes in C start at 0, not 1.

So I came up with the term "parameter number" because it refers to a more generic mapping of parameter <==> number. Let's face it: parameters are referred to by number through the bind interface, not by index. And the mapping of parameter to number is complex. The fact that it's called an index is just the implementation leaking through into the interface.

Anyway, call it what you want, we just need to be clear that it's not an index as one would normally think if it. It's a number predictively assigned to the parameter...a parameter number ;)

James

For numbered parameters, the parameter's number is the index by design (but it could have been different).

For positional parameters, you still need to count the parameters in the SQL statement to determine its index.

I think index is still the best term, it is just that you need to be clear that it is an index into the array of bound values, not into the text of the SQL statement.

Dennis Cote

Reply via email to