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

Go to the SVN repository for this file.

1 /* $Id: bulkinsert.cpp 44442 2010-01-13 20:05:34Z ivanovp $
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: bulkinsert.cpp 44442 2010-01-13 20:05:34Z ivanovp $
27 *
28 * Author: Michael Kholodov
29 *
30 * File Description: Base class for database access
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include "conn_impl.hpp"
35 #include "bulkinsert.hpp"
37 #include <dbapi/driver/public.hpp>
38 #include <dbapi/error_codes.hpp>
39 
40 
41 #define NCBI_USE_ERRCODE_X Dbapi_BulkInsert
42 
44 
45 // implementation
48  : m_cmd(0), m_conn(conn)
49 {
50  m_cmd = m_conn->GetCDB_Connection()->BCPIn(name);
51  SetIdent("CDBAPIBulkInsert");
52 }
53 
55 {
56  try {
58  FreeResources();
60  _TRACE(GetIdent() << " " << (void*)this << " deleted.");
61  }
63 }
64 
66 {
68  FreeResources();
69 }
70 
72 {
73  delete m_cmd;
74  m_cmd = 0;
75  if( m_conn != 0 && m_conn->IsAux() ) {
76  delete m_conn;
77  m_conn = 0;
79  }
80 }
81 
83 {
84  // GetBCPInCmd()->GetBindParams().Bind(col - 1, v->GetData());
85 
86  if (param.IsPositional()) {
87  // Decrement position by ONE.
88  GetBCPInCmd()->GetBindParams().Bind(param.GetPosition() - 1, v->GetData());
89  } else {
90  GetBCPInCmd()->GetBindParams().Bind(param, v->GetData());
91  }
92 }
93 
94 
96 {
97  GetBCPInCmd()->SetHints(hints);
98 }
99 
100 void CDBAPIBulkInsert::AddHint(EHints hint, unsigned int value /* = 0 */)
101 {
103 }
104 
106 {
108 }
109 
111 {
112  GetBCPInCmd()->SendRow();
113 }
114 
116 {
118 }
119 
121 {
122  GetBCPInCmd()->Cancel();
123 }
124 
126 {
128 }
129 
131 {
132  _TRACE(GetIdent() << " " << (void*)this << ": '" << e.GetName()
133  << "' from " << e.GetSource()->GetIdent());
134 
135  if(dynamic_cast<const CDbapiDeletedEvent*>(&e) != 0 ) {
137  if(dynamic_cast<CConnection*>(e.GetSource()) != 0 ) {
138  _TRACE("Deleting " << GetIdent() << " " << (void*)this);
139  delete this;
140  }
141  }
142 }
143 
void RemoveListener(CActiveObject *obj)
Definition: active_obj.cpp:60
void SetIdent(const string &name)
Definition: active_obj.cpp:98
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:107
void FreeResources()
Definition: bulkinsert.cpp:71
void SetHints(CTempString hints)
Set hints by one call. Resets everything that was set by Add*Hint().
Definition: bulkinsert.cpp:95
virtual void Action(const CDbapiEvent &e)
Definition: bulkinsert.cpp:130
CConnection * m_conn
Definition: bulkinsert.hpp:77
CDB_BCPInCmd * GetBCPInCmd()
Definition: bulkinsert.hpp:71
virtual void Close()
Close.
Definition: bulkinsert.cpp:65
virtual void Cancel()
Cancel bulk insert.
Definition: bulkinsert.cpp:120
virtual void Bind(const CDBParamVariant &param, CVariant *v)
Bind column.
Definition: bulkinsert.cpp:82
virtual ~CDBAPIBulkInsert()
Definition: bulkinsert.cpp:54
void AddOrderHint(CTempString columns)
Add "ORDER" hint.
Definition: bulkinsert.cpp:105
virtual void Complete()
Complete batch.
Definition: bulkinsert.cpp:125
CDBAPIBulkInsert(const string &table, CConnection *conn)
Definition: bulkinsert.cpp:46
CDB_BCPInCmd * m_cmd
Definition: bulkinsert.hpp:76
void AddHint(EHints hint, unsigned int value=0)
Add hint with value.
Definition: bulkinsert.cpp:100
virtual void StoreBatch()
Store batch of rows.
Definition: bulkinsert.cpp:115
virtual void AddRow()
Add row to the batch.
Definition: bulkinsert.cpp:110
string GetName() const
Definition: active_obj.hpp:57
CActiveObject * GetSource() const
Definition: active_obj.hpp:55
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CVariant –.
Definition: variant.hpp:99
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static const column_t columns[]
Definition: utf8_2.c:22
EHints
Type of hint that can be set.
Definition: dbapi.hpp:680
bool IsPositional(void) const
Definition: interfaces.hpp:115
virtual CDBParams & Bind(const CDBParamVariant &param, CDB_Object *value, bool out_param=false)
This method stores pointer to data.
Definition: interfaces.cpp:150
unsigned int GetPosition(void) const
Definition: interfaces.hpp:119
virtual bool SendRow()
Send row to the server.
Definition: public.cpp:975
virtual bool CompleteBatch()
Complete batch – to store all rows transferred by far in this batch into the table.
Definition: public.cpp:994
virtual CDB_BCPInCmd * BCPIn(const string &table_name)
Make "bulk copy in" command.
Definition: public.cpp:369
void AddOrderHint(CTempString columns)
Add "ORDER" hint.
Definition: public.cpp:954
void AddHint(EBCP_Hints hint, unsigned int value=0)
Add hint with value.
Definition: public.cpp:947
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
Definition: public.cpp:961
virtual bool CompleteBCP()
Complete the BCP and store all rows transferred in last batch into the table.
Definition: public.cpp:1005
EBCP_Hints
Type of hint that can be set.
Definition: public.hpp:778
virtual bool Cancel()
Cancel the BCP command.
Definition: public.cpp:988
void SetHints(CTempString hints)
Set hints by one call. Resets everything that was set by Add*Hint().
Definition: public.cpp:940
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).
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Modified on Fri Sep 20 14:57:27 2024 by modify_doxy.py rev. 669887