NCBI C++ ToolKit
interfaces.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef DBAPI_DRIVER_MYSQL___INTERFACES__HPP
2 #define DBAPI_DRIVER_MYSQL___INTERFACES__HPP
3 
4 /* $Id: interfaces.hpp 102711 2024-06-28 14:39:22Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Anton Butanayev
30  *
31  * File Description:
32  * Driver for MySQL server
33  *
34  */
35 
36 #include <dbapi/driver/public.hpp> // Kept for compatibility reasons ...
42 
43 #if defined(NCBI_OS_MSWIN)
44 # include <windows.h>
45 #ifdef WIN32_LEAN_AND_MEAN
46 # include <winsock2.h>
47 #endif
48 #endif
49 
50 #include <mysql.h>
51 
53 
54 
55 class CMySQLContext;
56 class CMySQL_Connection;
57 class CMySQL_LangCmd;
58 
59 
60 /////////////////////////////////////////////////////////////////////////////
61 //
62 // CMySQLContext::
63 //
64 
66 {
67  friend class CMySQL_Connection;
68 
69 public:
70  CMySQLContext();
71  virtual ~CMySQLContext();
72 
73 public:
74  virtual bool IsAbleTo(ECapability cpb) const;
75 
76  virtual string GetDriverName(void) const;
77 
78 protected:
79  virtual impl::CConnection* MakeIConnection(const CDBConnParams& params);
80 };
81 
82 
83 
84 /////////////////////////////////////////////////////////////////////////////
85 //
86 // CMySQL_Connection::
87 //
88 
90 {
91  friend class CMySQLContext;
92 
93 protected:
94  CMySQL_Connection(CMySQLContext& cntx, const CDBConnParams& params);
95  virtual ~CMySQL_Connection();
96 
97 protected:
98  virtual bool IsAlive();
99 
100  virtual CDB_LangCmd* LangCmd(const string& lang_query);
101  virtual CDB_SendDataCmd* SendDataCmd(I_BlobDescriptor& desc,
102  size_t data_size,
103  bool log_it = true,
104  bool dump_results = true);
105  virtual CDB_RPCCmd* RPC(const string& rpc_name);
106  virtual CDB_BCPInCmd* BCPIn(const string& table_name);
107  virtual CDB_CursorCmd* Cursor(const string& cursor_name,
108  const string& query,
109  unsigned int batch_size = 1);
110 
111 
112  virtual bool SendData(I_BlobDescriptor& desc, CDB_Stream& lob,
113  bool log_it = true);
114 
115  virtual bool Refresh();
116  virtual I_DriverContext::TConnectionMode ConnectMode() const;
117 
118  // abort the connection
119  // Attention: it is not recommended to use this method unless you absolutely have to.
120  // The expected implementation is - close underlying file descriptor[s] without
121  // destroing any objects associated with a connection.
122  // Returns: true - if succeed
123  // false - if not
124  virtual bool Abort();
125 
126  /// Close an open connection.
127  /// Returns: true - if successfully closed an open connection.
128  /// false - if not
129  virtual bool Close(void);
130 
131  virtual void SetTimeout(size_t nof_secs);
132  virtual void SetCancelTimeout(size_t nof_secs);
133 
134  const TDbgInfo& GetDbgInfo(void) const;
135  virtual string GetVersionString(void) const;
136 
137 private:
138  friend class CMySQL_LangCmd;
139  friend class CMySQL_RowResult;
140 
141  // for NCBI_DATABASE_THROW_ANNOTATED
142  const CDBParams* GetLastParams(void) const;
143 
144  MYSQL m_MySQL;
146  bool m_IsOpen;
147 };
148 
149 
150 
151 /////////////////////////////////////////////////////////////////////////////
152 //
153 // CMySQL_LangCmd::
154 //
155 
157 {
158 protected:
160  const string& lang_query);
161  virtual ~CMySQL_LangCmd();
162 
163 protected:
164  virtual bool Send();
165  virtual bool Cancel();
166  virtual CDB_Result* Result();
167  virtual bool HasMoreResults() const;
168  virtual bool HasFailed() const;
169  virtual int RowCount() const;
170  int LastInsertId() const;
171 
172  void SetExecCntxInfo(const string& info)
173  {
174  m_DbgInfo->extra_msg = info;
175  }
176  const string& GetExecCntxInfo(void) const
177  {
178  return m_DbgInfo->extra_msg;
179  }
180 
182  const TDbgInfo& GetDbgInfo(void) const
183  {
184  return *m_DbgInfo;
185  }
186 
187 public:
188  string EscapeString(const char* str, unsigned long len);
189 
190 private:
191  friend class CMySQL_Connection;
192 
194  {
195  _ASSERT(m_Connect);
196  return *m_Connect;
197  }
198 
199  const CMySQL_Connection& GetConnection(void) const
200  {
201  _ASSERT(m_Connect);
202  return *m_Connect;
203  }
204 
209 };
210 
211 
212 /////////////////////////////////////////////////////////////////////////////
213 //
214 // CMySQL_RowResult::
215 //
216 
218 {
219  friend class CMySQL_LangCmd;
220 
221 protected:
223  virtual ~CMySQL_RowResult();
224 
225 protected:
226  virtual EDB_ResType ResultType() const;
227  virtual bool Fetch();
228  virtual int CurrentItemNo() const;
229  virtual int GetColumnNum(void) const;
230  virtual CDB_Object* GetItem(CDB_Object* item_buf = 0,
232  virtual size_t ReadItem(void* buffer, size_t buffer_size,
233  bool* is_null = 0);
234  virtual I_BlobDescriptor* GetBlobDescriptor();
235  virtual bool SkipItem();
236 
238  {
240  return *m_Connect;
241  }
242 
244  {
245  return GetConnection().GetDbgInfo();
246  }
247 
248  const CDBParams* GetLastParams(void) const
249  {
250  return GetConnection().GetLastParams();
251  }
252 
253 
254 private:
255  MYSQL_RES* m_Result;
256  MYSQL_ROW m_Row;
257  unsigned long* m_Lengths;
260  // SMySQL_ColDescr* m_ColFmt;
261 };
262 
263 /////////////////////////////////////////////////////////////////////////////
265 
266 extern "C"
267 {
268 
270 void
274 
275 } // extern C
276 
277 /////////////////////////////////////////////////////////////////////////////
278 inline
281 }
282 
283 inline
286 }
287 
289 
290 
291 #endif
292 
293 
CDBConnParams::
Definition: interfaces.hpp:258
CDBParams.
Definition: interfaces.hpp:154
friend class CMySQL_Connection
Definition: interfaces.hpp:67
friend class CMySQLContext
Definition: interfaces.hpp:91
CMySQL_LangCmd * m_ActiveCmd
Definition: interfaces.hpp:145
const TDbgInfo & GetDbgInfo(void) const
Definition: interfaces.hpp:279
const CDBParams * GetLastParams(void) const
Definition: interfaces.hpp:284
CMySQL_Connection::TDbgInfo TDbgInfo
Definition: interfaces.hpp:181
CMySQL_Connection & GetConnection(void)
Definition: interfaces.hpp:193
void SetExecCntxInfo(const string &info)
Definition: interfaces.hpp:172
CRef< TDbgInfo > m_DbgInfo
Definition: interfaces.hpp:206
const TDbgInfo & GetDbgInfo(void) const
Definition: interfaces.hpp:182
const string & GetExecCntxInfo(void) const
Definition: interfaces.hpp:176
const CMySQL_Connection & GetConnection(void) const
Definition: interfaces.hpp:199
CMySQL_Connection * m_Connect
Definition: interfaces.hpp:205
const CDBParams * GetLastParams(void) const
Definition: interfaces.hpp:248
const CMySQL_Connection::TDbgInfo & GetDbgInfo(void) const
Definition: interfaces.hpp:243
unsigned long * m_Lengths
Definition: interfaces.hpp:257
CMySQL_Connection * m_Connect
Definition: interfaces.hpp:258
MYSQL_RES * m_Result
Definition: interfaces.hpp:255
const CMySQL_Connection & GetConnection() const
Definition: interfaces.hpp:237
I_BlobDescriptor::
Definition: interfaces.hpp:369
const CDBParams * GetLastParams(void) const
virtual bool SetTimeout(unsigned int nof_secs=0)
Set connection timeout.
virtual CConnection * MakeIConnection(const CDBConnParams &params)=0
virtual bool SetCancelTimeout(unsigned int nof_secs)
const string kDBAPI_MYSQL_DriverName
void NCBI_EntryPoint_xdbapi_mysql(CPluginManager< I_DriverContext >::TDriverInfoList &info_list, CPluginManager< I_DriverContext >::EEntryPointRequest method)
Definition: context.cpp:105
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static const char table_name[]
Definition: bcp.c:249
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
ECapability
Report if the driver supports this functionality.
virtual string GetDriverName(void) const
Definition: interfaces.cpp:342
EDB_ResType
EDB_ResType::
Definition: interfaces.hpp:386
virtual bool IsAbleTo(ECapability cpb) const =0
Check if a driver is acle to provide necessary functionality.
NCBI_XNCBI_EXPORT void Abort(void)
Smart abort function.
Definition: ncbidiag.cpp:8150
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
#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 NCBI_DBAPIDRIVER_MYSQL_EXPORT
Definition: ncbi_export.h:408
int len
static MDB_envinfo info
Definition: mdb_load.c:37
#define GetDbgInfo()
Definition: bcp.cpp:56
static uint8_t * buffer
Definition: pcre2test.c:1016
static string query
#define _ASSERT
Modified on Fri Sep 20 14:57:09 2024 by modify_doxy.py rev. 669887