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

Go to the SVN repository for this file.

1 /* $Id: rw_impl.cpp 71962 2016-04-08 13:52: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 * File Name: rw_impl.cpp
27 *
28 * Author: Michael Kholodov
29 *
30 * File Description: Reader/writer implementation
31 *
32 *
33 */
34 #include <ncbi_pch.hpp>
35 #include "rw_impl.hpp"
36 #include "rs_impl.hpp"
37 #include <dbapi/driver/public.hpp>
38 #include <dbapi/error_codes.hpp>
39 
40 
41 #define NCBI_USE_ERRCODE_X Dbapi_ObjImpls
42 
44 
46 : m_rs(rs)
47 {
48 
49 }
50 
52 {
53 
54 }
55 
57  size_t count,
58  size_t* bytes_read)
59 {
60  size_t bRead = m_rs->Read(buf, count);
61 
62  if( bytes_read != 0 ) {
63  *bytes_read = bRead;
64  }
65 
66  if( bRead != 0 ) {
67  return eRW_Success;
68  }
69  else {
70  return eRW_Eof;
71  }
72 
73 }
74 
76 {
77  return eRW_NotImplemented;
78 }
79 
80 //------------------------------------------------------------------------------------------------
81 
83  unsigned int item_num,
84  size_t datasize,
86  : m_destroy(false), m_cdbConn(0), m_BytesNeeded(datasize)
87 {
88  m_dataCmd = curCmd->SendDataCmd(item_num, datasize,
89  (flags & fBOS_SkipLogging) == 0);
90 }
91 
94  size_t blobsize,
96  bool destroy)
97  : m_destroy(destroy), m_cdbConn(conn), m_BytesNeeded(blobsize)
98 {
99  if ((flags & fBOS_UseTransaction) != 0) {
100  m_AutoTrans.reset(new CAutoTrans(*conn));
101  }
102  m_dataCmd = conn->SendDataCmd(d, blobsize,
103  (flags & fBOS_SkipLogging) == 0);
104 }
105 
107  size_t count,
108  size_t* bytes_written)
109 {
110  _ASSERT(count <= m_BytesNeeded);
111  size_t bPut = m_dataCmd->SendChunk(buf, count);
112 
113  if( bytes_written != 0 )
114  *bytes_written = bPut;
115 
116  m_BytesNeeded -= bPut;
117  if (m_BytesNeeded == 0 && m_AutoTrans.get() != NULL) {
118  // Promptly release the transaction.
119  m_AutoTrans->Finish();
120  m_AutoTrans.reset();
121  }
122 
123  if (bPut == 0) {
124  m_AutoTrans.reset();
125  return eRW_Eof;
126  } else {
127  return eRW_Success;
128  }
129 }
130 
132 {
133  return eRW_NotImplemented;
134 }
135 
137 {
138  try {
139  delete m_dataCmd;
140  }
142  if (m_destroy) {
143  delete m_cdbConn;
144  }
145 }
146 
147 
#define false
Definition: bool.h:36
virtual size_t Read(void *buf, size_t size)
Read unformatted data.
Definition: rs_impl.cpp:270
virtual ERW_Result Read(void *buf, size_t count, size_t *bytes_read=0)
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
Definition: rw_impl.cpp:56
virtual ~CxBlobReader()
Definition: rw_impl.cpp:51
CResultSet * m_rs
Definition: rw_impl.hpp:60
CxBlobReader(class CResultSet *rs)
Definition: rw_impl.cpp:45
virtual ERW_Result PendingCount(size_t *count)
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
Definition: rw_impl.cpp:75
size_t m_BytesNeeded
Definition: rw_impl.hpp:94
bool m_destroy
Definition: rw_impl.hpp:91
CxBlobWriter(CDB_Connection *conn, I_BlobDescriptor &d, size_t blobsize, TBlobOStreamFlags flags, bool destroy)
Definition: rw_impl.cpp:92
unique_ptr< CAutoTrans > m_AutoTrans
Definition: rw_impl.hpp:93
virtual ~CxBlobWriter()
Definition: rw_impl.cpp:136
CDB_SendDataCmd * m_dataCmd
Definition: rw_impl.hpp:90
virtual ERW_Result Flush(void)
Flush pending data (if any) down to the output device.
Definition: rw_impl.cpp:131
CDB_Connection * m_cdbConn
Definition: rw_impl.hpp:92
virtual ERW_Result Write(const void *buf, size_t count, size_t *bytes_written=0)
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
Definition: rw_impl.cpp:106
I_BlobDescriptor::
Definition: interfaces.hpp:369
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static uch flags
#define NULL
Definition: ncbistd.hpp:225
int TBlobOStreamFlags
Definition: dbapi.hpp:97
@ fBOS_UseTransaction
Use a (sub)transaction (committed once all data's been sent successfully, rolled back for unrecoverab...
Definition: dbapi.hpp:93
@ fBOS_SkipLogging
Definition: dbapi.hpp:94
virtual CDB_SendDataCmd * SendDataCmd(unsigned int item_num, size_t size, bool log_it=true, bool discard_results=true)
Make "send-data" command.
Definition: public.cpp:1069
virtual size_t SendChunk(const void *data, size_t size)
Send chunk of data to the server.
Definition: public.cpp:1123
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
void destroy(P pT)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
ERW_Result
Result codes for I/O operations.
@ eRW_NotImplemented
Action / information is not available.
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Success
Everything is okay, I/O completed.
#define kEmptyStr
Definition: ncbistr.hpp:123
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
char * buf
#define _ASSERT
Modified on Sat Dec 02 09:19:22 2023 by modify_doxy.py rev. 669887