Question

The SQLBindCol function expects a buffer length (for certain buffer types, like strings):

http://msdn.microsoft.com/en-us/library/ms710118(v=vs.85).aspx

SQLRETURN SQLBindCol(
      SQLHSTMT       StatementHandle,
      SQLUSMALLINT   ColumnNumber,
      SQLSMALLINT    TargetType,
      SQLPOINTER     TargetValuePtr,
      SQLLEN         BufferLength,
      SQLLEN *       StrLen_or_Ind);

How do I know how much bytes I should allocate?

The only thing I can think of is getting the SQL_DESC_LENGTH using SQLGetDescField, but I would have to execute the query twice then.

Était-ce utile?

La solution

As it turns out I confused the order in which the functions are run, the correct order is:

  1. SQLBindParameter
  2. SQLExecDirect
  3. SQLBindCol

For SQLBindParameter (at least for input parameters) the lengths are already known before the statement is executed.

After SQLExecDirect you can use the SQLNumResultCols and SQLGetDescField functions to determine the number of columns, their data types, lengths, etc.

The SQL92/CLI (call level interface) documentation has an example in appendix B.2 Interactive Query that uses SQLDescribeCol to get the length.

Autres conseils

Call SQLDescribeCol before binding.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top