Re: ESQL/C: why 2 short ints for indicator variables?
Posted in 1994
("Centr. Instytut Ochrony Pracy") writes: >Jonathan Leffler writes: >> First of all, you are responsible for allocating pointers to the sqlind >> stuff; ESQL/C doesn't assign anything there. Therefore, you are >> responsible for freeing it, if you used allocated memory. You might not >> have done for indicator variables. I tend to use pointers to 2 short >> integers, one containing 0, t'other -1. > >Why exactly are you using pointers to 2 short integers? >Having read the documentation I understand the sole purpose >of indicator variable is to indicate whether the value >of the given field is null. Why, then do you need 2 short ints >isn't one enough? I suspect Jonathan is using them to *set* the indicator to -1 or zero, depending on whether he wants to insert a null or not. Since he may want some variables null and others non-null in the same insert or update, it is handy to have the two. By setting the indicator to -1, a null will be inserted for the column regardless of what data is in the data pointer, so you will not have to "null out" the variable to insert the null, just change the indicator pointer. For selects, a single indicator variable will not work properly; with all the sqlda indicator pointers referencing it, only the last column selected will be indicated by the contents of the variable. For selects, you really need a separate indicator variable for each host variable. Dave -- Disclaimer: These opinions are not those of Informix Software, Inc. ************************************************************************** "I look back with some satisfaction on what an idiot I was when I was 25, but when I do that, I'm assuming I'm no longer an idiot." - Andy Rooney