繁体   English   中英

在关闭Occi :: Connection之前复制Occi :: ResultSet

[英]Copy Occi::ResultSet before closing Occi::Connection

我正在使用OCCI和C ++从Oracle获取数据。 代码运行良好,但我注意到一些性能下降。 发生这种情况是因为在rset-> next()迭代中,一些计算需要时间。 这种延迟的影响是oracle连接池有一个连接忙。 如果并发请求需要相同的计算,则池中的所有连接可能都是BUSY。

     Statement *stmt = conn->createStatement (sqlQuery);

      ResultSet *rset = stmt->executeQuery ();
      while (rset->next ())
      {
        //Slow computation takes time
        compute()
      }

      stmt->closeResultSet (rset);

      conn->terminateStatement (stmt);
      env->terminateConnection (conn);

所以我的问题是:我可以复制Occi :: ResultSet(使用共享指针吗?)以便在复制后关闭连接并在释放连接后进行计算?

go_to_oracle( ResultSet &result) {
 Statement *stmt = conn->createStatement (sqlQuery);

  ResultSet *rset = stmt->executeQuery ();

  copy_rset_to_result;


  stmt->closeResultSet (rset);

  conn->terminateStatement (stmt);
  env->terminateConnection (conn);
}

my_method() {

 ResultSet *result = NULL
 go_to_oracle(result);
 //here connection is closed, but we have the data
 compute(result) // do this without have connection occupied

}

GitHub上有哪些例子?

无法关闭与数据库的连接并保存结果集(occi :: ResultSet)以供以后使用。 一个原因是occi :: ResultSet :: next从数据库中检索数据。 相反,您可以使用数组提取和用户分配的数据缓冲区来存储结果。

使用occi :: ResultSet :: setDataBuffer的示例:

oracle::occi::ResultSet* rs=nullptr;
//.....
// query
//.....
static const size_t max_numrows=5000;
char var_buf[max_numrows][7];
char sym_buf[max_numrows][9];
rs->setDataBuffer(1,var_buf,oracle::occi::OCCI_SQLT_STR,sizeof(var_buf[0]),(ub2*)0);
rs->setDataBuffer(2,sym_buf,oracle::occi::OCCI_SQLT_STR,sizeof(sym_buf[0]),(ub2*)0);
size_t fetch_count=0;
while(rs->next(max_numrows)==ResultSet::DATA_AVAILABLE)
{
    /* This would probably be an error as you would like
       the whole result to fit in the data buffer.*/
}
stmt->closeResultSet (rs);
conn->terminateStatement (stmt);
compute(var_buf,sym_buf);

请注意,数组提取的作用类似于预取

Status next(
   unsigned int numRows =1);

每次调用最多可获取numRows。

执行查询不检索数据。 您使用rset-> next()从服务器读取数据。 因此,如果您终止连接 - 您无法读取数据

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM