Search code examples
c++sqlsql-serversqlncli

SQLBindParameter to prepare for SQLPutData using C++ and SQL Native Client


I'm trying to use SQLBindParameter to prepare my driver for input via SQLPutData. The field in the database is a TEXT field. My function is crafted based on MS's example here: http://msdn.microsoft.com/en-us/library/ms713824(VS.85).aspx.

I've setup the environment, made the connection, and prepared my statement successfully but when I call SQLBindParam (using code below) it consistently fails reporting: [Microsoft][SQL Native Client]Invalid precision value

int col_num = 1;
SQLINTEGER length = very_long_string.length( );
retcode = SQLBindParameter( StatementHandle,
            col_num,
            SQL_PARAM_INPUT,
            SQL_C_BINARY,
            SQL_LONGVARBINARY,
            NULL,
            NULL,            
            (SQLPOINTER) col_num,     
            NULL,                 
            &length ); 

The above relies on the driver in use returning "N" for the SQL_NEED_LONG_DATA_LEN information type in SQLGetInfo. My driver returns "Y". How do I bind so that I can use SQLPutData?


Solution

  • you're passing NULL as the buffer length, this is an in/out param that shoudl be the size of the col_num parameter. Also, you should pass a value for the ColumnSize or DecimalDigits parameters.

    http://msdn.microsoft.com/en-us/library/ms710963(VS.85).aspx