cursor.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:26k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: cursor.cpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 19:19:41  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /* $Id: cursor.cpp,v 1000.1 2004/06/01 19:19:41 gouriano Exp $
  10.  * ===========================================================================
  11.  *
  12.  *                            PUBLIC DOMAIN NOTICE
  13.  *               National Center for Biotechnology Information
  14.  *
  15.  *  This software/database is a "United States Government Work" under the
  16.  *  terms of the United States Copyright Act.  It was written as part of
  17.  *  the author's official duties as a United States Government employee and
  18.  *  thus cannot be copyrighted.  This software/database is freely available
  19.  *  to the public for use. The National Library of Medicine and the U.S.
  20.  *  Government have not placed any restriction on its use or reproduction.
  21.  *
  22.  *  Although all reasonable efforts have been taken to ensure the accuracy
  23.  *  and reliability of the software and data, the NLM and the U.S.
  24.  *  Government do not and cannot warrant the performance or results that
  25.  *  may be obtained by using this software or data. The NLM and the U.S.
  26.  *  Government disclaim all warranties, express or implied, including
  27.  *  warranties of performance, merchantability or fitness for any particular
  28.  *  purpose.
  29.  *
  30.  *  Please cite the author in any work or product based on this material.
  31.  *
  32.  * ===========================================================================
  33.  *
  34.  * Author:  Vladimir Soussov
  35.  *
  36.  * File Description:  CTLib cursor command
  37.  *
  38.  */
  39. #include <ncbi_pch.hpp>
  40. #include <dbapi/driver/ctlib/interfaces.hpp>
  41. BEGIN_NCBI_SCOPE
  42. /////////////////////////////////////////////////////////////////////////////
  43. //
  44. //  CTL_CursorCmd::
  45. //
  46. CTL_CursorCmd::CTL_CursorCmd(CTL_Connection* conn, CS_COMMAND* cmd,
  47.                              const string& cursor_name, const string& query,
  48.                              unsigned int nof_params, unsigned int fetch_size)
  49.     : m_Connect(conn),
  50.       m_Cmd(cmd),
  51.       m_Name(cursor_name),
  52.       m_Query(query),
  53.       m_Params(nof_params),
  54.       m_FetchSize(fetch_size)
  55. {
  56.     m_IsOpen      = false;
  57.     m_HasFailed   = false;
  58.     m_Used        = false;
  59.     m_Res         = 0;
  60.     m_RowCount    = -1;
  61. }
  62. bool CTL_CursorCmd::BindParam(const string& param_name, CDB_Object* param_ptr)
  63. {
  64.     return
  65.         m_Params.BindParam(CDB_Params::kNoParamNumber, param_name, param_ptr);
  66. }
  67. CDB_Result* CTL_CursorCmd::Open()
  68. {
  69.     if ( m_IsOpen ) {
  70.         // need to close it first
  71.         Close();
  72.     }
  73.     if ( !m_Used ) {
  74.         m_HasFailed = false;
  75.         switch ( ct_cursor(m_Cmd, CS_CURSOR_DECLARE,
  76.                            const_cast<char*> (m_Name.c_str()), CS_NULLTERM,
  77.                            const_cast<char*> (m_Query.c_str()), CS_NULLTERM,
  78.                            CS_UNUSED) ) {
  79.         case CS_SUCCEED:
  80.             break;
  81.         case CS_FAIL:
  82.             m_HasFailed = true;
  83.             throw CDB_ClientEx(eDB_Fatal, 122001, "CTL_CursorCmd::Open",
  84.                                "ct_cursor(DECLARE) failed");
  85.         case CS_BUSY:
  86.             throw CDB_ClientEx(eDB_Error, 122002, "CTL_CursorCmd::Open",
  87.                                "the connection is busy");
  88.         }
  89.         if (m_Params.NofParams() > 0) {
  90.             // we do have the parameters
  91.             // check if query is a select statement or a function call
  92.             if (m_Query.find("select") != string::npos  ||
  93.                 m_Query.find("SELECT") != string::npos) {
  94.                 // this is a select
  95.                 if ( !x_AssignParams(true) ) {
  96.                     m_HasFailed = true;
  97.                     throw CDB_ClientEx(eDB_Error, 122003,"CTL_CursorCmd::Open",
  98.                                        "cannot declare the params");
  99.                 }
  100.             }
  101.         }
  102.         if (m_FetchSize > 1) {
  103.             switch ( ct_cursor(m_Cmd, CS_CURSOR_ROWS, 0, CS_UNUSED,
  104.                                0, CS_UNUSED, (CS_INT) m_FetchSize) ) {
  105.             case CS_SUCCEED:
  106.                 break;
  107.             case CS_FAIL:
  108.                 m_HasFailed = true;
  109.                 throw CDB_ClientEx(eDB_Fatal, 122004, "CTL_CursorCmd::Open",
  110.                                    "ct_cursor(ROWS) failed");
  111.             case CS_BUSY:
  112.                 throw CDB_ClientEx(eDB_Error, 122002, "CTL_CursorCmd::Open",
  113.                                    "the connection is busy");
  114.             }
  115.         }
  116.     }
  117.     m_HasFailed = false;
  118.     // open the cursor
  119.     switch ( ct_cursor(m_Cmd, CS_CURSOR_OPEN, 0, CS_UNUSED, 0, CS_UNUSED,
  120.                        m_Used ? CS_RESTORE_OPEN : CS_UNUSED) ) {
  121.     case CS_SUCCEED:
  122.         break;
  123.     case CS_FAIL:
  124.         m_HasFailed = true;
  125.         throw CDB_ClientEx(eDB_Fatal, 122005, "CTL_CursorCmd::Open",
  126.                            "ct_cursor(open) failed");
  127.     case CS_BUSY:
  128.         throw CDB_ClientEx(eDB_Error, 122002, "CTL_CursorCmd::Open",
  129.                            "the connection is busy");
  130.     }
  131.     m_IsOpen = true;
  132.     if (m_Params.NofParams() > 0) {
  133.         // we do have the parameters
  134.         if ( !x_AssignParams(false) ) {
  135.             m_HasFailed = true;
  136.             throw CDB_ClientEx(eDB_Error, 122003, "CTL_CursorCmd::Open",
  137.                                "cannot assign the params");
  138.         }
  139.     }
  140.     // send this command
  141.     switch ( ct_send(m_Cmd) ) {
  142.     case CS_SUCCEED:
  143.         break;
  144.     case CS_FAIL:
  145.         m_HasFailed = true;
  146.         throw CDB_ClientEx(eDB_Error, 122006, "CTL_CursorCmd::Open",
  147.                            "ct_send failed");
  148.     case CS_CANCELED:
  149.         throw CDB_ClientEx(eDB_Error, 122008, "CTL_CursorCmd::Open",
  150.                            "command was canceled");
  151.     case CS_BUSY:
  152.     case CS_PENDING:
  153.         throw CDB_ClientEx(eDB_Error, 122007, "CTL_CursorCmd::Open",
  154.                            "connection has another request pending");
  155.     }
  156.     m_Used = true;
  157.     for (;;) {
  158.         CS_INT res_type;
  159.         switch ( ct_results(m_Cmd, &res_type) ) {
  160.         case CS_SUCCEED:
  161.             break;
  162.         case CS_END_RESULTS:
  163.             return 0;
  164.         case CS_FAIL:
  165.             m_HasFailed = true;
  166.             throw CDB_ClientEx(eDB_Error, 122013, "CTL_CursorCmd::Open",
  167.                                "ct_result failed");
  168.         case CS_CANCELED:
  169.             throw CDB_ClientEx(eDB_Error, 122011, "CTL_CursorCmd::Open",
  170.                                "your command has been canceled");
  171.         case CS_BUSY:
  172.             throw CDB_ClientEx(eDB_Error, 122014, "CTL_CursorCmd::Open",
  173.                                "connection has another request pending");
  174.         default:
  175.             throw CDB_ClientEx(eDB_Error, 122015, "CTL_CursorCmd::Open",
  176.                                "your request is pending");
  177.         }
  178.         switch ( res_type ) {
  179.         case CS_CMD_SUCCEED:
  180.         case CS_CMD_DONE:
  181.             // done with this command -- check the number of affected rows
  182.             g_CTLIB_GetRowCount(m_Cmd, &m_RowCount);
  183.             continue;
  184.         case CS_CMD_FAIL:
  185.             // the command has failed -- check the number of affected rows
  186.             g_CTLIB_GetRowCount(m_Cmd, &m_RowCount);
  187.             m_HasFailed = true;
  188.             while (ct_results(m_Cmd, &res_type) == CS_SUCCEED) {
  189.                 continue;
  190.             }
  191.             throw CDB_ClientEx(eDB_Warning, 122016, "CTL_CursorCmd::Open",
  192.                                "The server encountered an error while "
  193.                                "executing a command");
  194.         case CS_CURSOR_RESULT:
  195.             m_Res = new CTL_CursorResult(m_Cmd);
  196.             break;
  197.         default:
  198.             continue;
  199.         }
  200.         return Create_Result(*m_Res);
  201.     }
  202. }
  203. bool CTL_CursorCmd::Update(const string& table_name, const string& upd_query)
  204. {
  205.     if ( !m_IsOpen ) {
  206.         return false;
  207.     }
  208.     switch ( ct_cursor(m_Cmd, CS_CURSOR_UPDATE,
  209.                        const_cast<char*> (table_name.c_str()), CS_NULLTERM,
  210.                        const_cast<char*> (upd_query.c_str()),  CS_NULLTERM,
  211.                        CS_UNUSED) ) {
  212.     case CS_SUCCEED:
  213.         break;
  214.     case CS_FAIL:
  215.         m_HasFailed = true;
  216.         throw CDB_ClientEx(eDB_Fatal, 122030, "CTL_CursorCmd::Update",
  217.                            "ct_cursor(update) failed");
  218.     case CS_BUSY:
  219.         throw CDB_ClientEx(eDB_Error, 122031, "CTL_CursorCmd::Update",
  220.                            "the connection is busy");
  221.     }
  222.     // send this command
  223.     switch ( ct_send(m_Cmd) ) {
  224.     case CS_SUCCEED:
  225.         break;
  226.     case CS_FAIL:
  227.         m_HasFailed = true;
  228.         throw CDB_ClientEx(eDB_Error, 122032, "CTL_CursorCmd::Update",
  229.                            "ct_send failed");
  230.     case CS_CANCELED:
  231.         throw CDB_ClientEx(eDB_Error, 122033, "CTL_CursorCmd::Update",
  232.                            "command was canceled");
  233.     case CS_BUSY:
  234.     case CS_PENDING:
  235.         throw CDB_ClientEx(eDB_Error, 122034, "CTL_CursorCmd::Update",
  236.                            "connection has another request pending");
  237.     }
  238.     // process the results
  239.     for (;;) {
  240.         CS_INT res_type;
  241.         switch ( ct_results(m_Cmd, &res_type) ) {
  242.         case CS_SUCCEED:
  243.             break;
  244.         case CS_END_RESULTS:
  245.             return true;
  246.         case CS_FAIL:
  247.             m_HasFailed = true;
  248.             throw CDB_ClientEx(eDB_Error, 122035, "CTL_CursorCmd::Update",
  249.                                "ct_result failed");
  250.         case CS_CANCELED:
  251.             throw CDB_ClientEx(eDB_Error, 122036, "CTL_CursorCmd::Update",
  252.                                "your command has been canceled");
  253.         case CS_BUSY:
  254.             throw CDB_ClientEx(eDB_Error, 122037, "CTL_CursorCmd::Update",
  255.                                "connection has another request pending");
  256.         default:
  257.             throw CDB_ClientEx(eDB_Error, 122038, "CTL_CursorCmd::Update",
  258.                                "your request is pending");
  259.         }
  260.         if(m_Connect->m_ResProc) {
  261.             I_Result* res= 0;
  262.             switch (res_type) {
  263.             case CS_ROW_RESULT:
  264.                 res = new CTL_RowResult(m_Cmd);
  265.                 break;
  266.             case CS_PARAM_RESULT:
  267.                 res = new CTL_ParamResult(m_Cmd);
  268.                 break;
  269.             case CS_COMPUTE_RESULT:
  270.                 res = new CTL_ComputeResult(m_Cmd);
  271.                 break;
  272.             case CS_STATUS_RESULT:
  273.                 res = new CTL_StatusResult(m_Cmd);
  274.                 break;
  275.             }
  276.             if(res) {
  277.                 CDB_Result* dbres= Create_Result(*res);
  278.                 m_Connect->m_ResProc->ProcessResult(*dbres);
  279.                 delete dbres;
  280.                 delete res;
  281.                 continue;
  282.             }
  283.         }
  284.         switch ( res_type ) {
  285.         case CS_CMD_SUCCEED:
  286.         case CS_CMD_DONE: // done with this command
  287.             continue;
  288.         case CS_CMD_FAIL: // the command has failed
  289.             m_HasFailed = true;
  290.             while (ct_results(m_Cmd, &res_type) == CS_SUCCEED) {
  291.                 continue;
  292.             }
  293.             throw CDB_ClientEx(eDB_Warning, 122039, "CTL_CursorCmd::Update",
  294.                                "The server encountered an error while "
  295.                                "executing a command");
  296.         default:
  297.             continue;
  298.         }
  299.     }
  300. }
  301. I_ITDescriptor* CTL_CursorCmd::x_GetITDescriptor(unsigned int item_num)
  302. {
  303.     if(!m_IsOpen || (m_Res == 0)) {
  304.         return 0;
  305.     }
  306.     while(m_Res->CurrentItemNo() < item_num) {
  307.         if(!m_Res->SkipItem()) return 0;
  308.     }
  309.     
  310.     I_ITDescriptor* desc= 0;
  311.     if(m_Res->CurrentItemNo() == item_num) {
  312.         desc= m_Res->GetImageOrTextDescriptor();
  313.     }
  314.     else {
  315.         CTL_ITDescriptor* dsc = new CTL_ITDescriptor;
  316.         
  317.         if (ct_data_info(m_Cmd, CS_GET, item_num+1, &dsc->m_Desc)
  318.             != CS_SUCCEED) {
  319.             delete dsc;
  320.             throw CDB_ClientEx(eDB_Error, 130010,
  321.                                "CTL_CursorCmd::UpdateTextImage",
  322.                                "ct_data_info failed");
  323.         }
  324.         desc= dsc;
  325.     }
  326.     return desc;
  327. }
  328. bool CTL_CursorCmd::UpdateTextImage(unsigned int item_num, CDB_Stream& data, 
  329.     bool log_it)
  330. {
  331.     I_ITDescriptor* desc= x_GetITDescriptor(item_num);
  332.     C_ITDescriptorGuard d_guard(desc);
  333.     return (desc) ? m_Connect->x_SendData(*desc, data, log_it) : false;
  334. }
  335. CDB_SendDataCmd* CTL_CursorCmd::SendDataCmd(unsigned int item_num, size_t size, 
  336.     bool log_it)
  337. {
  338.     I_ITDescriptor* desc= x_GetITDescriptor(item_num);
  339.     C_ITDescriptorGuard d_guard(desc);
  340.     return (desc) ? m_Connect->SendDataCmd(*desc, size, log_it) : 0;
  341. }     
  342. bool CTL_CursorCmd::Delete(const string& table_name)
  343. {
  344.     if ( !m_IsOpen ) {
  345.         return false;
  346.     }
  347.     switch ( ct_cursor(m_Cmd, CS_CURSOR_DELETE,
  348.                        const_cast<char*> (table_name.c_str()), CS_NULLTERM,
  349.                        0, CS_UNUSED, CS_UNUSED) ) {
  350.     case CS_SUCCEED:
  351.         break;
  352.     case CS_FAIL:
  353.         m_HasFailed = true;
  354.         throw CDB_ClientEx(eDB_Fatal, 122040, "CTL_CursorCmd::Delete",
  355.                            "ct_cursor(delete) failed");
  356.     case CS_BUSY:
  357.         throw CDB_ClientEx(eDB_Error, 122041, "CTL_CursorCmd::Delete",
  358.                            "the connection is busy");
  359.     }
  360.     // send this command
  361.     switch ( ct_send(m_Cmd) ) {
  362.     case CS_SUCCEED:
  363.         break;
  364.     case CS_FAIL:
  365.         m_HasFailed = true;
  366.         throw CDB_ClientEx(eDB_Error, 122042, "CTL_CursorCmd::Delete",
  367.                            "ct_send failed");
  368.     case CS_CANCELED:
  369.         throw CDB_ClientEx(eDB_Error, 122043, "CTL_CursorCmd::Delete",
  370.                            "command was canceled");
  371.     case CS_BUSY:
  372.     case CS_PENDING:
  373.         throw CDB_ClientEx(eDB_Error, 122044, "CTL_CursorCmd::Delete",
  374.                            "connection has another request pending");
  375.     }
  376.     // process the results
  377.     for (;;) {
  378.         CS_INT res_type;
  379.         switch ( ct_results(m_Cmd, &res_type) ) {
  380.         case CS_SUCCEED:
  381.             break;
  382.         case CS_END_RESULTS:
  383.             return true;
  384.         case CS_FAIL:
  385.             m_HasFailed = true;
  386.             throw CDB_ClientEx(eDB_Error, 122045, "CTL_CursorCmd::Delete",
  387.                                "ct_result failed");
  388.         case CS_CANCELED:
  389.             throw CDB_ClientEx(eDB_Error, 122046, "CTL_CursorCmd::Delete",
  390.                                "your command has been canceled");
  391.         case CS_BUSY:
  392.             throw CDB_ClientEx(eDB_Error, 122047, "CTL_CursorCmd::Delete",
  393.                                "connection has another request pending");
  394.         default:
  395.             throw CDB_ClientEx(eDB_Error, 122048, "CTL_CursorCmd::Delete",
  396.                                "your request is pending");
  397.         }
  398.         if(m_Connect->m_ResProc) {
  399.             I_Result* res= 0;
  400.             switch (res_type) {
  401.             case CS_ROW_RESULT:
  402.                 res = new CTL_RowResult(m_Cmd);
  403.                 break;
  404.             case CS_PARAM_RESULT:
  405.                 res = new CTL_ParamResult(m_Cmd);
  406.                 break;
  407.             case CS_COMPUTE_RESULT:
  408.                 res = new CTL_ComputeResult(m_Cmd);
  409.                 break;
  410.             case CS_STATUS_RESULT:
  411.                 res = new CTL_StatusResult(m_Cmd);
  412.                 break;
  413.             }
  414.             if(res) {
  415.                 CDB_Result* dbres= Create_Result(*res);
  416.                 m_Connect->m_ResProc->ProcessResult(*dbres);
  417.                 delete dbres;
  418.                 delete res;
  419.                 continue;
  420.             }
  421.         }
  422.         switch ( res_type ) {
  423.         case CS_CMD_SUCCEED:
  424.         case CS_CMD_DONE: // done with this command
  425.             continue;
  426.         case CS_CMD_FAIL: // the command has failed
  427.             m_HasFailed = true;
  428.             while(ct_results(m_Cmd, &res_type) == CS_SUCCEED);
  429.             throw CDB_ClientEx(eDB_Warning, 122049, "CTL_CursorCmd::Delete",
  430.                                "The server encountered an error while "
  431.                                "executing a command");
  432.         default:
  433.             continue;
  434.         }
  435.     }
  436. }
  437. int CTL_CursorCmd::RowCount() const
  438. {
  439.     return m_RowCount;
  440. }
  441. bool CTL_CursorCmd::Close()
  442. {
  443.     if ( !m_IsOpen ) {
  444.         return false;
  445.     }
  446.     if (m_Res) {
  447.         delete m_Res;
  448.         m_Res = 0;
  449.     }
  450.     switch ( ct_cursor(m_Cmd, CS_CURSOR_CLOSE, 0, CS_UNUSED, 0, CS_UNUSED,
  451.                        CS_UNUSED) ) {
  452.     case CS_SUCCEED:
  453.         break;
  454.     case CS_FAIL:
  455.         m_HasFailed = true;
  456.         throw CDB_ClientEx(eDB_Fatal, 122020, "CTL_CursorCmd::Close",
  457.                            "ct_cursor(close) failed");
  458.     case CS_BUSY:
  459.         throw CDB_ClientEx(eDB_Error, 122021, "CTL_CursorCmd::Close",
  460.                            "the connection is busy");
  461.     }
  462.     // send this command
  463.     switch ( ct_send(m_Cmd) ) {
  464.     case CS_SUCCEED:
  465.         break;
  466.     case CS_FAIL:
  467.         m_HasFailed = true;
  468.         throw CDB_ClientEx(eDB_Error, 122022, "CTL_CursorCmd::Close",
  469.                            "ct_send failed");
  470.     case CS_CANCELED:
  471.         throw CDB_ClientEx(eDB_Error, 122023, "CTL_CursorCmd::Close",
  472.                            "command was canceled");
  473.     case CS_BUSY:
  474.     case CS_PENDING:
  475.         throw CDB_ClientEx(eDB_Error, 122024, "CTL_CursorCmd::Close",
  476.                            "connection has another request pending");
  477.     }
  478.     m_IsOpen = false;
  479.     CS_INT res_type;
  480.     for (;;) {
  481.         switch ( ct_results(m_Cmd, &res_type) ) {
  482.         case CS_SUCCEED:
  483.             break;
  484.         case CS_END_RESULTS:
  485.             return true;
  486.         case CS_FAIL:
  487.             m_HasFailed = true;
  488.             throw CDB_ClientEx(eDB_Error, 122025, "CTL_CursorCmd::Close",
  489.                                "ct_result failed");
  490.         case CS_CANCELED:
  491.             throw CDB_ClientEx(eDB_Error, 122026, "CTL_CursorCmd::Close",
  492.                                "your command has been canceled");
  493.         case CS_BUSY:
  494.             throw CDB_ClientEx(eDB_Error, 122027, "CTL_CursorCmd::Close",
  495.                                "connection has another request pending");
  496.         default:
  497.             throw CDB_ClientEx(eDB_Error, 122028, "CTL_CursorCmd::Close",
  498.                                "your request is pending");
  499.         }
  500.         if(m_Connect->m_ResProc) {
  501.             I_Result* res= 0;
  502.             switch (res_type) {
  503.             case CS_ROW_RESULT:
  504.                 res = new CTL_RowResult(m_Cmd);
  505.                 break;
  506.             case CS_PARAM_RESULT:
  507.                 res = new CTL_ParamResult(m_Cmd);
  508.                 break;
  509.             case CS_COMPUTE_RESULT:
  510.                 res = new CTL_ComputeResult(m_Cmd);
  511.                 break;
  512.             case CS_STATUS_RESULT:
  513.                 res = new CTL_StatusResult(m_Cmd);
  514.                 break;
  515.             }
  516.             if(res) {
  517.                 CDB_Result* dbres= Create_Result(*res);
  518.                 m_Connect->m_ResProc->ProcessResult(*dbres);
  519.                 delete dbres;
  520.                 delete res;
  521.                 continue;
  522.             }
  523.         }
  524.         switch ( res_type ) {
  525.         case CS_CMD_SUCCEED:
  526.         case CS_CMD_DONE:
  527.             // done with this command
  528.             continue;
  529.         case CS_CMD_FAIL:
  530.             // the command has failed
  531.             m_HasFailed = true;
  532.             while (ct_results(m_Cmd, &res_type) == CS_SUCCEED) {
  533.                 continue;
  534.             }
  535.             throw CDB_ClientEx(eDB_Warning, 122029, "CTL_CursorCmd::Close",
  536.                                "The server encountered an error while "
  537.                                "executing a command");
  538.         }
  539.     }
  540. }
  541. void CTL_CursorCmd::Release()
  542. {
  543.     m_BR = 0;
  544.     if ( m_IsOpen ) {
  545.         Close();
  546.         m_IsOpen = false;
  547.     }
  548.     m_Connect->DropCmd(*this);
  549.     delete this;
  550. }
  551. CTL_CursorCmd::~CTL_CursorCmd()
  552. {
  553.     if ( m_BR ) {
  554.         *m_BR = 0;
  555.     }
  556.     if ( m_IsOpen ) {
  557.         Close();
  558.     }
  559.     if ( m_Used ) {
  560.         // deallocate the cursor
  561.         switch ( ct_cursor(m_Cmd, CS_CURSOR_DEALLOC,
  562.                            0, CS_UNUSED, 0, CS_UNUSED, CS_UNUSED) ) {
  563.         case CS_SUCCEED:
  564.             break;
  565.         case CS_FAIL:
  566.             // m_HasFailed = true;
  567.             //throw CDB_ClientEx(eDB_Fatal, 122050, "::~CTL_CursorCmd",
  568.             //                   "ct_cursor(dealloc) failed");
  569.         case CS_BUSY:
  570.             //throw CDB_ClientEx(eDB_Error, 122051, "::~CTL_CursorCmd",
  571.             //                   "the connection is busy");
  572.             ct_cmd_drop(m_Cmd);
  573.             return;
  574.         }
  575.         // send this command
  576.         switch ( ct_send(m_Cmd) ) {
  577.         case CS_SUCCEED:
  578.             break;
  579.         case CS_FAIL:
  580.             // m_HasFailed = true;
  581.             // throw CDB_ClientEx(eDB_Error, 122052, "::~CTL_CursorCmd",
  582.             //                   "ct_send failed");
  583.         case CS_CANCELED:
  584.             // throw CDB_ClientEx(eDB_Error, 122053, "::~CTL_CursorCmd",
  585.             //                   "command was canceled");
  586.         case CS_BUSY:
  587.         case CS_PENDING:
  588.             // throw CDB_ClientEx(eDB_Error, 122054, "::~CTL_CursorCmd",
  589.             //                   "connection has another request pending");
  590.             ct_cmd_drop(m_Cmd);
  591.             return;
  592.         }
  593.         // process the results
  594.         for (bool need_cont = true;  need_cont; ) {
  595.             CS_INT res_type;
  596.             switch ( ct_results(m_Cmd, &res_type) ) {
  597.             case CS_SUCCEED:
  598.                 break;
  599.             case CS_END_RESULTS:
  600.                 need_cont = false;
  601.                 continue;
  602.             case CS_FAIL:
  603.                 // m_HasFailed = true;
  604.                 //throw CDB_ClientEx(eDB_Error, 122055, "::~CTL_CursorCmd",
  605.                 //                   "ct_result failed");
  606.             case CS_CANCELED:                          
  607.                 // throw CDB_ClientEx(eDB_Error, 122056, "::~CTL_CursorCmd",
  608.                 //                   "your command has been canceled");
  609.             case CS_BUSY:                              
  610.                 // throw CDB_ClientEx(eDB_Error, 122057, "::~CTL_CursorCmd",
  611.                 //                   "connection has another request pending");
  612.             default:                                   
  613.                 //throw CDB_ClientEx(eDB_Error, 122058, "::~CTL_CursorCmd",
  614.                 //                   "your request is pending");
  615.                 need_cont = false;
  616.                 continue;
  617.             }
  618.             if(m_Connect->m_ResProc) {
  619.                 I_Result* res= 0;
  620.                 switch (res_type) {
  621.                 case CS_ROW_RESULT:
  622.                     res = new CTL_RowResult(m_Cmd);
  623.                     break;
  624.                 case CS_PARAM_RESULT:
  625.                     res = new CTL_ParamResult(m_Cmd);
  626.                     break;
  627.                 case CS_COMPUTE_RESULT:
  628.                     res = new CTL_ComputeResult(m_Cmd);
  629.                     break;
  630.                 case CS_STATUS_RESULT:
  631.                     res = new CTL_StatusResult(m_Cmd);
  632.                     break;
  633.                 }
  634.                 if(res) {
  635.                     CDB_Result* dbres= Create_Result(*res);
  636.                     m_Connect->m_ResProc->ProcessResult(*dbres);
  637.                     delete dbres;
  638.                     delete res;
  639.                     continue;
  640.                 }
  641.             }
  642.             switch ( res_type ) {
  643.             case CS_CMD_SUCCEED:
  644.             case CS_CMD_DONE: // done with this command
  645.                 continue;
  646.             case CS_CMD_FAIL: // the command has failed
  647.                 // m_HasFailed = true;
  648.                 while (ct_results(m_Cmd, &res_type) == CS_SUCCEED);
  649.                 // throw CDB_ClientEx(eDB_Warning, 122059, "::~CTL_CursorCmd",
  650.                 //                   "The server encountered an error while "
  651.                 //                   "executing a command");
  652.                 need_cont = false;
  653.             default:
  654.                 continue;
  655.             }
  656.         }
  657.     }
  658. #if 0
  659.     if (ct_cmd_drop(m_Cmd) != CS_SUCCEED) {
  660.         // throw CDB_ClientEx(eDB_Fatal, 122060, "::~CTL_CursorCmd",
  661.         //                   "ct_cmd_drop failed");
  662.     }
  663. #else
  664.     ct_cmd_drop(m_Cmd);
  665. #endif
  666. }
  667. bool CTL_CursorCmd::x_AssignParams(bool declare_only)
  668. {
  669.     CS_DATAFMT param_fmt;
  670.     memset(&param_fmt, 0, sizeof(param_fmt));
  671.     param_fmt.namelen = CS_NULLTERM;
  672.     param_fmt.status  = CS_INPUTVALUE;
  673.     for (unsigned int i = 0;  i < m_Params.NofParams();  i++) {
  674.         if(m_Params.GetParamStatus(i) == 0) continue;
  675.         CDB_Object&   param = *m_Params.GetParam(i);
  676.         const string& param_name = m_Params.GetParamName(i);
  677.         CS_SMALLINT   indicator = (!declare_only  &&  param.IsNULL()) ? -1 : 0;
  678.         if ( !g_CTLIB_AssignCmdParam(m_Cmd, param, param_name, param_fmt,
  679.                                      indicator, declare_only) ) {
  680.             return false;
  681.         }
  682.     }
  683.     return true;
  684. }
  685. END_NCBI_SCOPE
  686. /*
  687.  * ===========================================================================
  688.  * $Log: cursor.cpp,v $
  689.  * Revision 1000.1  2004/06/01 19:19:41  gouriano
  690.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
  691.  *
  692.  * Revision 1.9  2004/05/17 21:12:03  gorelenk
  693.  * Added include of PCH ncbi_pch.hpp
  694.  *
  695.  * Revision 1.8  2003/06/05 16:00:31  soussov
  696.  * adds code for DumpResults and for the dumped results processing
  697.  *
  698.  * Revision 1.7  2003/05/16 20:24:24  soussov
  699.  * adds code to skip parameters if it was not set
  700.  *
  701.  * Revision 1.6  2002/09/16 16:34:16  soussov
  702.  * add try catch when canceling in Release method
  703.  *
  704.  * Revision 1.5  2002/05/16 21:35:22  soussov
  705.  * fixes the memory leak in text/image processing
  706.  *
  707.  * Revision 1.4  2002/03/26 15:34:38  soussov
  708.  * new image/text operations added
  709.  *
  710.  * Revision 1.3  2001/11/06 17:59:55  lavr
  711.  * Formatted uniformly as the rest of the library
  712.  *
  713.  * Revision 1.2  2001/09/25 16:29:57  soussov
  714.  * fixed typo in CTL_CursorCmd::x_AssignParams
  715.  *
  716.  * Revision 1.1  2001/09/21 23:40:02  vakatov
  717.  * -----  Initial (draft) revision.  -----
  718.  * This is a major revamp (by Denis Vakatov, with help from Vladimir Soussov)
  719.  * of the DBAPI "driver" libs originally written by Vladimir Soussov.
  720.  * The revamp involved massive code shuffling and grooming, numerous local
  721.  * API redesigns, adding comments and incorporating DBAPI to the C++ Toolkit.
  722.  *
  723.  * ===========================================================================
  724.  */