日期:2014-05-17  浏览次数:21042 次

OO4O的Odynaset.GetFieldValue无法获取4000字节左右的LONG型值
使用OO4O的C++包装类 查询 user_views 表的TEXT字段(类型为LONG)
通过调用oresult or = odynTV.GetFieldValue(i, (void __huge *)pCharArray, lFieldSize, &lReaded);
原型为oresult GetFieldValue(int index, void __huge *longval, long len, long *readlen) const;
发现当TEXT字段超过一定字节数后(估计2500-4000)左右就无法返回TEXT的内容了,这时readlen变量被赋值为0表示没有读出数据,其实数据是有的,查Oracle帮助文件,发现文档也示例
dyn.GetFieldValue("flong", (void *) blobbuff, 80000, &nread);
这样写也就是说80000个字节都能得到,可是我为什么超过几千个字节就获取不到了呢,2100字节左右的TEXT字段都可以获取成功。

------解决方案--------------------
还是中规中矩的用OClob来读取吧。

#include <oracl.h>
#include <iostream.h>
#include <fstream.h>

// Example for OClob::Read
int main()
{

//Initialize oo4o, connect, execute sql
OStartup();
ODatabase odb("ExampleDB", "scott", "tiger");
ODynaset odyn(odb, "SELECT * FROM PART");

if (!odyn.IsOpen())
{
cout <<"Connect Error: "<<odb.GetErrorText()<<endl;
cout <<"SQL Error: "<<odyn.GetErrorText()<<endl;
return 1;
}

OClob oclob;
odyn.GetFieldValue("PART_DESC", &oclob);

unsigned char *buffer = 0;
try
{
fstream fs;
fs.open("descout.txt", ios::out);
fs.setmode(filebuf::binary);

unsigned long size = oclob.GetSize();

// calculate an optimum buffersize of approximately 32k bytes
unsigned long optchunk = oclob.GetOptimumChunkSize();
unsigned int bufsize = ((int)(32768/optchunk)) *optchunk;
if (bufsize > size)
bufsize = size;

buffer = (unsigned char *)malloc(bufsize);

//By taking advantage of streaming we get the best performance
//and do not need to allocate a large buffer
oclob.EnableStreaming(size);

short status= OLOB_NEED_DATA;
unsigned long amtread=0;

while(status == OLOB_NEED_DATA)
{
amtread = oclob.Read(&status, buffer, bufsize);
fs.write(buffer, amtread);
}

oclob.DisableStreaming();
fs.close();
}
catch(OException E)
{
cout<<E.GetFailedMethodName()<< " Error: "<<E.GetErrorText()<<endl;
}

if (buffer)
free(buffer);

return 0;
}