0

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    

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.