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

Go to the SVN repository for this file.

1 /* $Id: dbapi_conn_policy.cpp 77792 2017-05-08 13:38:35Z ivanov $
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 
32 #include "dbapi_conn_policy.hpp"
33 #include <dbapi/driver/public.hpp>
35 #include <common/test_assert.h> /* This header must go last */
36 
37 
39 
40 
41 ///////////////////////////////////////////////////////////////////////////////
42 
44 : CDbapiSampleApp( eDoNotUseSampleDatabase )
45 {
46 }
47 
48 
50 {
51 }
52 
53 
54 int
56 {
57  try {
59 
60  // CConnValidatorCoR is developed to combine other validators into a chain.
61  CConnValidatorCoR conn_validator;
62 
63  // Combine validators.
64  conn_validator.Push
65  (CRef<IConnValidator>(new CTrivialConnValidator("tempdb", 0)));
66  conn_validator.Push(CRef<IConnValidator>(new CTrivialConnValidator("DBAPI_Sample")));
67 
68  for (int i = 0; i < 20; ++i) {
69  unique_ptr<CDB_Connection> conn(CreateConnection(&conn_validator));
70  }
71 
72  }
73  catch ( CDB_Exception& e ) {
75  return 1;
76  }
77 
78  return 0;
79 }
80 
81 
82 int main(int argc, const char* argv[])
83 {
84  return CConnectPolicyApp().AppMain(argc, argv);
85 }
86 
87 
CConnValidatorCoR.
void Push(const CRef< IConnValidator > &validator)
virtual int RunSample(void)
virtual ~CConnectPolicyApp(void)
CDB_Exception –.
Definition: exception.hpp:118
CDB_Connection * CreateConnection(IConnValidator *validator=NULL, I_DriverContext::TConnectionMode mode=I_DriverContext::fBcpIn, bool reusable=false, const string &pool_name=kEmptyStr)
Create new connection using server, username and password specified in the application command line.
int main(int argc, const char *argv[])
USING_NCBI_SCOPE
#define DBLB_INSTALL_DEFAULT()
Easy-to-use macro to install the default DBAPI service mapper.
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:832
static CDB_UserHandler & GetDefault(void)
Definition: exception.cpp:628
virtual bool HandleIt(CDB_Exception *ex)=0
Handle the exceptions resulting from a native API call, one-by-one.
int i
Modified on Fri Sep 20 14:58:09 2024 by modify_doxy.py rev. 669887