- 论坛徽章:
- 0
|
本帖最后由 jack1219 于 2012-09-18 09:46 编辑
- void select2()
- {
- int len=0;
- /*char* p =(char*)malloc(1024*1024*100);
- if(!p){
- printf("malloc fail\n");
- return ;
- }else{
- printf("malloc succ,%d\n",1024*1024*100);
- }*/
- char p[1024*1024*100];
- otl_long_string f2(20000); // define long string variable
- otl_stream i(10, // buffer size. To read CLOBs, it can be set to a size greater than 1
- "select f1,f2,f3 from test_tab where f1=:f<int>",
- // SELECT statement
- db // connect object
- );
- // create select stream
-
- float f1;
- otl_lob_stream lob; // Stream for reading CLOB
- i<<5; // assigning :f = 4
- // SELECT automatically executes when all input variables are
- // assigned. First portion of output rows is fetched to the buffer
- while(!i.eof()){ // while not end-of-data
- i>>f1;
- cout<<"f1="<<f1<<endl;
-
- i>>lob; // initializing CLOB stream by reading the CLOB reference
- // into the otl_lob_stream from the otl_stream.
- int n=0;
- while(!lob.eof()){ // read while not "end-of-file" -- end of CLOB
- ++n;
- lob>>f2; // reading a chunk of CLOB
- cout<<" chunk #"<<n;
- cout<<", f2="<<f2[0]<<f2[f2.len()-1]<<", len="<<f2.len()<<endl;
-
- }
- lob.close(); // closing the otl_lob_stream. This step may be skipped.
- i>>lob; // initializing CLOB stream by reading the CLOB reference
- // into the otl_lob_stream from the otl_stream.
- n=0;
- while(!lob.eof()){ // read while not "end-of-file" -- end of CLOB
- ++n;
- lob>>f2; // reading a chunk of CLOB
- cout<<" chunk #"<<n;
- cout<<", f3="<<f2[0]<<f2[f2.len()-1]<<", len="<<f2.len()<<endl;
- }
- lob.close(); // closing the otl_lob_stream. This step may be skipped.
-
- }
复制代码 这个是仿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)
这是什么原因呢?堆栈问题?
|
|