Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    4

    Unanswered: Problem passing string params with ODBC API and Oracle 8i Stored Packages

    I am using Visual C++ .NET 2003 and the ODBC API to interact with an Oracle 8i database. I am trying to execute a simple procedure inside of a stored package which inserts a single record into a table.

    I have absolutely no problem passing in numeric values as parameters. It works exactly like it should in that case. However, strings are another story.

    Below is what my code looks like. I removed error handling and resource freeing code, so it's easier to read here.

    Code:
    SQLRETURN nReturn = 0;
    
    nReturn = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_hEnv);
    
    nReturn = SQLSetEnvAttr(m_hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
    
    nReturn = SQLAllocHandle(SQL_HANDLE_DBC, m_hEnv, &m_hDBC);
    
    nReturn = SQLSetConnectAttr(m_hDBC, SQL_ATTR_ACCESS_MODE, SQL_MODE_READ_WRITE, 0);
    
    nReturn = SQLSetConnectAttr(m_hDBC, SQL_ATTR_CONNECTION_TIMEOUT, (SQLPOINTER) 30, 0);
    
    nReturn = SQLConnect(m_hDBC, m_lpzDSN, strlen(m_lpzDSN), m_lpzUserName, strlen(m_lpzUserName), m_lpzPassword, strlen(m_lpzPassword));
    
    nReturn = SQLAllocHandle(SQL_HANDLE_STMT, m_pDatabase->GetDBCHandle(), &m_hStmt);
    
    nReturn = SQLPrepare(m_hStmt, "{call SV3Ref.InsertQCNote(?)}", SQL_NTS);
    
    char pchTest[] = "testing\0";
    
    SQLLEN nLen = 0;
    
    nReturn = SQLBindParameter(m_hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, (SQLINTEGER) strlen(pchTest), 0, (SQLPOINTER) pchTest, (SQLUINTEGER) strlen(pchTest), &nLen);
    
    nReturn = SQLExecute(m_hStmt);
    nReturn returns -1 on SQLExecute and I get the following error.
    "Cannot insert NULL into field [HYPDEV].[QCNOTES].[QCNOTETEXT]"

    Does anyone have any ideas?

  2. #2
    Join Date
    Oct 2003
    Posts
    4
    Never mind. I got the last parameter of SQLBindParameter confused with the same parameter name in SQLGetData(). It is an input parameter and must be set to the length of the buffer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •