1 /* $Id: dbapi_driver_sample_base.cpp 535289 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 * File Description:
29 *
30 */
31
32
33 #include <ncbi_pch.hpp>
34
35 #include "dbapi_driver_sample_base.hpp"
36 #include <corelib/ncbiargs.hpp>
37 #include <dbapi/driver/dbapi_driver_conn_params.hpp>
38
39
40 BEGIN_NCBI_SCOPE
41
42
43 /////////////////////////////////////////////////////////////////////////////
44 // CDbapiDriverSampleApp::
45 //
46
47
CDbapiDriverSampleApp(const string & server_name,int tds_version)48 CDbapiDriverSampleApp::CDbapiDriverSampleApp(const string& server_name,
49 int tds_version) :
50 CNcbiApplication(),
51 m_DefaultServerName(server_name),
52 m_DefaultTDSVersion(tds_version)
53 {
54 return;
55 }
56
57
~CDbapiDriverSampleApp()58 CDbapiDriverSampleApp::~CDbapiDriverSampleApp()
59 {
60 return;
61 }
62
63
64 CDbapiDriverSampleApp::EServerType
GetServerType(void) const65 CDbapiDriverSampleApp::GetServerType(void) const
66 {
67 switch (CCPPToolkitConnParams::GetServerType(GetServerName())) {
68 case CCPPToolkitConnParams::eSybaseSQLServer:
69 case CCPPToolkitConnParams::eSybaseOpenServer:
70 return eSybase;
71 case CCPPToolkitConnParams::eMSSqlServer:
72 return eMsSql;
73 default:
74 return eUnknown;
75 }
76 }
77
78
79 void
Init()80 CDbapiDriverSampleApp::Init()
81 {
82 // Create command-line argument descriptions class
83 unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
84
85 // Specify USAGE context
86 arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
87 "DBAPI Sample Application");
88
89 // Describe the expected command-line arguments
90 arg_desc->AddDefaultKey("S", "server",
91 "Name of the SQL server to connect to",
92 CArgDescriptions::eString,
93 m_DefaultServerName);
94
95 arg_desc->AddDefaultKey("U", "username",
96 "User name",
97 CArgDescriptions::eString,
98 "DBAPI_test");
99
100 arg_desc->AddDefaultKey("P", "password",
101 "Password",
102 CArgDescriptions::eString,
103 "allowed");
104
105 arg_desc->AddDefaultKey("v", "version",
106 "TDS protocol version",
107 CArgDescriptions::eInteger,
108 NStr::IntToString(m_DefaultTDSVersion));
109
110 // Setup arg.descriptions for this application
111 SetupArgDescriptions(arg_desc.release());
112 }
113
114
115 int
Run()116 CDbapiDriverSampleApp::Run()
117 {
118
119 const CArgs& args = GetArgs();
120
121 // Get command-line arguments ...
122 m_ServerName = args["S"].AsString();
123 m_UserName = args["U"].AsString();
124 m_Password = args["P"].AsString();
125 m_TDSVersion = args["v"].AsInteger();
126
127 return RunSample();
128 }
129
130
131 END_NCBI_SCOPE
132
133