1 /* $Id: rpc.cpp 634271 2021-07-07 17:59:34Z ivanov $
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>
33 #include <dbapi/driver/ctlib/interfaces.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
46 BEGIN_NCBI_SCOPE
47
48 #ifdef FTDS_IN_USE
49 namespace NCBI_NS_FTDS_CTLIB
50 {
51 #endif
52
53 /////////////////////////////////////////////////////////////////////////////
54 //
55 // CTL_RPCCmd::
56 //
57
CTL_RPCCmd(CTL_Connection & conn,const string & proc_name)58 CTL_RPCCmd::CTL_RPCCmd(CTL_Connection& conn,
59 const string& proc_name
60 )
61 : CTL_LRCmd(conn, proc_name)
62 {
63 SetExecCntxInfo("RPC Command: " + GetQuery());
64 }
65
66
67 CDBParams&
GetBindParams(void)68 CTL_RPCCmd::GetBindParams(void)
69 {
70 if (m_InParams.get() == NULL) {
71 m_InParams.reset(new impl::CRowInfo_SP_SQL_Server(
72 GetQuery(),
73 GetConnImpl(),
74 GetBindParamsImpl()
75 )
76 );
77 }
78
79 return *m_InParams;
80 }
81
82
Send()83 bool CTL_RPCCmd::Send()
84 {
85 DeleteResultInternal();
86 Cancel();
87
88 SetHasFailed(false);
89
90 CTL_Connection::CCancelModeGuard guard(GetConnection());
91 CheckSFB(ct_command(x_GetSybaseCmd(), CS_RPC_CMD,
92 const_cast<char*>(GetQuery().data()),
93 GetQuery().size(),
94 NeedToRecompile() ? CS_RECOMPILE : CS_UNUSED),
95 "ct_command failed", 121001);
96
97 SetHasFailed(!x_AssignParams());
98 CHECK_DRIVER_ERROR( HasFailed(), "Cannot assign the params." + GetDbgInfo(), 121003 );
99
100 return SendInternal();
101 }
102
103
Result()104 CDB_Result* CTL_RPCCmd::Result()
105 {
106 return MakeResult();
107 }
108
HasMoreResults() const109 bool CTL_RPCCmd::HasMoreResults() const
110 {
111 return WasSent();
112 }
113
114
RowCount() const115 int CTL_RPCCmd::RowCount() const
116 {
117 return m_RowCount;
118 }
119
120
~CTL_RPCCmd()121 CTL_RPCCmd::~CTL_RPCCmd()
122 {
123 try {
124 DropCmd(*this);
125
126 x_Close();
127
128 DetachInterface();
129 }
130 NCBI_CATCH_ALL_X( 7, NCBI_CURRENT_FUNCTION )
131 }
132
133
134 void
x_Close(void)135 CTL_RPCCmd::x_Close(void)
136 {
137 if (x_GetSybaseCmd()) {
138
139 DeleteResultInternal();
140 Cancel();
141
142 DropSybaseCmd();
143 }
144 }
145
146
x_AssignParams()147 bool CTL_RPCCmd::x_AssignParams()
148 {
149 CS_DATAFMT param_fmt;
150 memset(¶m_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 =
160 ((GetBindParamsImpl().GetParamStatus(i) & impl::CDB_Params::fOutput) == 0)
161 ? CS_INPUTVALUE : CS_RETURN;
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
178 END_NCBI_SCOPE
179
180
181