ADO调用ORACLE存储过程保存BLOB字段时只能写入部分数据的问题
CAdoRecordSet DstPicSet;
CAdoConnection DstPicConnection;
//使用数据源 myoracle 连接数据库,使用oracle in orahome92 数据源驱动
if(DstPicConnection.Open("Data Source = myoracle;UID = nlv_guest; PWD=guest;",adModeUnknown) == FALSE)
{
OutputDebugString("连接数据库失败");
return FALSE;
}
CAdoCommand DstCommand;
DstCommand.SetConnection(&DstPicConnection);
// 图片参数1
VARIANT varBLOB;
SAFEARRAYBOUND rgsabound[1];
SAFEARRAY *psa = NULL;
BYTE* m_pchCurrentFile = new unsigned char[72350];
memset(m_pchCurrentFile,0,72350);
CFile fs_File;
fs_File.Open("C:\\1.jpg",CFile::modeRead);
long lLength = fs_File.GetLength();
if(fs_File.Read((void*)m_pchCurrentFile,lLength) != lLength)
{
AfxMessageBox("读取文件长度错误!"); //测试
return FALSE;
}
else
{
AfxMessageBox("读取文件长度ok");
}
fs_File.Close();
byte* pBuff = m_pchCurrentFile;
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lLength;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
if(psa == NULL)
{
AfxMessageBox("SafeArrayCreate error");
}
for (long i = 0; i < (long)lLength; i++)
{
if(S_OK == SafeArrayPutElement(psa, &i, pBuff++))
{
continue;
}
}
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
DstCommand.Append(DstCommand.CreateParameter("ZJWJ1",adBinary,adParamInput,varBLOB.parray->rgsabound[0].cElements,varBLOB));
SafeArrayDestroy(psa);
delete[] m_pchCurrentFile;
// 调用 system.pro_eps 存储过程
DstCommand.SetCommandText("system.pro_eps");
if(DstCommand.Execute() == FALSE)
{
AfxMessageBox("DstPicTestSet execute error");
}
以上就是这段代码,数据库用的是 oracle9.2 ,每次调用该存储过程可以保存图片到表中的 BLOB 字段,使用TOAD工具导出该字段时,图片打开显示只有上面一小部分,属性显示图片大小每次都是 2,000 字节.我想问下高手是不是我的代码那个地方写错了,限制了写入数据的大小?还是数据库的问题?