簡體   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