⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cursor.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: cursor.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:20:15  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * PRODUCTION * =========================================================================== *//* $Id: cursor.cpp,v 1000.1 2004/06/01 19:20:15 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Author:  Vladimir Soussov * * File Description:  DBLib cursor command * */#include <ncbi_pch.hpp>#ifndef USE_MS_DBLIB#  include <dbapi/driver/dblib/interfaces.hpp>#  include <dbapi/driver/dblib/interfaces_p.hpp>#else#  include <dbapi/driver/msdblib/interfaces.hpp>#  include <dbapi/driver/msdblib/interfaces_p.hpp>#endifBEGIN_NCBI_SCOPE/////////////////////////////////////////////////////////////////////////////////  CDBL_CursorCmd:://CDBL_CursorCmd::CDBL_CursorCmd(CDBL_Connection* con, DBPROCESS* cmd,                               const string& cursor_name, const string& query,                               unsigned int nof_params) :    m_Connect(con), m_Cmd(cmd), m_Name(cursor_name), m_LCmd(0), m_Query(query),    m_Params(nof_params), m_IsOpen(false), m_HasFailed(false),    m_IsDeclared(false), m_Res(0), m_RowCount(-1){}bool CDBL_CursorCmd::BindParam(const string& param_name, CDB_Object* param_ptr){    return        m_Params.BindParam(CDB_Params::kNoParamNumber, param_name, param_ptr);}CDB_Result* CDBL_CursorCmd::Open(){    if (m_IsOpen) { // need to close it first        Close();    }    m_HasFailed = false;    // declare the cursor    if (!x_AssignParams()) {        m_HasFailed = true;        throw CDB_ClientEx(eDB_Error, 222003, "CDBL_CursorCmd::Open",                           "cannot assign params");    }    m_LCmd = 0;    string buff = "declare " + m_Name + " cursor for " + m_Query;    try {        m_LCmd = m_Connect->LangCmd(buff);        m_LCmd->Send();        m_LCmd->DumpResults();#if 0        while (m_LCmd->HasMoreResults()) {            CDB_Result* r = m_LCmd->Result();            if (r) {                while (r->Fetch())                    ;                delete r;            }        }#endif        delete m_LCmd;    } catch (CDB_Exception& ) {        if (m_LCmd) {            delete m_LCmd;            m_LCmd = 0;        }        throw CDB_ClientEx(eDB_Error, 222001, "CDBL_CursorCmd::Open",                           "failed to declare cursor");    }    m_IsDeclared = true;    // open the cursor    m_LCmd = 0;    buff = "open " + m_Name;    try {        m_LCmd = m_Connect->LangCmd(buff);        m_LCmd->Send();        m_LCmd->DumpResults();#if 0        while (m_LCmd->HasMoreResults()) {            CDB_Result* r = m_LCmd->Result();            if (r) {                while (r->Fetch())                    ;                delete r;            }        }#endif        delete m_LCmd;    } catch (CDB_Exception& ) {        if (m_LCmd) {            delete m_LCmd;            m_LCmd = 0;        }        throw CDB_ClientEx(eDB_Error, 222002, "CDBL_CursorCmd::Open",                           "failed to open cursor");    }    m_IsOpen = true;    m_LCmd = 0;    buff = "fetch " + m_Name;    m_LCmd = m_Connect->LangCmd(buff);    m_Res = new CDBL_CursorResult(m_LCmd);    return Create_Result(*m_Res);}bool CDBL_CursorCmd::Update(const string&, const string& upd_query){    if (!m_IsOpen)        return false;    CDB_LangCmd* cmd = 0;    try {        string buff = upd_query + " where current of " + m_Name;        cmd = m_Connect->LangCmd(buff);        cmd->Send();        cmd->DumpResults();#if 0        while (cmd->HasMoreResults()) {            CDB_Result* r = cmd->Result();            if (r) {                while (r->Fetch())                    ;                delete r;            }        }#endif        delete cmd;    } catch (CDB_Exception& ) {        if (cmd)            delete cmd;        throw CDB_ClientEx(eDB_Error, 222004, "CDBL_CursorCmd::Update",                           "update failed");    }    return true;}I_ITDescriptor* CDBL_CursorCmd::x_GetITDescriptor(unsigned int item_num){    if(!m_IsOpen || (m_Res == 0)) {        return 0;    }    while(m_Res->CurrentItemNo() < item_num) {        if(!m_Res->SkipItem()) return 0;    }        I_ITDescriptor* desc= new CDBL_ITDescriptor(m_Cmd, item_num+1);    return desc;}bool CDBL_CursorCmd::UpdateTextImage(unsigned int item_num, CDB_Stream& data,                                      bool log_it){    I_ITDescriptor* desc= x_GetITDescriptor(item_num);    C_ITDescriptorGuard g(desc);        return (desc) ? m_Connect->x_SendData(*desc, data, log_it) : false;}CDB_SendDataCmd* CDBL_CursorCmd::SendDataCmd(unsigned int item_num, size_t size,                                              bool log_it){    I_ITDescriptor* desc= x_GetITDescriptor(item_num);    C_ITDescriptorGuard g(desc);        return (desc) ? m_Connect->SendDataCmd(*desc, size, log_it) : 0;}					    bool CDBL_CursorCmd::Delete(const string& table_name){    if (!m_IsOpen)        return false;    CDB_LangCmd* cmd = 0;    try {        string buff = "delete " + table_name + " where current of " + m_Name;        cmd = m_Connect->LangCmd(buff);        cmd->Send();        cmd->DumpResults();#if 0        while (cmd->HasMoreResults()) {            CDB_Result* r = cmd->Result();            if (r) {                while (r->Fetch())                    ;                delete r;            }        }#endif        delete cmd;    } catch (CDB_Exception& ) {        if (cmd)            delete cmd;        throw CDB_ClientEx(eDB_Error, 222004, "CDBL_CursorCmd::Update",                           "update failed");    }    return true;}int CDBL_CursorCmd::RowCount() const{    return m_RowCount;}bool CDBL_CursorCmd::Close(){    if (!m_IsOpen)        return false;    if (m_Res) {        delete m_Res;        m_Res = 0;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -