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

Go to the SVN repository for this file.

1 /* $Id: cstmt_impl.cpp 58116 2013-05-13 13:59:10Z 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 * File Name: $Id: cstmt_impl.cpp 58116 2013-05-13 13:59:10Z ucko $
27 *
28 * Author: Michael Kholodov
29 *
30 * File Description: Callable statement implementation
31 *
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include "conn_impl.hpp"
36 #include "cstmt_impl.hpp"
37 #include "rs_impl.hpp"
38 #include <dbapi/driver/public.hpp>
39 #include <dbapi/error_codes.hpp>
40 
41 
42 #define NCBI_USE_ERRCODE_X Dbapi_ObjImpls
43 
45 
46 // implementation
50 , m_status(0)
51 , m_StatusIsAvailable(false)
52 {
53  SetBaseCmd(conn->GetCDB_Connection()->RPC(proc));
54  SetIdent("CCallableStatement");
55 }
56 
58 {
59  try {
61  }
63 }
64 
66 {
67  return (CDB_RPCCmd*)GetBaseCmd();
68 }
69 
71 {
72  _TRACE("CCallableStatement::HasMoreResults(): Calling parent method");
73  bool more = CStatement::HasMoreResults();
74 
75  if (more
76  && GetCDB_Result() != 0
77  && GetCDB_Result()->ResultType() == eDB_StatusResult ) {
78 
79  _TRACE("CCallableStatement::HasMoreResults(): Status result received");
80  CDB_Int *res = 0;
81  while( GetCDB_Result()->Fetch() ) {
82  res = dynamic_cast<CDB_Int*>(GetCDB_Result()->GetItem());
83  }
84 
85  if( res != 0 ) {
86  m_status = res->Value();
87  m_StatusIsAvailable = true;
88  _TRACE("CCallableStatement::HasMoreResults(): Return status "
89  << m_status );
90  delete res;
91  }
92 
94  }
95 
96  return more;
97 }
98 
100  const CDBParamVariant& param)
101 {
102  if (param.IsPositional()) {
103  // Decrement position by ONE.
104  GetRpcCmd()->GetBindParams().Set(param.GetPosition() - 1, v.GetData());
105  } else {
106  GetRpcCmd()->GetBindParams().Set(param, v.GetData());
107  }
108 }
109 
111  const CDBParamVariant& param)
112 {
113  if (param.IsPositional()) {
114  // Decrement position by ONE.
115  GetRpcCmd()->GetBindParams().Set(param.GetPosition() - 1, v.GetData(), true);
116  } else {
117  GetRpcCmd()->GetBindParams().Set(param, v.GetData(), true);
118  }
119 }
120 
121 
123 {
124  SetFailed(false);
125 
126  // Reset status value ...
127  m_status = 0;
128  m_StatusIsAvailable = false;
129 
130  _TRACE("Executing stored procedure: " + GetRpcCmd()->GetProcName());
131  GetRpcCmd()->Send();
132 
133  if ( IsAutoClearInParams() ) {
134  // Implicitely clear all parameters.
135  ClearParamList();
136  }
137 }
138 
140 {
141  Execute();
142 
143  PurgeResults();
144 }
145 
147 {
148  CHECK_NCBI_DBAPI(!m_StatusIsAvailable, "Return status is not available yet.");
149 
150  /*
151  if (!m_StatusIsAvailable) {
152  ERR_POST_X(10, Warning << "Return status is not available yet.");
153  }
154  */
155 
156  return m_status;
157 }
158 
159 
161 {
162  Notify(CDbapiClosedEvent(this));
163  FreeResources();
164 }
165 
166 
#define false
Definition: bool.h:36
void SetIdent(const string &name)
Definition: active_obj.cpp:98
void Notify(const CDbapiEvent &e)
Definition: active_obj.cpp:71
CCallableStatement(const string &proc, CConnection *conn)
Definition: cstmt_impl.cpp:47
CDB_RPCCmd * GetRpcCmd()
Definition: cstmt_impl.cpp:65
virtual int GetReturnStatus()
Get return status from the stored procedure.
Definition: cstmt_impl.cpp:146
virtual bool HasMoreResults()
Check for more results available.
Definition: cstmt_impl.cpp:70
virtual ~CCallableStatement()
Definition: cstmt_impl.cpp:57
virtual void SetParam(const CVariant &v, const CDBParamVariant &param)
Set input parameters.
Definition: cstmt_impl.cpp:99
virtual void Execute()
Execute stored procedure.
Definition: cstmt_impl.cpp:122
virtual void SetOutputParam(const CVariant &v, const CDBParamVariant &param)
Set output parameter, which will be returned as resultset.
Definition: cstmt_impl.cpp:110
virtual void ExecuteUpdate()
Executes stored procedure no results returned.
Definition: cstmt_impl.cpp:139
virtual void Close()
Close statement.
Definition: cstmt_impl.cpp:160
CDB_Result * GetCDB_Result()
Definition: stmt_impl.cpp:317
virtual void PurgeResults()
Purge results.
Definition: stmt_impl.cpp:364
I_BaseCmd * GetBaseCmd()
Definition: stmt_impl.hpp:124
virtual void ClearParamList()
Clear parameter list.
Definition: stmt_impl.cpp:204
void FreeResources()
Definition: stmt_impl.cpp:344
virtual bool HasMoreResults()
Check for more results available.
Definition: stmt_impl.cpp:147
virtual bool IsAutoClearInParams(void) const
Get auto-clear input parameter flag value.
Definition: stmt_impl.hpp:117
void SetFailed(bool f)
Definition: stmt_impl.hpp:128
void SetBaseCmd(I_BaseCmd *cmd)
Definition: stmt_impl.hpp:123
CVariant –.
Definition: variant.hpp:99
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
#define CHECK_NCBI_DBAPI(failed, message)
Definition: dbexception.hpp:62
bool IsPositional(void) const
Definition: interfaces.hpp:115
virtual CDBParams & Set(const CDBParamVariant &param, CDB_Object *value, bool out_param=false)
This method stores copy of data.
Definition: interfaces.cpp:161
unsigned int GetPosition(void) const
Definition: interfaces.hpp:119
@ eDB_StatusResult
Definition: interfaces.hpp:390
virtual bool Send()
Send command to the server.
Definition: public.cpp:839
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
Definition: public.cpp:825
virtual CDB_Object * GetItem(CDB_Object *item_buf=0, EGetItem policy=eAppendLOB)
Get a result item (you can use either GetItem or ReadItem).
Definition: public.cpp:672
Int4 Value() const
Definition: types.hpp:373
CDB_Object * GetData() const
Definition: variant.hpp:269
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#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
#define kEmptyStr
Definition: ncbistr.hpp:123
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
static const char * proc
Definition: stats.c:21
Modified on Sat Dec 02 09:22:54 2023 by modify_doxy.py rev. 669887