简体   繁体   English

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

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

I am using OCCI with C++ to get data from Oracle. 我正在使用OCCI和C ++从Oracle获取数据。 The code works well, however I noticed some performance decrease. 代码运行良好,但我注意到一些性能下降。 This happens because in the rset->next() iteration some computation takes time. 发生这种情况是因为在rset-> next()迭代中,一些计算需要时间。 The impact of this delay is that the oracle connection pool has one connection busy. 这种延迟的影响是oracle连接池有一个连接忙。 If concurrently requests demand the same computation, the maybe all connection in the pool will be BUSY. 如果并发请求需要相同的计算,则池中的所有连接可能都是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);

So my question is: Can I copy the Occi::ResultSet (using a shared pointer?) in order to close the connection AFTER the copy and do the computation after releasing the connection? 所以我的问题是:我可以复制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

}

Any examples available on GitHub? GitHub上有哪些例子?

It is not possible to close the connection to the database and save the result set (occi::ResultSet) for later use. 无法关闭与数据库的连接并保存结果集(occi :: ResultSet)以供以后使用。 One reason is that occi::ResultSet::next retrieves data from the database. 一个原因是occi :: ResultSet :: next从数据库中检索数据。 Instead you may use array fetch and a user allocated data buffer to store the results. 相反,您可以使用数组提取和用户分配的数据缓冲区来存储结果。

Example of use of occi::ResultSet::setDataBuffer: 使用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);

Note that array fetch acts like prefetch in that 请注意,数组提取的作用类似于预取

Status next(
   unsigned int numRows =1);

fetches up to numRows per call. 每次调用最多可获取numRows。

Execute query does not retrieve data. 执行查询不检索数据。 You read data from server using rset->next (). 您使用rset-> next()从服务器读取数据。 So, if you terminate connection - you cannot read data 因此,如果您终止连接 - 您无法读取数据

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

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