I am having trouble with a certain piece of documentation from MSDN. I am using C++ (or C, rather) to connection to an SQL Server instance via ODBC. Take at the code sample at the bottom of this piece of documentation.
Notice there is a function in the sample called AllocParamBuffer(). The documentation describes what it should do, but doesn’t provide any further help. Could someone please give me a few pointers (no pun intended) as to how I could replicate the definition of this function for this particular case, or, better yet, show it could be done? I’m at a real roadblock, and I can’t find any assistance elsewhere.
Any help would be greatly appreciated.
Thank you for your time.
You are referring to:
All this does is allocate some memory one presumes with malloc (since the later free calls) to store the input parameter (PtrArray[i]) then set the buffer length BufferLenArray[i] (i.e. the amount of memory allocated for PtrArrayp[i]).
We’d only be guessing how it calculates how much memory to allocate since the amount required in this case will differ depending on the DataType and ParamSize returned by SQLDescribeParameter. The guess work is down to the fact all the parameters are bound as SQL_C_CHAR and some of them might not be string columns e.g., they could be dates.
All you need to do is malloc some memory, assign the pointer to PtrArray[i] and set the amount allocated in BufferLenArray[i].