免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4163 | 回复: 4
打印 上一主题 下一主题

[C++] OTL操作clob core掉了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-18 09:46 |只看该作者 |倒序浏览
本帖最后由 jack1219 于 2012-09-18 09:46 编辑
  1. void select2()
  2. {
  3. int len=0;

  4. /*char* p =(char*)malloc(1024*1024*100);
  5. if(!p){
  6.         printf("malloc fail\n");
  7.         return ;
  8. }else{
  9.         printf("malloc succ,%d\n",1024*1024*100);
  10. }*/
  11. char p[1024*1024*100];

  12. otl_long_string f2(20000); // define long string variable

  13. otl_stream i(10, // buffer size. To read CLOBs, it can be set to a size greater than 1
  14.               "select f1,f2,f3 from test_tab where f1=:f<int>",
  15.                  // SELECT statement
  16.               db // connect object
  17.              );
  18.    // create select stream

  19. float f1;
  20. otl_lob_stream lob; // Stream for reading CLOB

  21. i<<5; // assigning :f = 4
  22.    // SELECT automatically executes when all input variables are
  23.    // assigned. First portion of output rows is fetched to the buffer

  24. while(!i.eof()){ // while not end-of-data
  25.   i>>f1;
  26.   cout<<"f1="<<f1<<endl;
  27.   
  28.   i>>lob; // initializing CLOB stream by reading the CLOB reference
  29.           // into the otl_lob_stream from the otl_stream.
  30.   int n=0;
  31.   while(!lob.eof()){ // read while not "end-of-file" -- end of CLOB
  32.    ++n;
  33.    lob>>f2; // reading a chunk of CLOB
  34.    cout<<"   chunk #"<<n;
  35.    cout<<", f2="<<f2[0]<<f2[f2.len()-1]<<", len="<<f2.len()<<endl;

  36.    
  37.   }
  38.   lob.close(); // closing the otl_lob_stream. This step may be skipped.

  39.   i>>lob; // initializing CLOB stream by reading the CLOB reference
  40.           // into the otl_lob_stream from the otl_stream.
  41.   n=0;
  42.   while(!lob.eof()){ // read while not "end-of-file" -- end of CLOB
  43.    ++n;
  44.    lob>>f2; // reading a chunk of CLOB
  45.    cout<<"   chunk #"<<n;
  46.    cout<<", f3="<<f2[0]<<f2[f2.len()-1]<<", len="<<f2.len()<<endl;
  47.   }
  48.   lob.close(); // closing the otl_lob_stream. This step may be skipped.
  49.   
  50. }
复制代码
这个是仿otl example写一个查询clob类型数据库的例子。
其中test_tab表,有3个字段, "create table test_tab(f1 number, f2 clob, f3 clob)"
有个问题就是,当查询前,如果char p[1024*1024*100];就会core
但如果采用malloc方法,(被注释部分),就不会core了。


core信息:
#0  0x0000000000436b96 in select2 () at FrontendMain.cpp:330
330      otl_long_string f2(20000); // define long string variable
(gdb) bt
#0  0x0000000000436b96 in select2 () at FrontendMain.cpp:330
#1  0x0000000000436fcb in main () at FrontendMain.cpp:400
(gdb)

这是什么原因呢?堆栈问题?

论坛徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52双子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午马
日期:2013-10-18 21:43:38
2 [报告]
发表于 2012-09-18 09:50 |只看该作者
1024*1024*100,100M, 超出栈大小了

论坛徽章:
0
3 [报告]
发表于 2012-09-18 09:53 |只看该作者
回复 2# hellioncu

谢谢,谢谢。


   

论坛徽章:
0
4 [报告]
发表于 2013-07-10 14:47 |只看该作者
你的问题,我有新的发现:
otl_long_string f2(4);  // 这里是我定义的数据大小。方便重现问题

数据库里的clob类型的字段有10个字符。

这里已经报错了:
chunk #1
aaaa
len= 4
CLOB/BLOB stream is not open for reading



由于OTL所有的错误都需要捕获。没有try catch 导致core掉。

你的core信息也指向你的定义:otl_long_string f2(20000); // define long string variable

如果超过 20000 需要你加以特殊处理的。

论坛徽章:
0
5 [报告]
发表于 2013-07-10 16:43 |只看该作者
误导了
我的流关闭早了。这个发现不成立
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP