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

Go to the SVN repository for this file.

1 /* $Id: dbapi_impl_context.cpp 102149 2024-04-09 13:58:35Z 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 * Author: Sergey Sikorskiy
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
31 
37 #include <dbapi/error_codes.hpp>
38 
40 #include <corelib/ncbifile.hpp>
41 
42 #include <algorithm>
43 #include <set>
44 
45 
46 #if defined(NCBI_OS_MSWIN)
47 # include <winsock2.h>
48 #endif
49 
50 
52 
53 #define NCBI_USE_ERRCODE_X Dbapi_DrvrContext
54 
55 
57 
58 
59 namespace impl
60 {
61 
62 struct SNoLock
63 {
64  void operator() (CDB_UserHandler::TExceptions& /*resource*/) const {}
65 };
66 
67 struct SUnLock
68 {
70  {
72  }
73 };
74 
75 inline
76 static bool s_Matches(CConnection* conn, const string& pool_name,
77  const string& server_name)
78 {
79  if (pool_name.empty()) {
80  // There is no server name check here. We assume that a connection
81  // pool contains connections with appropriate server names only.
82  return conn->ServerName() == server_name
83  || conn->GetRequestedServer() == server_name;
84  } else {
85  return conn->PoolName() == pool_name;
86  }
87 }
88 
89 ///////////////////////////////////////////////////////////////////////////
90 // CDriverContext::
91 //
92 
94  m_PoolSem(0, 1),
95  m_LoginTimeout(0),
96  m_Timeout(0),
97  m_CancelTimeout(0),
98  m_MaxBlobSize(0),
99  m_ClientEncoding(eEncoding_ISO8859_1)
100 {
103 }
104 
106 {
107  try {
108  DeleteAllConn();
109  } STD_CATCH_ALL("CDriverContext::DeleteAllConn");
110 }
111 
112 void
113 CDriverContext::SetApplicationName(const string& app_name)
114 {
115  CWriteLockGuard guard(x_GetCtxLock());
116 
117  m_AppName = app_name;
118 }
119 
120 string
122 {
123  CReadLockGuard guard(x_GetCtxLock());
124 
125  return m_AppName;
126 }
127 
128 void
129 CDriverContext::SetHostName(const string& host_name)
130 {
131  CWriteLockGuard guard(x_GetCtxLock());
132 
133  m_HostName = host_name;
134 }
135 
136 string
138 {
139  CReadLockGuard guard(x_GetCtxLock());
140 
141  return m_HostName;
142 }
143 
144 unsigned int CDriverContext::GetLoginTimeout(void) const
145 {
146  CReadLockGuard guard(x_GetCtxLock());
147 
148  return m_LoginTimeout;
149 }
150 
151 bool CDriverContext::SetLoginTimeout (unsigned int nof_secs)
152 {
153  CWriteLockGuard guard(x_GetCtxLock());
154 
155  m_LoginTimeout = nof_secs;
156 
157  return true;
158 }
159 
160 unsigned int CDriverContext::GetTimeout(void) const
161 {
162  CReadLockGuard guard(x_GetCtxLock());
163 
164  return m_Timeout;
165 }
166 
167 bool CDriverContext::SetTimeout(unsigned int nof_secs)
168 {
169  bool success = true;
170  CWriteLockGuard guard(x_GetCtxLock());
171 
172  try {
173  m_Timeout = nof_secs;
174 
175  // We do not have to update query/connection timeout in context
176  // any more. Each connection can be updated explicitly now.
177  // UpdateConnTimeout();
178  } catch (...) {
179  success = false;
180  }
181 
182  return success;
183 }
184 
185 unsigned int CDriverContext::GetCancelTimeout(void) const
186 {
187  CReadLockGuard guard(x_GetCtxLock());
188 
189  return m_CancelTimeout;
190 }
191 
192 bool CDriverContext::SetCancelTimeout(unsigned int nof_secs)
193 {
194  bool success = true;
195  CWriteLockGuard guard(x_GetCtxLock());
196 
197  try {
198  m_CancelTimeout = nof_secs;
199  } catch (...) {
200  success = false;
201  }
202 
203  return success;
204 }
205 
206 bool CDriverContext::SetMaxBlobSize(size_t nof_bytes)
207 {
208  CWriteLockGuard guard(x_GetCtxLock());
209 
210  m_MaxBlobSize = nof_bytes;
211 
213 
214  return true;
215 }
216 
218  EOwnership ownership)
219 {
220  CWriteLockGuard guard(x_GetCtxLock());
221  m_CntxHandlers.Push(h, ownership);
222 }
223 
225 {
226  CWriteLockGuard guard(x_GetCtxLock());
227  m_CntxHandlers.Pop(h);
228 }
229 
231  EOwnership ownership)
232 {
233  CWriteLockGuard guard(x_GetCtxLock());
234  m_ConnHandlers.Push(h, ownership);
235 }
236 
238 {
239  CWriteLockGuard guard(x_GetCtxLock());
240  m_ConnHandlers.Pop(h);
241 
242  // Remove this handler from all connections
245  con = *it;
246  con->PopMsgHandler(h);
247  }
248 
249  ITERATE(TConnPool, it, m_InUse) {
250  con = *it;
251  con->PopMsgHandler(h);
252  }
253 }
254 
255 
257 {
258  DEFINE_STATIC_MUTEX(env_mtx);
259 
260  CMutexGuard mg(env_mtx);
262 
263  // If user forces his own Sybase client path using $RESET_SYBASE
264  // and $SYBASE -- use that unconditionally.
265  try {
266  if (env.Get("LC_ALL") == "POSIX") {
267  // Canonicalize, since locales.dat might list C but not POSIX.
268  env.Set("LC_ALL", "C");
269  }
270  if (!env.Get("SYBASE").empty()) {
271  string reset = env.Get("RESET_SYBASE");
272  if ( !reset.empty() && NStr::StringToBool(reset)) {
273  return;
274  }
275  }
276  // ...else try hardcoded paths
277  } catch (const CStringException&) {
278  // Conversion error -- try hardcoded paths too
279  }
280 
281  // User-set or default hardcoded path
282  if ( CDir(NCBI_GetSybasePath()).CheckAccess(CDirEntry::fRead) ) {
283  env.Set("SYBASE", NCBI_GetSybasePath());
284  return;
285  }
286 
287  // If NCBI_SetSybasePath() was used to set up the Sybase path, and it is
288  // not right, then use the very Sybase client against which the code was
289  // compiled
292  env.Set("SYBASE", NCBI_GetDefaultSybasePath());
293  }
294 
295  // Else, well, use whatever $SYBASE there is
296 }
297 
298 
299 void CDriverContext::x_Recycle(CConnection* conn, bool conn_reusable)
300 {
302 
303  TConnPool::iterator it = find(m_InUse.begin(), m_InUse.end(), conn);
304 
305  if (it != m_InUse.end()) {
306  m_InUse.erase(it);
307  }
308 
309 #ifdef NCBI_THREADS
310  CConnection** recipient = nullptr;
311  for (auto &consumer : m_PoolSemConsumers) {
312  if ( !consumer.selected
313  && (consumer.subject_is_pool
314  ? conn->PoolName() == consumer.subject
315  : s_Matches(conn, kEmptyStr, consumer.subject))) {
316  consumer.selected = true;
317  recipient = &consumer.conn;
318  // probably redundant, but ensures Post will work
319  m_PoolSem.TryWait();
320  m_PoolSem.Post();
321  break;
322  }
323  }
324 #endif
325 
326  bool keep = false;
327  if (conn_reusable && conn->IsOpeningFinished() && conn->IsValid()) {
328  keep = true;
329  // Tentatively; account for temporary overflow below, bearing
330  // in mind that that conn is already gone from m_InUse and not
331  // yet in m_NotInUse, and as such uncounted.
332  if (conn->m_PoolMaxSize <= m_InUse.size() + m_NotInUse.size()) {
333  unsigned int n;
334  if (conn->m_Pool.empty()) {
335  n = NofConnections(conn->m_RequestedServer);
336  } else {
337  n = NofConnections(kEmptyStr, conn->m_Pool);
338  }
339  if (n >= conn->m_PoolMaxSize) {
340  keep = false;
341  }
342  }
343 
344  if (keep && conn->m_ReuseCount + 1 > conn->m_PoolMaxConnUse) {
345  // CXX-4420: limit the number of time the connection is reused
346  keep = false;
347  }
348  }
349 
350  if (keep) {
351  if (conn->m_PoolIdleTimeParam.GetSign() != eNegative) {
352  CTime now(CTime::eCurrent);
353  conn->m_CleanupTime = now + conn->m_PoolIdleTimeParam;
354  }
355  m_NotInUse.push_back(conn);
356 #ifdef NCBI_THREADS
357  if (recipient != nullptr) {
358  *recipient = conn;
359  }
360 #endif
361  } else {
362  x_AdjustCounts(conn, -1);
363  delete conn;
364  }
365 
367 }
368 
369 
371 {
372  if (delta != 0 && conn->IsReusable()) {
374  string server_name = conn->GetServerName();
375  if (conn->Host() != 0 && server_name.find('@') == NPOS) {
376  server_name += '@' + ConvertN2A(conn->Host());
377  if (conn->Port() != 0) {
378  server_name += ':' + NStr::NumericToString(conn->Port());
379  }
380  }
381  _DEBUG_ARG(unsigned int pool_count =)
382  m_CountsByPool[conn->PoolName()][server_name] += delta;
383  _DEBUG_ARG(unsigned int service_count =)
384  m_CountsByService[conn->GetRequestedServer()][server_name] += delta;
385  _TRACE(server_name << " count += " << delta << " for pool "
386  << conn->PoolName() << " (" << pool_count << ") and service "
387  << conn->GetRequestedServer() << " (" << service_count << ')');
388  }
389 }
390 
391 
393  const string& name, TCounts* counts) const
394 {
395  CReadLockGuard guard(m_PoolLock);
396  auto it = main_map.find(name);
397  if (it == main_map.end()) {
398  counts->clear();
399  } else {
400  *counts = it->second;
401  }
402 }
403 
404 
405 void CDriverContext::CloseUnusedConnections(const string& srv_name,
406  const string& pool_name,
407  unsigned int max_closings)
408 {
410 
412 
413  // close all connections first
415  con = *it;
416 
417  if ( !srv_name.empty() && srv_name != con->ServerName()
418  && srv_name != con->GetRequestedServer() )
419  continue;
420  if((!pool_name.empty()) && pool_name.compare(con->PoolName())) continue;
421 
422  it = m_NotInUse.erase(it);
423  x_AdjustCounts(con, -1);
424  delete con;
425  if (--max_closings == 0) {
426  break;
427  }
428  }
429 }
430 
431 unsigned int CDriverContext::NofConnections(const TSvrRef& svr_ref,
432  const string& pool_name) const
433 {
434  CReadLockGuard guard(m_PoolLock);
435 
436  if ((!svr_ref || !svr_ref->IsValid()) && pool_name.empty()) {
437  return static_cast<unsigned int>(m_InUse.size() + m_NotInUse.size());
438  }
439 
440  string server;
441  Uint4 host = 0;
442  Uint2 port = 0;
443  if (svr_ref) {
444  host = svr_ref->GetHost();
445  port = svr_ref->GetPort();
446  if (host == 0)
447  server = svr_ref->GetName();
448  }
449 
450  const TConnPool* pools[] = {&m_NotInUse, &m_InUse};
451  int n = 0;
452  for (size_t i = 0; i < ArraySize(pools); ++i) {
453  ITERATE(TConnPool, it, (*pools[i])) {
454  TConnPool::value_type con = *it;
455  if(!server.empty()) {
456  if (server != con->ServerName()
457  && server != con->GetRequestedServer())
458  continue;
459  }
460  else if (host != 0) {
461  if (host != con->Host() || port != con->Port())
462  continue;
463  }
464  if((!pool_name.empty()) && pool_name.compare(con->PoolName())) continue;
465  ++n;
466  }
467  }
468 
469  return n;
470 }
471 
472 unsigned int CDriverContext::NofConnections(const string& srv_name,
473  const string& pool_name) const
474 {
475  TSvrRef svr_ref(new CDBServer(srv_name, 0, 0));
476  return NofConnections(svr_ref, pool_name);
477 }
478 
480  int delta)
481 {
482  connection->m_CleanupTime.Clear();
484  m_InUse.push_back(connection);
485  x_AdjustCounts(connection, delta);
486 
487  return new CDB_Connection(connection);
488 }
489 
492 {
493  if (params.GetParam("is_pooled") == "true") {
495 
496  string pool_name (params.GetParam("pool_name")),
497  server_name(params.GetServerName());
498 
500  CConnection* t_con(*it);
501  if (s_Matches(t_con, pool_name, server_name)) {
502  it = m_NotInUse.erase(it);
503  CDB_Connection* dbcon = MakeCDBConnection(t_con, 0);
504  if (dbcon->Refresh()) {
505  /* Future development ...
506  if (!params.GetDatabaseName().empty()) {
507  return SetDatabase(dbcon, params);
508  } else {
509  return dbcon;
510  }
511  */
512 
513  return dbcon;
514  }
515  else {
516  x_AdjustCounts(t_con, -1);
517  t_con->m_Reusable = false;
518  delete dbcon;
519  }
520  }
521  }
522 
523  // Connection should be created, but we can have limit on number of
524  // connections in the pool.
525  string pool_max_str(params.GetParam("pool_maxsize"));
526  if (!pool_max_str.empty() && pool_max_str != "default") {
527  int pool_max = NStr::StringToInt(pool_max_str);
528  if (pool_max != 0) {
529  int total_cnt = 0;
530  ITERATE(TConnPool, it, m_InUse) {
531  CConnection* t_con(*it);
532  if (s_Matches(t_con, pool_name, server_name)) {
533  ++total_cnt;
534  }
535  }
536  if (total_cnt >= pool_max) {
537 #ifdef NCBI_THREADS
538  string timeout_str(params.GetParam("pool_wait_time"));
539  double timeout_val = 0.0;
540  if ( !timeout_str.empty() && timeout_str != "default") {
541  timeout_val = NStr::StringToDouble(timeout_str);
542  }
543  CDeadline deadline{CTimeout(timeout_val)};
545  if (pool_name.empty()) {
546  subject = server_name;
547  } else {
548  subject = pool_name;
549  }
550  auto target = (m_PoolSemConsumers
551  .emplace(m_PoolSemConsumers.end(),
552  subject, !pool_name.empty()));
553  guard.Release();
554  bool timed_out = true;
555  bool relocked = false;
556  while (m_PoolSem.TryWait(deadline.GetRemainingTime())) {
557  guard.Guard(m_PoolLock);
558  relocked = true;
559  if (target->selected) {
560  timed_out = false;
561  for (const auto &it : m_PoolSemConsumers) {
562  if (&it != &*target && it.selected) {
563  m_PoolSem.TryWait();
564  m_PoolSem.Post();
565  break;
566  }
567  }
568  } else {
569  m_PoolSem.TryWait();
570  m_PoolSem.Post();
571  relocked = false;
572  guard.Release();
573  continue;
574  }
575  CConnection* t_con = NULL;
577  if (*it == target->conn) {
578  t_con = target->conn;
579  m_NotInUse.erase((++it).base());
580  break;
581  }
582  }
583  if (t_con != NULL) {
584  m_PoolSemConsumers.erase(target);
585  return MakeCDBConnection(t_con, 0);
586  }
587  break;
588  }
589  if ( !relocked ) {
590  guard.Guard(m_PoolLock);
591  }
592  m_PoolSemConsumers.erase(target);
593  if (timed_out)
594 #endif
595  if (params.GetParam("pool_allow_temp_overflow")
596  != "true") {
597  string msg = FORMAT("Connection pool full (size "
598  << pool_max << ") for "
599  << (pool_name.empty() ? server_name
600  : pool_name));
601  DATABASE_DRIVER_ERROR(msg, 200011);
602  }
603  }
604  }
605  }
606  }
607 
608  if (params.GetParam("do_not_connect") == "true") {
609  return NULL;
610  }
611 
612  // Precondition check.
613  if (!TDbapi_CanUseKerberos::GetDefault()
614  && (params.GetUserName().empty()
615  || params.GetPassword().empty()))
616  {
617  string err_msg("Insufficient credentials to connect.");
618 
619  if (params.GetUserName().empty()) {
620  err_msg += " User name has not been set.";
621  }
622  if (params.GetPassword().empty()) {
623  err_msg += " Password has not been set.";
624  }
625 
626  DATABASE_DRIVER_ERROR( err_msg, 200010 );
627  }
628 
629  CConnection* t_con = MakeIConnection(params);
630 
631  return MakeCDBConnection(t_con, 1);
632 }
633 
634 void
636 {
638  // close all connections first
640  x_AdjustCounts(*it, -1);
641  delete *it;
642  }
643  m_NotInUse.clear();
644 
645  ITERATE(TConnPool, it, m_InUse) {
646  (*it)->Close();
647  }
648 }
649 
650 void
652 {
654  // close all connections first
656  x_AdjustCounts(*it, -1);
657  delete *it;
658  }
659  m_NotInUse.clear();
660 
661  ITERATE(TConnPool, it, m_InUse) {
662  x_AdjustCounts(*it, -1);
663  delete *it;
664  }
665  m_InUse.clear();
666 }
667 
668 
670 {
671 public:
673  : m_Other(other)
674  {
675  // Override what is set in CDBConnParamsBase constructor
676  SetParam("secure_login", kEmptyStr);
677  SetParam("is_pooled", kEmptyStr);
678  SetParam("do_not_connect", kEmptyStr);
679  }
680 
682  {}
683 
684  virtual Uint4 GetProtocolVersion(void) const
685  {
686  return m_Other.GetProtocolVersion();
687  }
688 
689  virtual EEncoding GetEncoding(void) const
690  {
691  return m_Other.GetEncoding();
692  }
693 
694  virtual string GetServerName(void) const
695  {
697  }
698 
699  virtual string GetDatabaseName(void) const
700  {
702  }
703 
704  virtual string GetUserName(void) const
705  {
707  }
708 
709  virtual string GetPassword(void) const
710  {
712  }
713 
714  virtual EServerType GetServerType(void) const
715  {
716  return m_Other.GetServerType();
717  }
718 
719  virtual Uint4 GetHost(void) const
720  {
721  return m_Other.GetHost();
722  }
723 
724  virtual Uint2 GetPort(void) const
725  {
726  return m_Other.GetPort();
727  }
728 
730  {
731  return m_Other.GetConnValidator();
732  }
733 
734  virtual string GetParam(const string& key) const
735  {
737  if (result.empty())
738  return m_Other.GetParam(key);
739  else
740  return result;
741  }
742 
748 
749 private:
751 };
752 
753 
755 {
756  string server_name;
757  string user_name;
758  string db_name;
759  string password;
760 
761  SLoginData(const string& sn, const string& un,
762  const string& dn, const string& pass)
763  : server_name(sn), user_name(un), db_name(dn), password(pass)
764  {}
765 
766  bool operator< (const SLoginData& right) const
767  {
768  if (server_name != right.server_name)
769  return server_name < right.server_name;
770  else if (user_name != right.user_name)
771  return user_name < right.user_name;
772  else if (db_name != right.db_name)
773  return db_name < right.db_name;
774  else
775  return password < right.password;
776  }
777 };
778 
779 
780 static void
781 s_TransformLoginData(string& server_name, string& user_name,
782  string& db_name, string& password)
783 {
784  if (!TDbapi_ConnUseEncryptData::GetDefault())
785  return;
786 
787  string app_name = CNcbiApplication::Instance()->GetProgramDisplayName();
788  set<SLoginData> visited;
790 
791  visited.insert(SLoginData(server_name, user_name, db_name, password));
792  for (;;) {
793  string res_name = app_name;
794  if (!user_name.empty()) {
795  res_name += "/";
796  res_name += user_name;
797  }
798  if (!server_name.empty()) {
799  res_name += "@";
800  res_name += server_name;
801  }
802  if (!db_name.empty()) {
803  res_name += ":";
804  res_name += db_name;
805  }
806  const CNcbiResourceInfo& info
807  = res_file.GetResourceInfo(res_name, password);
808  if (!info)
809  break;
810 
811  password = info.GetValue();
812  typedef CNcbiResourceInfo::TExtraValuesMap TExtraMap;
813  typedef TExtraMap::const_iterator TExtraMapIt;
814  const TExtraMap& extra = info.GetExtraValues().GetPairs();
815 
816  TExtraMapIt it = extra.find("server");
817  if (it != extra.end())
818  server_name = it->second;
819  it = extra.find("username");
820  if (it != extra.end())
821  user_name = it->second;
822  it = extra.find("database");
823  if (it != extra.end())
824  db_name = it->second;
825 
826  if (!visited.insert(
827  SLoginData(server_name, user_name, db_name, password)).second)
828  {
830  "Circular dependency inside resources info file.", 100012);
831  }
832  }
833 }
834 
835 
836 void
838 {
839  flags = 0;
840  server.clear();
841  port.clear();
842  database.clear();
843  username.clear();
844  password.clear();
845  login_timeout.clear();
846  io_timeout.clear();
847  single_server.clear();
848  is_pooled.clear();
849  pool_name.clear();
850  pool_maxsize.clear();
851  pool_idle_time.clear();
852  pool_wait_time.clear();
853  pool_allow_temp_overflow.clear();
854  pool_max_conn_use.clear();
855  args.clear();
856 }
857 
858 void
859 CDriverContext::ReadDBConfParams(const string& service_name,
860  SDBConfParams* params)
861 {
862  params->Clear();
863  if (service_name.empty())
864  return;
865 
867  if (!app)
868  return;
869 
870  const IRegistry& reg = app->GetConfig();
871  string section_name(service_name);
872  section_name.append(1, '.');
873  section_name.append("dbservice");
874  if (!reg.HasEntry(section_name, kEmptyStr))
875  return;
876 
877  if (reg.HasEntry(section_name, "service", IRegistry::fCountCleared)) {
878  params->flags += SDBConfParams::fServerSet;
879  params->server = reg.Get(section_name, "service");
880  }
881  if (reg.HasEntry(section_name, "port", IRegistry::fCountCleared)) {
882  params->flags += SDBConfParams::fPortSet;
883  params->port = reg.Get(section_name, "port");
884  }
885  if (reg.HasEntry(section_name, "database", IRegistry::fCountCleared)) {
887  params->database = reg.Get(section_name, "database");
888  }
889  if (reg.HasEntry(section_name, "username", IRegistry::fCountCleared)) {
891  params->username = reg.Get(section_name, "username");
892  }
893  if (reg.HasEntry(section_name, "password_key", IRegistry::fCountCleared)) {
895  params->password_key_id = reg.Get(section_name, "password_key");
896  }
897  if (reg.HasEntry(section_name, "password", IRegistry::fCountCleared)) {
899  params->password = reg.Get(section_name, "password");
900  if (CNcbiEncrypt::IsEncrypted(params->password)) {
901  try {
902  params->password = CNcbiEncrypt::Decrypt(params->password);
903  } NCBI_CATCH("Password decryption for " + service_name);
904  } else if (params->password_key_id.empty()) {
906  << "Using unencrypted password for " + service_name);
907  }
908  }
909  if (reg.HasEntry(section_name, "password_file",
911  // password and password_file are mutually exclusive, but only SDBAPI
912  // actually honors the latter, so it will take care of throwing
913  // exceptions as necessary.
915  params->password_file = reg.Get(section_name, "password_file");
916  }
917  if (reg.HasEntry(section_name, "login_timeout", IRegistry::fCountCleared)) {
919  params->login_timeout = reg.Get(section_name, "login_timeout");
920  }
921  if (reg.HasEntry(section_name, "io_timeout", IRegistry::fCountCleared)) {
923  params->io_timeout = reg.Get(section_name, "io_timeout");
924  }
925  if (reg.HasEntry(section_name, "cancel_timeout", IRegistry::fCountCleared)) {
927  params->cancel_timeout = reg.Get(section_name, "cancel_timeout");
928  }
929  if (reg.HasEntry(section_name, "exclusive_server", IRegistry::fCountCleared)) {
931  params->single_server = reg.Get(section_name, "exclusive_server");
932  }
933  if (reg.HasEntry(section_name, "use_conn_pool", IRegistry::fCountCleared)) {
935  params->is_pooled = reg.Get(section_name, "use_conn_pool");
936  params->pool_name = section_name;
937  params->pool_name.append(1, '.');
938  params->pool_name.append("pool");
939  }
940  if (reg.HasEntry(section_name, "conn_pool_name", IRegistry::fCountCleared)) {
941  // params->flags += SDBConfParams::fPoolNameSet;
942  params->pool_name = reg.Get(section_name, "conn_pool_name");
943  }
944  if (reg.HasEntry(section_name, "conn_pool_minsize", IRegistry::fCountCleared)) {
946  params->pool_minsize = reg.Get(section_name, "conn_pool_minsize");
947  }
948  if (reg.HasEntry(section_name, "conn_pool_maxsize", IRegistry::fCountCleared)) {
950  params->pool_maxsize = reg.Get(section_name, "conn_pool_maxsize");
951  }
952  if (reg.HasEntry(section_name, "conn_pool_idle_time",
955  params->pool_idle_time = reg.Get(section_name, "conn_pool_idle_time");
956  }
957  if (reg.HasEntry(section_name, "conn_pool_wait_time",
960  params->pool_wait_time = reg.Get(section_name, "conn_pool_wait_time");
961  }
962  if (reg.HasEntry(section_name, "conn_pool_allow_temp_overflow",
966  = reg.Get(section_name, "conn_pool_allow_temp_overflow");
967  }
968  if (reg.HasEntry(section_name, "continue_after_raiserror",
972  = reg.Get(section_name, "continue_after_raiserror");
973  }
974  if (reg.HasEntry(section_name, "conn_pool_max_conn_use",
977  params->pool_max_conn_use
978  = reg.Get(section_name, "conn_pool_max_conn_use");
979  }
980  if (reg.HasEntry(section_name, "log_minor_messages",
983  params->log_minor_messages
984  = reg.Get(section_name, "log_minor_messages");
985  }
986  if (reg.HasEntry(section_name, "args", IRegistry::fCountCleared)) {
987  params->flags += SDBConfParams::fArgsSet;
988  params->args = reg.Get(section_name, "args");
989  }
990 }
991 
992 bool
994 {
996 
997  string pool_min_str = params.GetParam("pool_minsize");
998  if (pool_min_str.empty() || pool_min_str == "default")
999  return true;
1000  int pool_min = NStr::StringToInt(pool_min_str);
1001  if (pool_min <= 0)
1002  return true;
1003 
1004  string pool_name = params.GetParam("pool_name"),
1005  server_name = params.GetServerName();
1006  int total_cnt = 0;
1007  ITERATE(TConnPool, it, m_InUse) {
1008  CConnection* t_con(*it);
1009  if (t_con->IsReusable() && s_Matches(t_con, pool_name, server_name)
1010  && t_con->IsValid() && t_con->IsAlive())
1011  {
1012  ++total_cnt;
1013  }
1014  }
1015  ITERATE(TConnPool, it, m_NotInUse) {
1016  CConnection* t_con(*it);
1017  if (t_con->IsReusable() && s_Matches(t_con, pool_name, server_name)
1018  && t_con->IsAlive())
1019  {
1020  ++total_cnt;
1021  }
1022  }
1023  guard.Release();
1024  vector< AutoPtr<CDB_Connection> > conns(pool_min);
1025  for (int i = total_cnt; i < pool_min; ++i) {
1026  try {
1027  conns.push_back(MakeConnection(params));
1028  }
1029  catch (CDB_Exception& ex) {
1030  ERR_POST_X(1, "Error filling connection pool: " << ex);
1031  return false;
1032  }
1033  }
1034  return true;
1035 }
1036 
1039 {
1040  CMakeConnActualParams act_params(params);
1041 
1042  SDBConfParams conf_params;
1043  conf_params.Clear();
1044  if (params.GetParam("do_not_read_conf") != "true") {
1045  ReadDBConfParams(params.GetServerName(), &conf_params);
1046  }
1047 
1048  unique_ptr<CDB_Connection> t_con;
1049  {
1050  string server_name = (conf_params.IsServerSet()? conf_params.server:
1051  params.GetServerName());
1052  string user_name = (conf_params.IsUsernameSet()? conf_params.username:
1053  params.GetUserName());
1054  string db_name = (conf_params.IsDatabaseSet()? conf_params.database:
1055  params.GetDatabaseName());
1056  string password = (conf_params.IsPasswordSet()? conf_params.password:
1057  params.GetPassword());
1060  auto cfactory
1061  = dynamic_cast<const CDBConnectionFactory*>(
1062  factory.GetPointerOrNull());
1063  unsigned int timeout;
1064  if (cfactory != nullptr) {
1065  timeout = cfactory->GetLoginTimeout();
1066  } else if (conf_params.IsLoginTimeoutSet()) {
1067  if (conf_params.login_timeout.empty()) {
1068  timeout = 0;
1069  } else {
1070  NStr::StringToNumeric(conf_params.login_timeout, &timeout);
1071  }
1072  } else {
1073  string value(params.GetParam("login_timeout"));
1074  if (value == "default") {
1075  timeout = 0;
1076  } else if (!value.empty()) {
1077  NStr::StringToNumeric(value, &timeout);
1078  } else {
1079  timeout = GetLoginTimeout();
1080  }
1081  }
1082  if (timeout == 0 && cfactory != nullptr) {
1083  timeout = 30;
1084  }
1085  act_params.SetParam("login_timeout", NStr::NumericToString(timeout));
1086 
1087  if (conf_params.IsIOTimeoutSet()) {
1088  if (conf_params.io_timeout.empty()) {
1089  timeout = 0;
1090  } else {
1091  NStr::StringToNumeric(conf_params.io_timeout, &timeout);
1092  }
1093  } else {
1094  string value(params.GetParam("timeout"));
1095  if (value == "default") {
1096  timeout = 0;
1097  } else if (!value.empty()) {
1098  NStr::StringToNumeric(value, &timeout);
1099  } else {
1100  timeout = GetTimeout();
1101  }
1102  }
1103  if (cfactory != nullptr) {
1104  auto validation_timeout = cfactory->GetConnectionTimeout();
1105  if (validation_timeout == 0) {
1106  validation_timeout = timeout ? timeout : 30;
1107  }
1108  act_params.SetParam("timeout",
1109  NStr::NumericToString(validation_timeout));
1110  } else {
1111  act_params.SetParam("timeout", NStr::NumericToString(timeout));
1112  }
1113  if (conf_params.IsCancelTimeoutSet()) {
1114  if (conf_params.cancel_timeout.empty()) {
1115  SetCancelTimeout(0);
1116  }
1117  else {
1119  }
1120  }
1121  else {
1122  string value(params.GetParam("cancel_timeout"));
1123  if (value == "default") {
1124  SetCancelTimeout(10);
1125  }
1126  else if (!value.empty()) {
1128  }
1129  }
1130  if (conf_params.IsSingleServerSet()) {
1131  if (conf_params.single_server.empty()) {
1132  act_params.SetParam("single_server", "true");
1133  }
1134  else {
1135  act_params.SetParam("single_server",
1137  conf_params.single_server)));
1138  }
1139  }
1140  else if (params.GetParam("single_server") == "default") {
1141  act_params.SetParam("single_server", "true");
1142  }
1143  if (conf_params.IsPooledSet()) {
1144  if (conf_params.is_pooled.empty()) {
1145  act_params.SetParam("is_pooled", "false");
1146  }
1147  else {
1148  act_params.SetParam("is_pooled",
1150  conf_params.is_pooled)));
1151  act_params.SetParam("pool_name", conf_params.pool_name);
1152  }
1153  }
1154  else if (params.GetParam("is_pooled") == "default") {
1155  act_params.SetParam("is_pooled", "false");
1156  }
1157  if (conf_params.IsPoolMinSizeSet())
1158  act_params.SetParam("pool_minsize", conf_params.pool_minsize);
1159  else if (params.GetParam("pool_minsize") == "default") {
1160  act_params.SetParam("pool_minsize", "0");
1161  }
1162  if (conf_params.IsPoolMaxSizeSet())
1163  act_params.SetParam("pool_maxsize", conf_params.pool_maxsize);
1164  else if (params.GetParam("pool_maxsize") == "default") {
1165  act_params.SetParam("pool_maxsize", "");
1166  }
1167  if (conf_params.IsPoolIdleTimeSet())
1168  act_params.SetParam("pool_idle_time", conf_params.pool_idle_time);
1169  else if (params.GetParam("pool_idle_time") == "default") {
1170  act_params.SetParam("pool_idle_time", "");
1171  }
1172  if (conf_params.IsPoolWaitTimeSet())
1173  act_params.SetParam("pool_wait_time", conf_params.pool_wait_time);
1174  else if (params.GetParam("pool_wait_time") == "default") {
1175  act_params.SetParam("pool_wait_time", "0");
1176  }
1177  if (conf_params.IsPoolAllowTempOverflowSet()) {
1178  if (conf_params.pool_allow_temp_overflow.empty()) {
1179  act_params.SetParam("pool_allow_temp_overflow", "false");
1180  }
1181  else {
1182  act_params.SetParam
1183  ("pool_allow_temp_overflow",
1186  conf_params.pool_allow_temp_overflow)));
1187  }
1188  }
1189  else if (params.GetParam("pool_allow_temp_overflow") == "default") {
1190  act_params.SetParam("pool_allow_temp_overflow", "false");
1191  }
1192  if (conf_params.IsPoolMaxConnUseSet())
1193  act_params.SetParam("pool_max_conn_use",
1194  conf_params.pool_max_conn_use);
1195  else if (params.GetParam("pool_max_conn_use") == "default") {
1196  act_params.SetParam("pool_max_conn_use", "0");
1197  }
1198  if (conf_params.IsContinueAfterRaiserrorSet()) {
1199  if (conf_params.continue_after_raiserror.empty()) {
1200  act_params.SetParam("continue_after_raiserror", "false");
1201  }
1202  else {
1203  act_params.SetParam
1204  ("continue_after_raiserror",
1207  conf_params.continue_after_raiserror)));
1208  }
1209  }
1210  else if (params.GetParam("continue_after_raiserror") == "default") {
1211  act_params.SetParam("continue_after_raiserror", "false");
1212  }
1213  if (conf_params.IsLogMinorMessagesSet()) {
1214  if (conf_params.log_minor_messages.empty()) {
1215  act_params.SetParam("log_minor_messages", "false");
1216  }
1217  else {
1218  act_params.SetParam
1219  ("log_minor_messages",
1222  conf_params.log_minor_messages)));
1223  }
1224  }
1225  else if (params.GetParam("log_minor_messages") == "default") {
1226  act_params.SetParam("log_minor_messages", "false");
1227  }
1228 
1229  s_TransformLoginData(server_name, user_name, db_name, password);
1230  act_params.SetServerName(server_name);
1231  act_params.SetUserName(user_name);
1232  act_params.SetDatabaseName(db_name);
1233  act_params.SetPassword(password);
1234 
1237  guard(expts);
1238  t_con.reset(factory->MakeDBConnection(*this, act_params, expts));
1239 
1240  if (t_con.get() == NULL) {
1241  if (act_params.GetParam("do_not_connect") == "true") {
1242  return NULL;
1243  }
1244 
1245  string err;
1246  err += "Cannot connect to the server '" + act_params.GetServerName();
1247  err += "' as user '" + act_params.GetUserName() + "'";
1248 
1249  CDB_ClientEx ex(DIAG_COMPILE_INFO, NULL, err, eDiag_Error, 100011);
1250  ex.SetRetriable(eRetriable_No);
1252  {
1253  ex.AddPrevious(*it);
1254  }
1255  throw ex;
1256  }
1257 
1258  t_con->SetTimeout(timeout);
1259  // Set database ...
1260  t_con->SetDatabaseName(act_params.GetDatabaseName());
1261 
1262  }
1263 
1264  return t_con.release();
1265 }
1266 
1267 size_t CDriverContext::CloseConnsForPool(const string& pool_name,
1268  Uint4 keep_host_ip, Uint2 keep_port)
1269 {
1270  size_t invalidated_count = 0;
1271  CWriteLockGuard guard(m_PoolLock);
1272 
1273  ITERATE(TConnPool, it, m_InUse) {
1274  CConnection* t_con(*it);
1275  if (t_con->IsReusable() && pool_name == t_con->PoolName()) {
1276  if (t_con->Host() != keep_host_ip || t_con->Port() != keep_port) {
1277  t_con->Invalidate();
1278  ++invalidated_count;
1279  }
1280  }
1281  }
1283  CConnection* t_con(*it);
1284  if (t_con->IsReusable() && pool_name == t_con->PoolName()) {
1285  if (t_con->Host() != keep_host_ip || t_con->Port() != keep_port) {
1286  m_NotInUse.erase(it);
1287  x_AdjustCounts(t_con, -1);
1288  delete t_con;
1289  }
1290  }
1291  }
1292  return invalidated_count;
1293 }
1294 
1295 
1296 void CDriverContext::CloseOldIdleConns(unsigned int max_closings,
1297  const string& pool_name)
1298 {
1299  CWriteLockGuard guard(m_PoolLock);
1300  if (max_closings == 0) {
1301  return;
1302  }
1303 
1304  set<string> at_min_by_pool, at_min_by_server;
1305  CTime now(CTime::eCurrent);
1307  const string& pool_name_2 = (*it)->PoolName();
1308  set<string>& at_min
1309  = pool_name_2.empty() ? at_min_by_server : at_min_by_pool;
1310  if (pool_name_2.empty()) {
1311  if ( !pool_name.empty()
1312  || at_min.find((*it)->GetRequestedServer()) != at_min.end()) {
1313  continue;
1314  }
1315  } else if (( !pool_name.empty() && pool_name != pool_name_2)
1316  || at_min.find(pool_name_2) != at_min.end()) {
1317  continue;
1318  }
1319  if ((*it)->m_CleanupTime.IsEmpty() || (*it)->m_CleanupTime > now) {
1320  continue;
1321  }
1322  unsigned int n;
1323  if (pool_name_2.empty()) {
1324  n = NofConnections((*it)->GetRequestedServer());
1325  } else {
1326  n = NofConnections(TSvrRef(), pool_name_2);
1327  }
1328  if (n > (*it)->m_PoolMinSize) {
1329  x_AdjustCounts(*it, -1);
1330  delete *it;
1331  m_NotInUse.erase(it);
1332  if (--max_closings == 0) {
1333  break;
1334  }
1335  } else {
1336  at_min.insert(pool_name_2);
1337  }
1338  }
1339 }
1340 
1341 
1343 {
1344  if (impl) {
1345  impl->ReleaseInterface();
1346  x_Recycle(impl, impl->IsReusable());
1347  }
1348 }
1349 
1350 void CDriverContext::SetClientCharset(const string& charset)
1351 {
1352  CWriteLockGuard guard(x_GetCtxLock());
1353 
1354  m_ClientCharset = charset;
1356 
1357  if (NStr::CompareNocase(charset, "UTF-8") == 0 ||
1358  NStr::CompareNocase(charset, "UTF8") == 0) {
1360  } else if (NStr::CompareNocase(charset, "Ascii") == 0) {
1362  } else if (NStr::CompareNocase(charset, "ISO8859_1") == 0 ||
1363  NStr::CompareNocase(charset, "ISO8859-1") == 0
1364  ) {
1366  } else if (NStr::CompareNocase(charset, "Windows_1252") == 0 ||
1367  NStr::CompareNocase(charset, "Windows-1252") == 0) {
1369  }
1370 }
1371 
1373 {
1374  // Do not protect this method. It is already protected.
1375 
1376  ITERATE(TConnPool, it, m_NotInUse) {
1377  CConnection* t_con = *it;
1378  if (!t_con) continue;
1379 
1380  t_con->SetTimeout(GetTimeout());
1381  }
1382 
1383  ITERATE(TConnPool, it, m_InUse) {
1384  CConnection* t_con = *it;
1385  if (!t_con) continue;
1386 
1387  t_con->SetTimeout(GetTimeout());
1388  }
1389 }
1390 
1391 
1393 {
1394  // Do not protect this method. It is protected.
1395 
1396  ITERATE(TConnPool, it, m_NotInUse) {
1397  CConnection* t_con = *it;
1398  if (!t_con) continue;
1399 
1400  t_con->SetBlobSize(GetMaxBlobSize());
1401  }
1402 
1403  ITERATE(TConnPool, it, m_InUse) {
1404  CConnection* t_con = *it;
1405  if (!t_con) continue;
1406 
1407  t_con->SetBlobSize(GetMaxBlobSize());
1408  }
1409 }
1410 
1411 
1412 ///////////////////////////////////////////////////////////////////////////
1414 {
1415 #if defined(NCBI_OS_MSWIN)
1416  WSADATA wsaData;
1417  if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
1418  {
1419  DATABASE_DRIVER_ERROR( "winsock initialization failed", 200001 );
1420  }
1421 #endif
1422 }
1423 
1425 {
1426 #if defined(NCBI_OS_MSWIN)
1427  WSACleanup();
1428 #endif
1429 }
1430 
1431 } // namespace impl
1432 
1434 
1435 
CDBConnParams::
Definition: interfaces.hpp:258
unsigned int GetLoginTimeout(void) const
IDBServiceMapper.
Uint2 GetPort(void) const
const string & GetName(void) const
bool IsValid(void) const
Uint4 GetHost(void) const
CDB_Exception –.
Definition: exception.hpp:118
CRef< IDBConnectionFactory > GetConnectionFactory(void) const
Retrieve a connection factory.
static CDbapiConnMgr & Instance(void)
Get access to the class instance.
CDeadline.
Definition: ncbitime.hpp:1830
CDir –.
Definition: ncbifile.hpp:1695
void Guard(resource_type &resource)
Manually force the guard to protect some other resource.
Definition: guard.hpp:175
void Release()
Manually force the resource to be released.
Definition: guard.hpp:166
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:264
static bool IsEncrypted(const string &data)
Check if the string contains valid encrypted data.
static string Decrypt(const string &encrypted_string)
Decrypt a string using the matching key found in the NCBI keys files.
CNcbiEnvironment –.
Definition: ncbienv.hpp:110
Class for handling resource info files.
static string GetDefaultFileName(void)
Get default resource info file location (/etc/ncbi/.info).
const CNcbiResourceInfo & GetResourceInfo(const string &res_name, const string &pwd) const
Get read-only resource info for the given name.
Class for storing encrypted resource information.
CStringException –.
Definition: ncbistr.hpp:4506
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTime –.
Definition: ncbitime.hpp:296
CTimeout – Timeout interval.
Definition: ncbitime.hpp:1693
virtual CDB_Connection * MakeDBConnection(I_DriverContext &ctx, const CDBConnParams &params, CDB_UserHandler::TExceptions &exceptions)=0
Create new connection object for the given context and connection attributes.
IRegistry –.
Definition: ncbireg.hpp:73
virtual void SetTimeout(size_t nof_secs)=0
virtual void SetBlobSize(size_t nof_bytes)
bool IsReusable(void) const
Check if this connection is a reusable one.
virtual bool IsAlive(void)=0
Check out if connection is alive (this function doesn't ping the server, it just checks the status of...
const string & PoolName(void) const
Find out which connection pool this connection belongs to.
impl::CDBConnParamsBase::
virtual string GetPassword(void) const
virtual string GetDatabaseName(void) const
virtual string GetUserName(void) const
void SetUserName(const string &name)
virtual string GetParam(const string &key) const
Parameters, which are not listed above explicitly, should be retrieved via SetParam() method.
void SetParam(const string &key, const string &value)
void SetServerName(const string &name)
void SetPassword(const string &passwd)
virtual string GetServerName(void) const
void SetDatabaseName(const string &name)
void Pop(CDB_UserHandler *h, bool last=true)
void Push(CDB_UserHandler *h, EOwnership ownership=eNoOwnership)
virtual void PopDefConnMsgHandler(CDB_UserHandler *h)
Remove `per-connection' mess. handler "h" and all above it in the stack.
virtual void PushDefConnMsgHandler(CDB_UserHandler *h, EOwnership ownership=eNoOwnership)
Add `per-connection' err.message handler "h" to the stack of default handlers which are inherited by ...
CDBHandlerStack m_ConnHandlers
Stacks of `per-connection' err.message handlers.
void x_AdjustCounts(const CConnection *conn, int delta)
virtual CDB_Connection * MakeConnection(const CDBConnParams &params)
Create connection object using Load Balancer / connection factory.
size_t CloseConnsForPool(const string &pool_name, Uint4 keep_host_ip=0, Uint2 keep_port=0)
virtual void SetHostName(const string &host_name)
Set host name.
virtual void PushCntxMsgHandler(CDB_UserHandler *h, EOwnership ownership=eNoOwnership)
Add message handler "h" to process 'context-wide' (not bound to any particular connection) error mess...
list< SConsumer > m_PoolSemConsumers
void ReadDBConfParams(const string &service_name, SDBConfParams *params)
size_t GetMaxBlobSize(void) const
CDBHandlerStack m_CntxHandlers
Stack of `per-context' err.message handlers.
virtual string GetHostName(void) const
Get host name.
bool SatisfyPoolMinimum(const CDBConnParams &params)
void x_Recycle(CConnection *conn, bool conn_reusable)
Return unused connection "conn" to the driver context for future reuse (if "conn_reusable" is TRUE) o...
virtual unsigned int GetCancelTimeout(void) const
virtual unsigned int NofConnections(const string &srv_name="", const string &pool_name="") const
Return number of currently open connections in this context.
virtual bool SetTimeout(unsigned int nof_secs=0)
Set connection timeout.
static void ResetEnvSybase(void)
void UpdateConnMaxBlobSize(void) const
TConnPool m_NotInUse
Unused(reserve) connections.
virtual string GetApplicationName(void) const
Return application name.
virtual void PopCntxMsgHandler(CDB_UserHandler *h)
Remove message handler "h" and all handlers above it in the stack.
CDB_Connection * MakePooledConnection(const CDBConnParams &params)
Create connection object WITHOUT using of Load Balancer / connection factory.
virtual bool SetMaxBlobSize(size_t nof_bytes)
Set maximal size for BLOB data.
virtual void SetClientCharset(const string &charset)
virtual CRWLock & x_GetCtxLock(void) const
void CloseOldIdleConns(unsigned int max_closings, const string &pool_name=kEmptyStr)
virtual unsigned int GetLoginTimeout(void) const
Get login timeout.
virtual CConnection * MakeIConnection(const CDBConnParams &params)=0
virtual void SetApplicationName(const string &app_name)
Set application name.
virtual bool SetLoginTimeout(unsigned int nof_secs=0)
Set login timeout.
CDB_Connection * MakeCDBConnection(CConnection *connection, int delta)
TConnPool m_InUse
Used connections.
virtual unsigned int GetTimeout(void) const
Get connection timeout.
void UpdateConnTimeout(void) const
void x_GetCounts(const TCountsMap &main_map, const string &name, TCounts *counts) const
void CloseUnusedConnections(const string &srv_name=kEmptyStr, const string &pool_name=kEmptyStr, unsigned int max_closings=kMax_UInt)
close reusable deleted connections for specified server and/or pool
void DestroyConnImpl(CConnection *impl)
list< CConnection * > TConnPool
virtual bool SetCancelTimeout(unsigned int nof_secs)
virtual string GetUserName(void) const
virtual Uint4 GetProtocolVersion(void) const
virtual CRef< IConnValidator > GetConnValidator(void) const
virtual string GetDatabaseName(void) const
virtual string GetPassword(void) const
virtual Uint2 GetPort(void) const
void SetUserName(const string &name)
virtual EEncoding GetEncoding(void) const
virtual string GetParam(const string &key) const
Parameters, which are not listed above explicitly, should be retrieved via SetParam() method.
void SetParam(const string &key, const string &value)
virtual string GetServerName(void) const
virtual Uint4 GetHost(void) const
virtual EServerType GetServerType(void) const
void SetServerName(const string &name)
CMakeConnActualParams(const CDBConnParams &other)
void SetPassword(const string &passwd)
void SetDatabaseName(const string &name)
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
bool empty() const
Definition: set.hpp:133
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
NCBI_PARAM_DEF_EX(bool, dbapi, conn_use_encrypt_data, false, eParam_NoThread, NULL)
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static HENV env
Definition: transaction2.c:38
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
constexpr size_t ArraySize(const Element(&)[Size])
Definition: ncbimisc.hpp:1532
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ERASE_ITERATE(Type, Var, Cont)
Non-constant version with ability to erase current element, if container permits.
Definition: ncbimisc.hpp:843
const string & GetProgramDisplayName(void) const
Get the application's "display" name.
#define NON_CONST_REVERSE_ITERATE(Type, Var, Cont)
Non constant version of REVERSE_ITERATE macro.
Definition: ncbimisc.hpp:834
@ eRetriable_No
It makes no sense to retry the action.
Definition: ncbimisc.hpp:168
@ eNegative
Value is negative.
Definition: ncbimisc.hpp:121
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
#define NULL
Definition: ncbistd.hpp:225
void SetDatabaseName(const string &d)
Definition: exception.hpp:208
#define DATABASE_DRIVER_ERROR(message, err_code)
Definition: exception.hpp:740
static CDB_UserHandler & GetDefault(void)
Definition: exception.cpp:628
static void ClearExceptions(TExceptions &expts)
Definition: exception.cpp:606
deque< CDB_Exception * > TExceptions
Exception container type.
Definition: exception.hpp:574
virtual EEncoding GetEncoding(void) const =0
virtual EServerType GetServerType(void) const =0
virtual string GetPassword(void) const =0
virtual Uint4 GetProtocolVersion(void) const =0
virtual Uint4 GetHost(void) const =0
virtual string GetServerName(void) const =0
virtual Uint2 GetPort(void) const =0
virtual string GetDatabaseName(void) const =0
virtual CRef< IConnValidator > GetConnValidator(void) const =0
conn_use_encrypt_data
Definition: interfaces.hpp:796
virtual string GetUserName(void) const =0
virtual string GetParam(const string &key) const =0
Parameters, which are not listed above explicitly, should be retrieved via SetParam() method.
virtual bool Refresh()
Reset the connection to the "ready" state (cancel all active commands)
Definition: public.cpp:414
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define _DEBUG_ARG(arg)
Definition: ncbidbg.hpp:134
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
Definition: ncbidiag.hpp:170
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
#define STD_CATCH_ALL(message)
Standard handling of "exception"-derived exceptions; catches non-standard exceptions and generates "u...
Definition: ncbiexpt.hpp:570
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
#define FORMAT(message)
Format message using iostreams library.
Definition: ncbiexpt.hpp:672
@ fRead
Read permission.
Definition: ncbifile.hpp:1153
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
virtual bool HasEntry(const string &section, const string &name=kEmptyStr, TFlags flags=0) const
Definition: ncbireg.cpp:290
@ fCountCleared
Let explicitly cleared entries stand.
Definition: ncbireg.hpp:94
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2821
EEncoding
Definition: ncbistr.hpp:199
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
Definition: ncbistr.cpp:1387
#define NPOS
Definition: ncbistr.hpp:133
static TNumeric StringToNumeric(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
Definition: ncbistr.hpp:330
static const string BoolToString(bool value)
Convert bool to string.
Definition: ncbistr.cpp:2815
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
@ eEncoding_Windows_1252
Definition: ncbistr.hpp:207
@ eEncoding_Ascii
Definition: ncbistr.hpp:202
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
Definition: ncbistr.hpp:203
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ eEncoding_Unknown
Definition: ncbistr.hpp:200
#define DEFINE_STATIC_MUTEX(id)
Define static mutex and initialize it.
Definition: ncbimtx.hpp:512
bool TryWait(unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
Timed wait.
Definition: ncbimtx.cpp:1844
void Post(unsigned int count=1)
Increment the semaphore by "count".
Definition: ncbimtx.cpp:1971
CTime & Clear(void)
Make the time "empty",.
Definition: ncbitime.cpp:1999
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
int i
yy_size_t n
static MDB_envinfo info
Definition: mdb_load.c:37
string ConvertN2A(Uint4 host)
static bool s_Matches(CConnection *conn, const string &pool_name, const string &server_name)
static void s_TransformLoginData(string &server_name, string &user_name, string &db_name, string &password)
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
CRef< CDBServer > TSvrRef
const char * NCBI_GetDefaultSybasePath(void)
Get default Sybase client installation path.
const char * NCBI_GetSybasePath(void)
Get Sybase client installation path.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Int4 delta(size_t dimension_, const Int4 *score_)
Defines NCBI C++ secure resources API.
static string subject
bool IsContinueAfterRaiserrorSet(void)
bool IsPoolAllowTempOverflowSet(void)
bool operator<(const SLoginData &right) const
SLoginData(const string &sn, const string &un, const string &dn, const string &pass)
void operator()(CDB_UserHandler::TExceptions &) const
void operator()(CDB_UserHandler::TExceptions &resource) const
else result
Definition: token2.c:20
Modified on Wed Jun 19 17:06:37 2024 by modify_doxy.py rev. 669887