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

Go to the SVN repository for this file.

1 /* $Id $
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 RPC command
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <corelib/ncbiapp.hpp>
38 #include <common/test_assert.h> /* This header must go last */
39 
40 
42 
43 
45 {
46 public:
47  virtual ~COdbcSpwhoDemoApp(void) {}
48 
49  virtual int Run(void);
50 };
51 
52 int
54 {
55  try {
57 
58  CODBCContext my_context;
59 
60  unique_ptr<CDB_Connection> con(my_context.Connect("msdev1",
61  "DBAPI_test",
62  "allowed",
63  0));
64 
65  unique_ptr<CDB_RPCCmd> rcmd(con->RPC("sp_who"));
66  rcmd->Send();
67 
68  while (rcmd->HasMoreResults()) {
69  unique_ptr<CDB_Result> r(rcmd->Result());
70  if (!r.get())
71  continue;
72 
73  if (r->ResultType() == eDB_RowResult) {
74  while (r->Fetch()) {
75  for (unsigned int j = 0; j < r->NofItems(); j++) {
76  EDB_Type rt = r->ItemDataType(j);
77  if (rt == eDB_Char || rt == eDB_VarChar) {
78  CDB_VarChar r_vc;
79  r->GetItem(&r_vc);
80  cout << r->ItemName(j) << ": " << r_vc.AsString()
81  << " \t";
82  } else if (rt == eDB_Int ||
83  rt == eDB_SmallInt ||
84  rt == eDB_TinyInt) {
85  CDB_Int r_in;
86  r->GetItem(&r_in);
87  cout << r->ItemName(j) << ": " << r_in.Value() << ' ';
88  } else
89  r->SkipItem();
90  }
91  cout << endl;
92  }
93  }
94  }
95  } catch (CDB_Exception& e) {
96  CDB_UserHandler_Stream myExHandler(&cerr);
97 
98  myExHandler.HandleIt(&e);
99  return 1;
100  } catch (const CException&) {
101  return 1;
102  }
103 
104  return 0;
105 }
106 
107 int main(int argc, const char* argv[])
108 {
109  return COdbcSpwhoDemoApp().AppMain(argc, argv);
110 }
111 
112 
113 
CDB_Exception –.
Definition: exception.hpp:118
virtual int Run(void)
Run the application.
Definition: odbc_sp_who.cpp:53
virtual ~COdbcSpwhoDemoApp(void)
Definition: odbc_sp_who.cpp:47
#define DBLB_INSTALL_DEFAULT()
Easy-to-use macro to install the default DBAPI service mapper.
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
virtual bool HandleIt(CDB_Exception *ex)
Handle the exceptions resulting from a native API call, one-by-one.
Definition: exception.cpp:765
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:295
@ eDB_RowResult
Definition: interfaces.hpp:387
EDB_Type
Definition: types.hpp:52
Int4 Value() const
Definition: types.hpp:373
const string & AsString(void) const
Definition: types.hpp:517
@ eDB_Char
Definition: types.hpp:58
@ eDB_VarChar
Definition: types.hpp:57
@ eDB_TinyInt
Definition: types.hpp:55
@ eDB_Int
Definition: types.hpp:53
@ eDB_SmallInt
Definition: types.hpp:54
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
int main(int argc, const char *argv[])
USING_NCBI_SCOPE
Definition: odbc_sp_who.cpp:41
Modified on Fri Sep 20 14:58:23 2024 by modify_doxy.py rev. 669887