Reputation: 470
I am trying to bind an NULL-Value to a parameter in a sql query but I always get an error HY009 Invalid argument value when I execute the statement. That strange behavior only appears when I build in release mode. In debug mode it's working fine. Any ideas?
My Code:
SQLRETURN nRet = SQLPrepare(m_hStmt, (SQLTCHAR *)strSQL, SQL_NTS); // returns SQL_SUCCESS
SQLINTEGER cbNumeric = SQL_NULL_DATA;
nRet = SQLBindParameter(m_hStmt,
parameterIndex,
SQL_PARAM_INPUT,
SQL_C_CHAR,
SQL_LONGVARCHAR,
0,
NULL,
NULL,
0,
&cbNumeric); // returns SQL_SUCCESS
nRet = SQLExecute(m_hStmt); // returns SQL_NEED_DATA
nRet = _SQLParamDataPutData(nRet); // returns Debug: SQL_SUCCESS, Release: SQL_ERROR
Upvotes: 0
Views: 879
Reputation: 1652
If I understand the documentation at https://msdn.microsoft.com/en-us/library/ms710963%28v=vs.85%29.aspx correctly, you are not allowed to pass a NULL-pointer as ParameterValuePtr
argument - even if the value is a NULL-Value.
From the comments section in the doc, about the error HY009:
(DM) The argument ParameterValuePtr was a null pointer, the argument StrLen_or_IndPtr was a null pointer, and the argument InputOutputType was not SQL_PARAM_OUTPUT.
Does it work if you change your code to something like this:
SQLRETURN nRet = SQLPrepare(m_hStmt, (SQLTCHAR *)strSQL, SQL_NTS);
SQLCHAR dummy[1];
dummy[0] = '\0';
SQLINTEGER cbNumeric = SQL_NULL_DATA;
nRet = SQLBindParameter(m_hStmt,
parameterIndex,
SQL_PARAM_INPUT,
SQL_C_CHAR,
SQL_LONGVARCHAR,
0,
NULL,
dummy,
SQL_NTS,
&cbNumeric); // returns SQL_SUCCESS
nRet = SQLExecute(m_hStmt); // returns SQL_NEED_DATA
nRet = _SQLParamDataPutData(nRet);
Upvotes: 1