NCBI C++ ToolKit
rpc.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: rpc.cpp 99071 2023-02-09 17:00:30Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Vladimir Soussov
27  *
28  * File Description: CTLib RPC command
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
34 #include <dbapi/driver/public.hpp>
35 #include <dbapi/error_codes.hpp>
36 
37 
38 #define NCBI_USE_ERRCODE_X Dbapi_CTlib_Cmds
39 
40 #undef NCBI_DATABASE_THROW
41 #define NCBI_DATABASE_THROW(ex_class, message, err_code, severity) \
42  NCBI_DATABASE_THROW_ANNOTATED(ex_class, message, err_code, severity, \
43  GetDbgInfo(), GetConnection(), GetLastParams())
44 // No use of NCBI_DATABASE_RETHROW or DATABASE_DRIVER_*_EX here.
45 
47 
48 #ifdef FTDS_IN_USE
49 namespace NCBI_NS_FTDS_CTLIB
50 {
51 #endif
52 
53 /////////////////////////////////////////////////////////////////////////////
54 //
55 // CTL_RPCCmd::
56 //
57 
59  const string& proc_name
60  )
61 : CTL_LRCmd(conn, proc_name)
62 {
63  SetExecCntxInfo("RPC Command: " + GetQuery());
64 }
65 
66 
67 CDBParams&
69 {
70  if (m_InParams.get() == NULL) {
72  GetQuery(),
73  GetConnImpl(),
75  )
76  );
77  }
78 
79  return *m_InParams;
80 }
81 
82 
84 {
86  Cancel();
87 
88  SetHasFailed(false);
89 
92  const_cast<char*>(GetQuery().data()),
93  static_cast<CS_INT>(GetQuery().size()),
95  "ct_command failed", 121001);
96 
98  CHECK_DRIVER_ERROR( HasFailed(), "Cannot assign the params." + GetDbgInfo(), 121003 );
99 
100  return SendInternal();
101 }
102 
103 
105 {
106  return MakeResult();
107 }
108 
110 {
111  return WasSent();
112 }
113 
114 
116 {
117  return m_RowCount;
118 }
119 
120 
122 {
123  try {
124  DropCmd(*this);
125 
126  x_Close();
127 
128  DetachInterface();
129  }
131 }
132 
133 
134 void
136 {
137  if (x_GetSybaseCmd()) {
138 
140  Cancel();
141 
142  DropSybaseCmd();
143  }
144 }
145 
146 
148 {
149  CS_DATAFMT param_fmt;
150  memset(&param_fmt, 0, sizeof(param_fmt));
151  param_fmt.format = CS_FMT_UNUSED;
152 
153  for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); i++) {
154 
155  if(GetBindParamsImpl().GetParamStatus(i) == 0) continue;
156  CDB_Object& param = *GetBindParamsImpl().GetParam(i);
157  const string& param_name = GetBindParamsImpl().GetParamName(i);
158 
159  param_fmt.status =
162 
163  if ( !AssignCmdParam(param,
164  param_name,
165  param_fmt,
166  false/*!declare_only*/) ) {
167  return false;
168  }
169  }
170 
171  return true;
172 }
173 
174 #ifdef FTDS_IN_USE
175 } // namespace NCBI_NS_FTDS_CTLIB
176 #endif
177 
179 
180 
CDBParams.
Definition: interfaces.hpp:154
void DropCmd(impl::CCommand &cmd)
CTL_Connection & GetConnection(void)
virtual void SetHasFailed(bool flag=true)
Definition: interfaces.hpp:700
void SetExecCntxInfo(const string &info)
Definition: interfaces.hpp:675
const TDbgInfo & GetDbgInfo(void) const
Definition: interfaces.hpp:711
bool AssignCmdParam(CDB_Object &param, const string &param_name, CS_DATAFMT &param_fmt, bool declare_only=false)
Definition: lang_cmd.cpp:230
void DropSybaseCmd(void)
Definition: lang_cmd.cpp:204
CS_COMMAND * x_GetSybaseCmd(void) const
void DeleteResultInternal(void)
CS_RETCODE CheckSFB(CS_RETCODE rc, const char *msg, unsigned int msg_num)
Definition: lang_cmd.cpp:673
bool SendInternal(void)
Definition: lang_cmd.cpp:929
CDB_Result * MakeResult(void)
Definition: lang_cmd.cpp:840
bool Cancel(void) override
Cancel the command execution.
Definition: lang_cmd.cpp:849
bool x_AssignParams(void)
Definition: rpc.cpp:147
virtual bool Send(void)
Send command to the server.
Definition: rpc.cpp:83
virtual int RowCount(void) const
Get the number of rows affected by the command Special case: negative on error or if there is no way ...
Definition: rpc.cpp:115
virtual CDBParams & GetBindParams(void)
Binding.
Definition: rpc.cpp:68
virtual CDB_Result * Result(void)
Get result set.
Definition: rpc.cpp:104
void x_Close(void)
Definition: rpc.cpp:135
virtual bool HasMoreResults(void) const
Definition: rpc.cpp:109
CTL_RPCCmd(CTL_Connection &con, const string &proc_name)
Definition: rpc.cpp:58
virtual ~CTL_RPCCmd(void)
Definition: rpc.cpp:121
unique_ptr< CDBParams > m_InParams
Definition: interfaces.hpp:903
const string & GetQuery(void) const
virtual bool HasFailed(void) const
const CDB_Params & GetBindParamsImpl(void) const
void DetachInterface(void)
bool NeedToRecompile(void) const
bool WasSent(void) const
impl::CConnection & GetConnImpl(void) const
CDB_Object * GetParam(unsigned int param_no) const
Definition: parameters.hpp:63
const string & GetParamName(unsigned int param_no) const
Definition: parameters.hpp:67
TStatus GetParamStatus(unsigned int param_no) const
Definition: parameters.hpp:83
unsigned int NofParams() const
Definition: parameters.hpp:59
#define CS_INPUTVALUE
Definition: cspublic.h:293
#define CS_FMT_UNUSED
Definition: cspublic.h:398
#define CS_RETURN
Definition: cspublic.h:295
#define CS_RPC_CMD
Definition: cspublic.h:442
#define CS_UNUSED
Definition: cspublic.h:425
@ CS_RECOMPILE
Definition: cspublic.h:382
Int4 CS_INT
Definition: cstypes.h:41
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
CS_RETCODE ct_command(CS_COMMAND *cmd, CS_INT type, const CS_VOID *buffer, CS_INT buflen, CS_INT option)
Definition: ct.c:760
char data[12]
Definition: iconv.c:80
#define NULL
Definition: ncbistd.hpp:225
#define CHECK_DRIVER_ERROR(failed, message, err_code)
Definition: exception.hpp:765
#define NCBI_CURRENT_FUNCTION
Get current function name.
Definition: ncbidiag.hpp:142
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
CS_INT format
Definition: cstypes.h:126
CS_INT status
Definition: cstypes.h:130
Modified on Wed Apr 17 13:08:53 2024 by modify_doxy.py rev. 669887