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

Go to the SVN repository for this file.

1 /* $Id: cursor_impl.cpp 79243 2017-08-24 15:46:37Z satskyse $
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: cursor_impl.cpp 79243 2017-08-24 15:46:37Z satskyse $
27 *
28 * Author: Michael Kholodov
29 *
30 * File Description: Cursor implementation class
31 *
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include "conn_impl.hpp"
36 #include "cursor_impl.hpp"
37 #include "rs_impl.hpp"
39 #include <dbapi/driver/public.hpp>
40 #include <dbapi/error_codes.hpp>
41 
42 
43 #define NCBI_USE_ERRCODE_X Dbapi_ObjImpls
44 
46 
47 // implementation
48 CCursor::CCursor(const string& name,
49  const string& sql,
50  int batchSize,
52  : m_cmd(0), m_conn(conn), m_ostr(0), m_wr(0)
53 {
54  SetIdent("CCursor");
55 
56  m_cmd = m_conn->GetCDB_Connection()->Cursor(name, sql, batchSize);
57 }
58 
60 {
61  try {
63  FreeResources();
65  _TRACE(GetIdent() << " " << (void*)this << " deleted.");
66  }
68 }
69 
70 
72 {
73  return m_conn;
74 }
75 
76 void CCursor::SetParam(const CVariant& v,
77  const CDBParamVariant& param)
78 {
79  if (param.IsPositional()) {
80  // Decrement position by ONE.
81  GetCursorCmd()->GetBindParams().Set(param.GetPosition() - 1, v.GetData());
82  } else {
83  GetCursorCmd()->GetBindParams().Set(param, v.GetData());
84  }
85 }
86 
87 
89 {
90  CResultSet *ri = new CResultSet(m_conn, GetCursorCmd()->Open());
91  ri->AddListener(this);
92  AddListener(ri);
93  return ri;
94 }
95 
96 void CCursor::Update(const string& table, const string& updateSql)
97 {
98  GetCursorCmd()->Update(table, updateSql);
99 }
100 
101 void CCursor::Delete(const string& table)
102 {
104 }
105 
107  size_t blob_size,
109  size_t buf_size)
110 {
111  // Delete previous ostream
112  delete m_ostr;
113  m_ostr = 0;
114 
116  col - 1,
117  blob_size,
118  flags),
119  buf_size, 0, (CRWStreambuf::fOwnWriter |
121  return *m_ostr;
122 }
123 
125  size_t blob_size,
126  EAllowLog log_it,
127  size_t buf_size)
128 {
129  return ICursor::GetBlobOStream(col, blob_size, log_it, buf_size);
130 }
131 
132 IWriter* CCursor::GetBlobWriter(unsigned int col,
133  size_t blob_size,
135 {
136  // Delete previous writer
137  delete m_wr;
138  m_wr = 0;
139 
141  col - 1,
142  blob_size,
143  flags);
144  return m_wr;
145 }
146 
147 IWriter* CCursor::GetBlobWriter(unsigned int col,
148  size_t blob_size,
149  EAllowLog log_it)
150 {
151  return ICursor::GetBlobWriter(col, blob_size, log_it);
152 }
153 
155 {
156  if( GetCursorCmd() != 0 )
157  GetCursorCmd()->Close();
158 }
159 
161 {
162  Notify(CDbapiClosedEvent(this));
163  FreeResources();
164 }
165 
167 {
168  delete m_cmd;
169  m_cmd = 0;
170  delete m_ostr;
171  m_ostr = 0;
172  if( m_conn != 0 && m_conn->IsAux() ) {
173  delete m_conn;
174  m_conn = 0;
176  }
177 }
178 
180 {
181  _TRACE(GetIdent() << " " << (void*)this << ": '" << e.GetName()
182  << "' from " << e.GetSource()->GetIdent());
183 
184  if(dynamic_cast<const CDbapiDeletedEvent*>(&e) != 0 ) {
186  if(dynamic_cast<CConnection*>(e.GetSource()) != 0 ) {
187  _TRACE("Deleting " << GetIdent() << " " << (void*)this);
188  delete this;
189  }
190  }
191 }
192 
void RemoveListener(CActiveObject *obj)
Definition: active_obj.cpp:60
void SetIdent(const string &name)
Definition: active_obj.cpp:98
void AddListener(CActiveObject *obj)
Definition: active_obj.cpp:50
string GetIdent() const
Definition: active_obj.cpp:93
void Notify(const CDbapiEvent &e)
Definition: active_obj.cpp:71
bool IsAux()
Definition: conn_impl.hpp:116
virtual CDB_Connection * GetCDB_Connection()
Returns the internal driver connection object.
Definition: conn_impl.cpp:105
CConnection * m_conn
virtual void Update(const string &table, const string &updateSql)
Update statement for cursor.
Definition: cursor_impl.cpp:96
virtual void Close()
Close cursor.
class CxBlobWriter * m_wr
virtual void SetParam(const CVariant &v, const CDBParamVariant &param)
Set input parameter.
Definition: cursor_impl.cpp:76
void FreeResources()
virtual IResultSet * Open()
Open cursor and get corresponding resultset.
Definition: cursor_impl.cpp:88
ostream * m_ostr
CDB_CursorCmd * m_cmd
CNcbiOstream & GetBlobOStream(unsigned int col, size_t blob_size, TBlobOStreamFlags flags, size_t buf_size)
Get output stream for BLOB updates, requires BLOB column number.
virtual ~CCursor()
Definition: cursor_impl.cpp:59
virtual void Cancel()
Cancel cursor.
virtual void Action(const CDbapiEvent &e)
CCursor(const string &name, const string &sql, int batchSize, CConnection *conn)
Definition: cursor_impl.cpp:48
virtual IWriter * GetBlobWriter(unsigned int col, size_t blob_size, TBlobOStreamFlags flags)
Get Blob Writer.
CDB_CursorCmd * GetCursorCmd()
virtual IConnection * GetParentConn()
Get the parent connection.
Definition: cursor_impl.cpp:71
virtual void Delete(const string &table)
Delete statement for cursor.
string GetName() const
Definition: active_obj.hpp:57
CActiveObject * GetSource() const
Definition: active_obj.hpp:55
@ fLogExceptions
Exceptions logged only.
Definition: rwstreambuf.hpp:71
@ fOwnWriter
Own the underlying writer.
Definition: rwstreambuf.hpp:67
CVariant –.
Definition: variant.hpp:99
Writer-based output stream.
Definition: rwstream.hpp:171
A very basic data-write interface.
static uch flags
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static char sql[1024]
Definition: putdata.c:19
virtual IWriter * GetBlobWriter(unsigned int col, size_t blob_size, TBlobOStreamFlags flags=0)=0
Get Blob Writer.
virtual CNcbiOstream & GetBlobOStream(unsigned int col, size_t blob_size, TBlobOStreamFlags flags=0, size_t buf_size=0)=0
Get output stream for BLOB updates, requires BLOB column number.
int TBlobOStreamFlags
Definition: dbapi.hpp:97
EAllowLog
EDataSource –.
Definition: dbapi.hpp:72
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
virtual bool Delete(const string &table_name)
Delete the last fetched row.
Definition: public.cpp:1079
virtual bool Close()
Close the cursor.
Definition: public.cpp:1091
virtual CDB_CursorCmd * Cursor(const string &cursor_name, const string &query, unsigned int batch_size)
Make cursor command.
Definition: public.cpp:376
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
Definition: public.cpp:1034
virtual bool Update(const string &table_name, const string &upd_query)
Update the last fetched row.
Definition: public.cpp:1055
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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
Modified on Thu May 23 12:35:26 2024 by modify_doxy.py rev. 669887