bulkinsert.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: bulkinsert.cpp,v $
  4.  * PRODUCTION Revision 1000.3  2004/06/01 19:18:09  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /* $Id: bulkinsert.cpp,v 1000.3 2004/06/01 19:18:09 gouriano Exp $
  10. * ===========================================================================
  11. *
  12. *                            PUBLIC DOMAIN NOTICE                          
  13. *               National Center for Biotechnology Information
  14. *                                                                          
  15. *  This software/database is a "United States Government Work" under the   
  16. *  terms of the United States Copyright Act.  It was written as part of    
  17. *  the author's official duties as a United States Government employee and 
  18. *  thus cannot be copyrighted.  This software/database is freely available 
  19. *  to the public for use. The National Library of Medicine and the U.S.    
  20. *  Government have not placed any restriction on its use or reproduction.  
  21. *                                                                          
  22. *  Although all reasonable efforts have been taken to ensure the accuracy  
  23. *  and reliability of the software and data, the NLM and the U.S.          
  24. *  Government do not and cannot warrant the performance or results that    
  25. *  may be obtained by using this software or data. The NLM and the U.S.    
  26. *  Government disclaim all warranties, express or implied, including       
  27. *  warranties of performance, merchantability or fitness for any particular
  28. *  purpose.                                                                
  29. *                                                                          
  30. *  Please cite the author in any work or product based on this material.   
  31. *
  32. * ===========================================================================
  33. *
  34. * File Name:  $Id: bulkinsert.cpp,v 1000.3 2004/06/01 19:18:09 gouriano Exp $
  35. *
  36. * Author:  Michael Kholodov
  37. *   
  38. * File Description:  Base class for database access
  39. *
  40. *
  41. * $Log: bulkinsert.cpp,v $
  42. * Revision 1000.3  2004/06/01 19:18:09  gouriano
  43. * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
  44. *
  45. * Revision 1.7  2004/05/17 21:10:28  gorelenk
  46. * Added include of PCH ncbi_pch.hpp
  47. *
  48. * Revision 1.6  2004/04/12 14:25:33  kholodov
  49. * Modified: resultset caching scheme, fixed single connection handling
  50. *
  51. * Revision 1.5  2004/04/08 15:56:58  kholodov
  52. * Multiple bug fixes and optimizations
  53. *
  54. * Revision 1.4  2004/03/08 22:15:19  kholodov
  55. * Added: 3 new Get...() methods internally
  56. *
  57. * Revision 1.3  2002/10/03 18:49:59  kholodov
  58. * Added: additional TRACE diagnostics about object deletion
  59. * Fixed: setting parameters in IStatement object is fully supported
  60. * Added: IStatement::ExecuteLast() to execute the last statement with
  61. * different parameters if any
  62. *
  63. * Revision 1.2  2002/09/18 18:49:27  kholodov
  64. * Modified: class declaration and Action method to reflect
  65. * direct inheritance of CActiveObject from IEventListener
  66. *
  67. * Revision 1.1  2002/09/16 19:34:40  kholodov
  68. * Added: bulk insert support
  69. *
  70. *
  71. *
  72. */
  73. #include <ncbi_pch.hpp>
  74. #include "conn_impl.hpp"
  75. #include "bulkinsert.hpp"
  76. #include <dbapi/driver/exception.hpp>
  77. #include <dbapi/driver/public.hpp>
  78. BEGIN_NCBI_SCOPE
  79. // implementation
  80. CBulkInsert::CBulkInsert(const string& name,
  81.                          unsigned int cols,
  82.                          CConnection* conn)
  83.     : m_nofCols(cols), m_cmd(0), m_conn(conn)
  84. {
  85.     SetIdent("CBulkInsert");
  86.     m_cmd = m_conn->GetCDB_Connection()->BCPIn(name, cols);
  87. }
  88. CBulkInsert::~CBulkInsert()
  89. {
  90.     Notify(CDbapiClosedEvent(this));
  91.     FreeResources();
  92.     Notify(CDbapiDeletedEvent(this));
  93.     _TRACE(GetIdent() << " " << (void*)this << " deleted."); 
  94. }
  95. void CBulkInsert::Close()
  96. {
  97.     Notify(CDbapiClosedEvent(this));
  98.     FreeResources();
  99. }
  100. void CBulkInsert::FreeResources()
  101. {
  102.     delete m_cmd;
  103.     m_cmd = 0;
  104.     if( m_conn != 0 && m_conn->IsAux() ) {
  105.     delete m_conn;
  106.     m_conn = 0;
  107.     Notify(CDbapiAuxDeletedEvent(this));
  108.     }
  109. }
  110.  
  111. void CBulkInsert::Bind(unsigned int col, CVariant* v)
  112. {
  113.     GetBCPInCmd()->Bind(col - 1, v->GetData());
  114. }
  115. void CBulkInsert::AddRow()
  116. {
  117.     GetBCPInCmd()->SendRow();
  118. }
  119. void CBulkInsert::StoreBatch() 
  120. {
  121.     GetBCPInCmd()->CompleteBatch();
  122. }
  123. void CBulkInsert::Cancel()
  124. {
  125.     GetBCPInCmd()->Cancel();
  126. }
  127. void CBulkInsert::Complete()
  128. {
  129.     GetBCPInCmd()->CompleteBCP();
  130. }
  131. void CBulkInsert::Action(const CDbapiEvent& e) 
  132. {
  133.     _TRACE(GetIdent() << " " << (void*)this << ": '" << e.GetName() 
  134.            << "' from " << e.GetSource()->GetIdent());
  135.     if(dynamic_cast<const CDbapiDeletedEvent*>(&e) != 0 ) {
  136. RemoveListener(e.GetSource());
  137.         if(dynamic_cast<CConnection*>(e.GetSource()) != 0 ) {
  138.             _TRACE("Deleting " << GetIdent() << " " << (void*)this); 
  139.             delete this;
  140.         }
  141.     }
  142. }
  143. END_NCBI_SCOPE