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

Go to the SVN repository for this file.

1 /* $Id: blobstream.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: $Id: blobstream.cpp 71962 2016-04-08 13:52:30Z ucko $
27 *
28 * Author: Michael Kholodov
29 *
30 * File Description: stream implementation for reading and writing BLOBs
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include "blobstream.hpp"
35 
36 #include <dbapi/driver/public.hpp>
37 #include <dbapi/error_codes.hpp>
38 #include "rs_impl.hpp"
39 
40 
41 #define NCBI_USE_ERRCODE_X Dbapi_BlobStream
42 
44 
46 : istream(new CByteStreamBuf(bufsize))
47 {
48  ((CByteStreamBuf*)rdbuf())->SetRs(rs);
49 }
50 
52 {
53  try {
54  delete rdbuf();
55  }
57 }
58 
60  I_BlobDescriptor* desc,
61  size_t datasize,
62  streamsize bufsize,
64  bool destroyConn)
65  : ostream(new CByteStreamBuf(bufsize, flags, connAux)), m_desc(desc),
66  m_conn(connAux), m_destroyConn(destroyConn)
67 {
68  _TRACE("CBlobOStream: flags = " << flags);
69  ((CByteStreamBuf*)rdbuf())
70  ->SetCmd(m_conn->SendDataCmd(*m_desc, datasize,
71  (flags & fBOS_SkipLogging) == 0));
72 }
73 
75  unsigned int item_num,
76  size_t datasize,
77  streamsize bufsize,
80  : ostream(new CByteStreamBuf(bufsize, flags, conn)), m_desc(NULL),
81  m_conn(conn), m_destroyConn(false)
82 {
83  _TRACE("CBlobOStream: flags = " << flags);
84  ((CByteStreamBuf*)rdbuf())
85  ->SetCmd(curCmd->SendDataCmd(item_num, datasize,
86  (flags & fBOS_SkipLogging) == 0));
87 }
88 
90 {
91  try {
92  delete rdbuf();
93  delete m_desc;
94  if( m_destroyConn )
95  delete m_conn;
96  }
98 }
99 
#define false
Definition: bool.h:36
virtual ~CBlobIStream()
Definition: blobstream.cpp:51
CBlobIStream(CResultSet *rs, streamsize bufsize=0)
Definition: blobstream.cpp:45
I_BlobDescriptor * m_desc
Definition: blobstream.hpp:72
virtual ~CBlobOStream()
Definition: blobstream.cpp:89
CDB_Connection * m_conn
Definition: blobstream.hpp:73
bool m_destroyConn
Definition: blobstream.hpp:74
CBlobOStream(CDB_Connection *connAux, I_BlobDescriptor *desc, size_t datasize, streamsize bufsize, TBlobOStreamFlags flags, bool destroyConn=false)
Definition: blobstream.cpp:59
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_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 CDB_SendDataCmd * SendDataCmd(I_BlobDescriptor &desc, size_t data_size, bool log_it=true, bool discard_results=true)
Make "send-data" command.
Definition: public.cpp:385
#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 int bufsize
Definition: pcregrep.c:162
Modified on Tue Dec 05 02:10:31 2023 by modify_doxy.py rev. 669887