I have a class which takes an SQL query, executes it, then binds every column in the resultset as SQL_C_WCHAR using row-wise binding.
right now the way I do it is to allocate a vector of char, and determine the pointers to give SQLBindColumn as follows:
- buffer for column 1 = &vec[0]
- buffer for length indicator of column 1 = &vec[0] + (sizeof(SQLWCHAR) * length of column 1)
- buffer for column 2 = &vec[0] + (sizeof(SQLWCHAR) * length of
column 1) + sizeof(length indicator) - buffer for length indicator of column 2 = &vec[0] + (sizeof(SQLWCHAR) * length of column 1) + sizeof(length indicator) + (sizeof(SQLWCHAR) * length of column 2)
and so on
this is causing some alignment issues (on SPARC). I know I need to add some padding, but I don’t know how to calculate how much portably.
The way I ended up dealing with it was to actually put the length indicators and the wchars in seperate, correctly typed, buffers. They don’t actually have to live in the same buffer since all that ODBC does is add the ‘struct size’ to each address each time it wants to go the the next set.
I figured out the alignment needed for WCHAR and SQLLEN by allocating two small arrays on the stack and subtracting pointers between adjacent cells. Then I took the LCM of both of the alignments, and added padding to the buffers so each set would occupy a multiple of that space. The I fed ODBC this as a phony ‘struct size’.