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

📄 lang_cmd.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: lang_cmd.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:20:51  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//* $Id: lang_cmd.cpp,v 1000.1 2004/06/01 19:20:51 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:  TDS language command * */#include <ncbi_pch.hpp>#include <dbapi/driver/ftds/interfaces.hpp>BEGIN_NCBI_SCOPE/////////////////////////////////////////////////////////////////////////////////  CTDS_LangCmd:://CTDS_LangCmd::CTDS_LangCmd(CTDS_Connection* conn, DBPROCESS* cmd,                           const string& lang_query,                           unsigned int nof_params) :    m_Connect(conn), m_Cmd(cmd), m_Query(lang_query), m_Params(nof_params){    m_WasSent   =  false;    m_HasFailed =  false;    m_Res       =  0;    m_RowCount  = -1;    m_Status    =  0;}bool CTDS_LangCmd::More(const string& query_text){    m_Query.append(query_text);    return true;}bool CTDS_LangCmd::BindParam(const string& param_name, CDB_Object* param_ptr){    return        m_Params.BindParam(CDB_Params::kNoParamNumber, param_name, param_ptr);}bool CTDS_LangCmd::SetParam(const string& param_name, CDB_Object* param_ptr){    return        m_Params.SetParam(CDB_Params::kNoParamNumber, param_name, param_ptr);}bool CTDS_LangCmd::Send(){    if (m_WasSent)        Cancel();    m_HasFailed = false;    if (!x_AssignParams()) {        dbfreebuf(m_Cmd);        m_HasFailed = true;        throw CDB_ClientEx(eDB_Error, 220003, "CTDS_LangCmd::Send",                           "cannot assign params");    }    if (dbcmd(m_Cmd, (char*)(m_Query.c_str())) != SUCCEED) {        dbfreebuf(m_Cmd);        m_HasFailed = true;        throw CDB_ClientEx(eDB_Fatal, 220001, "CTDS_LangCmd::Send",                           "dbcmd failed");    }        m_Connect->TDS_SetTimeout();    if (dbsqlsend(m_Cmd) != SUCCEED) {        m_HasFailed = true;        throw CDB_ClientEx(eDB_Error, 220005, "CTDS_LangCmd::Send",                           "dbsqlsend failed");    }    m_WasSent = true;    m_Status = 0;    return true;}bool CTDS_LangCmd::WasSent() const{    return m_WasSent;}bool CTDS_LangCmd::Cancel(){    if (m_WasSent) {        if (m_Res) {            delete m_Res;            m_Res = 0;        }        m_WasSent = false;        return (dbcancel(m_Cmd) == SUCCEED);    }    dbfreebuf(m_Cmd);    m_Query.erase();    return true;}bool CTDS_LangCmd::WasCanceled() const{    return !m_WasSent;}CDB_Result* CTDS_LangCmd::Result(){    if (m_Res) {        if(m_RowCount < 0) {            m_RowCount= DBCOUNT(m_Cmd);        }        delete m_Res;        m_Res = 0;    }    if (!m_WasSent) {        throw CDB_ClientEx(eDB_Error, 220010, "CTDS_LangCmd::Result",                           "a command has to be sent first");    }    if (m_Status == 0) {        m_Status = 0x1;        if (dbsqlok(m_Cmd) != SUCCEED) {            m_WasSent = false;            m_HasFailed = true;            throw CDB_ClientEx(eDB_Error, 220011, "CTDS_LangCmd::Result",                               "dbsqlok failed");        }    }    if ((m_Status & 0x10) != 0) { // we do have a compute result        m_Res = new CTDS_ComputeResult(m_Cmd, &m_Status);        m_RowCount= 1;        return Create_Result(*m_Res);    }    while ((m_Status & 0x1) != 0) {        switch (dbresults(m_Cmd)) {        case SUCCEED:            if (DBCMDROW(m_Cmd) == SUCCEED) { // we may get rows in this result                m_Res = new CTDS_RowResult(m_Cmd, &m_Status);                m_RowCount = -1;                return Create_Result(*m_Res);            } else {                m_RowCount = DBCOUNT(m_Cmd);                continue;            }        case NO_MORE_RESULTS:            m_Status = 2;            break;        default:            m_HasFailed = true;            throw CDB_ClientEx(eDB_Warning, 221016, "CTDS_RPCCmd::Result",                               "error encountered in command execution");        }        break;    }    // we've done with the row results at this point    // let's look at return parameters and ret status    if (m_Status == 2) {        m_Status = 4;        int n = dbnumrets(m_Cmd);        if (n > 0) {            m_Res = new CTDS_ParamResult(m_Cmd, n);            m_RowCount = 1;            return Create_Result(*m_Res);        }    }    if (m_Status == 4) {        m_Status = 6;        if (dbhasretstat(m_Cmd)) {            m_Res = new CTDS_StatusResult(m_Cmd);            m_RowCount = 1;            return Create_Result(*m_Res);        }    }    m_WasSent = false;    return 0;}bool CTDS_LangCmd::HasMoreResults() const{    return m_WasSent;}void CTDS_LangCmd::DumpResults(){    CDB_Result* dbres;    while(m_WasSent) {        dbres= Result();        if(dbres) {            if(m_Connect->m_ResProc) {                m_Connect->m_ResProc->ProcessResult(*dbres);            }            else {                while(dbres->Fetch());            }            delete dbres;        }    }}bool CTDS_LangCmd::HasFailed() const{    return m_HasFailed;}int CTDS_LangCmd::RowCount() const{    return (m_RowCount < 0)? DBCOUNT(m_Cmd) : m_RowCount;}void CTDS_LangCmd::Release(){    m_BR = 0;    if (m_WasSent) {        Cancel();        m_WasSent = false;    }    m_Connect->DropCmd(*this);    delete this;}

⌨️ 快捷键说明

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