为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM Database Server x64 V7.1.5.95-Build(2016.06.28-70305)ENT
【操作系统】:凝思
【CPU】:
【问题描述】:OCIBindByPos函数总是返回-1
CS_RETCODE DBComm::exec_proc( CS_CHAR sqlcmd, CS_CHAR firstValue, CS_CHAR secondValue)
{
OCIBind bindcolp = (OCIBind*)malloc(sizeof(OCIBind));
sb2 sb2aInd[3];
sword retcode = 0;
sb4 errcode = 0;
//数据库需要 GBK 的SQL语句。因此需要转换字符集
retcode = OCIHandleAlloc( (dvoid *)m_envhp, (dvoid **)&m_stmthp, OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
if ( 0 != retcode || NULL == m_stmthp)
{
printf("CS_FAIL return line is %d file is %s retcode is %d\r\n",
__LINE__, __FILE__, retcode);
return CS_FAIL;
}
retcode = OCIStmtPrepare(m_stmthp, m_errhp, (text *)sqlcmd, (ub4) strlen(sqlcmd), (ub4)OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
if(retcode != OCI_SUCCESS && retcode != OCI_SUCCESS_WITH_INFO)
{
printf("CS_FAIL return line is %d file is %s retcode is %d\r\n",
__LINE__, __FILE__, retcode);
return CS_FAIL;
}
//绑定3个输入变量
if ((retcode = OCIBindByPos(m_stmthp, bindcolp, m_errhp, (ub4)1, (dvoid *)firstValue, 2000, SQLT_STR, 0 , 0 , 0 , 0 , 0 , OCI_DEFAULT))!=OCI_SUCCESS)
{
printf("CS_FAIL return line is %d file is %s retcode is %d\r\n",
__LINE__, __FILE__, retcode);
return CS_FAIL;
}
if ((retcode = OCIBindByPos(m_stmthp, bindcolp + 1, m_errhp, (ub4)2, (dvoid *)secondValue, 2000, SQLT_STR, 0 , 0 , 0 , 0 , 0 , OCI_DEFAULT))!=OCI_SUCCESS)
{
printf("CS_FAIL return line is %d file is %s retcode is %d\r\n",
__LINE__, __FILE__, retcode);
return CS_FAIL;
}
retcode = OCIStmtExecute(m_svchp, m_stmthp, m_errhp, (ub4)1, (ub4)0, (OCISnapshot *)NULL,(OCISnapshot*)NULL,(ub4)OCI_DEFAULT);
if (OCI_SUCCESS != retcode)
{
printf("CS_FAIL return line is %d file is %s retcode is %d\r\n",
__LINE__, __FILE__, retcode);
return CS_FAIL;
}
if((retcode = OCITransCommit(m_svchp, m_errhp, (ub4)0)) !=OCI_SUCCESS)
{
printf("CS_FAIL return line is %d file is %s retcode is %d\r\n",
__LINE__, __FILE__, retcode);
return CS_FAIL;
}
return CS_SUCCEED;
}