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

Go to the SVN repository for this file.

1 /* $Id: ctl_lang.cpp 70303 2015-12-17 18:55:21Z 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: Vladimir Soussov
27  *
28  * This simple program illustrates how to use the language command
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "../../dbapi_driver_sample_base.hpp"
36 #ifdef FTDS_IN_USE
37 # include <interfaces.hpp>
38 #else
40 #endif
42 #include <common/test_assert.h> /* This header must go last */
43 
44 
46 
47 
48 class CDemoApp : public CDbapiDriverSampleApp
49 {
50 public:
51  CDemoApp(const string& server_name,
53  virtual ~CDemoApp(void);
54 
55  virtual int RunSample(void);
56 };
57 
58 
59 CDemoApp::CDemoApp(const string& server_name, int tds_version) :
60  CDbapiDriverSampleApp(server_name, tds_version)
61 {
62 }
63 
64 
66 {
67  return;
68 }
69 
70 
71 int
73 {
74  try {
76 
77 #ifdef FTDS_IN_USE
78  CTDSContext my_context(true, GetTDSVersion());
79 #else
80  CTLibContext my_context(true, GetTDSVersion());
81 #endif
82 
84  GetUserName(),
85  GetPassword(),
86  0));
87 
89  (con->LangCmd("select name, crdate from sysdatabases"));
90  lcmd->Send();
91 
92  while (lcmd->HasMoreResults()) {
93  auto_ptr<CDB_Result> r(lcmd->Result());
94  if (!r.get())
95  continue;
96 
97  cout
98  << r->ItemName(0) << " \t\t\t"
99  << r->ItemName(1) << endl
100  << "-----------------------------------------------------"
101  << endl;
102 
103  while (r->Fetch()) {
104  CDB_Char dbname(24);
105  CDB_DateTime crdate;
106 
107  r->GetItem(&dbname);
108  r->GetItem(&crdate);
109 
110  cout
111  << dbname.AsString() << ' '
112  << crdate.Value().AsString("M/D/Y h:m") << endl;
113  }
114  }
115  } catch (CDB_Exception& e) {
116  CDB_UserHandler_Stream myExHandler(&cerr);
117 
118  myExHandler.HandleIt(&e);
119  return 1;
120  } catch (const CException&) {
121  return 1;
122  }
123 
124  return 0;
125 }
126 
127 int main(int argc, const char* argv[])
128 {
129  return CDemoApp("DBAPI_DEV3").AppMain(argc, argv);
130 }
131 
#define DBLB_INSTALL_DEFAULT()
Easy-to-use macro to install the default DBAPI service mapper.
const string & GetServerName(void) const
Return current server name.
int GetTDSVersion(void) const
Return TDS version.
virtual bool HandleIt(CDB_Exception *ex)
Handle the exceptions resulting from a native API call, one-by-one.
Definition: exception.cpp:756
int main(int argc, const char *argv[])
Definition: ctl_lang.cpp:127
const string & GetPassword(void) const
Return current password.
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:610
CDB_Connection * Connect(const string &srv_name, const string &user_name, const string &passwd, TConnectionMode mode, bool reusable=false, const string &pool_name=kEmptyStr)
Create new connection to specified server (or service) within this context.
Definition: interfaces.cpp:283
const string & AsString(void) const
Definition: types.hpp:515
virtual int RunSample(void)
Definition: ctl_lang.cpp:72
#define tds_version
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1514
const CTime & Value(void) const
Definition: types.cpp:2486
Derive our application class from CwxNCBIApp and use it together with standard CNCBIwxApplication.
virtual ~CDemoApp(void)
Definition: ctl_lang.cpp:65
CDB_Exception –.
Definition: exception.hpp:116
CException –.
Definition: ncbiexpt.hpp:709
char * dbname(DBPROCESS *dbproc)
Get name of current database.
Definition: dblib.c:6854
virtual bool Send()
Send command to the server.
Definition: public.cpp:731
USING_NCBI_SCOPE
Definition: ctl_lang.cpp:45
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
CS_INT GetCtlibTdsVersion(int version=0)
Definition: context.cpp:1580
const string & GetUserName(void) const
Return current user name.
Modified on Mon Jan 23 17:05:11 2017 by modify_doxy.py rev. 506947