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

Go to the SVN repository for this file.

1 /* $Id: dbapi_send_data.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 
27 #include <ncbi_pch.hpp>
28 #include "dbapi_send_data.hpp"
29 #include "../dbapi_sample_base.hpp"
30 #include <common/test_assert.h> /* This header must go last */
31 
33 
34 // This program will CREATE a table with 5 rows , UPDATE text field,
35 // PRINT table on screen (each row will begin with <ROW> and ended by </ROW>)
36 // and DELETE table from the database.
37 
38 // The following function illustrates an update text in the table by using SendData();
39 
40 /////////////////////////////////////////////////////////////////////////////
41 // CDbapiTestBcpApp::
42 //
43 
45 {
46 public:
47  CDbapiSendDataApp(void);
48  virtual ~CDbapiSendDataApp(void);
49 
50 protected:
51  virtual int RunSample(void);
52  string GetTableName(void) const;
53 };
54 
56 {
57 }
58 
60 {
61 }
62 
63 inline
64 string
66 {
67  return "#snd_test";
68 }
69 
70 int
72 {
73  try {
74  unique_ptr<CDB_LangCmd> set_cmd;
75 
77 
78  // Create table in database for the test
80 
81  CDB_Text txt;
82 
83  txt.Append ("This text will replace a text in the table.");
84 
85  // Example: update text field in the table CursorSample where int_val=4,
86  // by using function SendData()
87 
88  // Get a descriptor
89  CDB_BlobDescriptor d(GetTableName(), "txt_val", "int_val = 4");
90 
91  // Update text field
92  GetConnection().SendData(d, txt);
93 
94  // Print resutls on the screen
95  ShowResults("select int_val,fl_val,date_val,str_val,txt_val from " + GetTableName());
96 
97  // Delete table from database
99  }
100  catch ( CDB_Exception& e ) {
102  return 1;
103  }
104 
105  return 0;
106 }
107 
108 int main(int argc, char* argv[])
109 {
110  // Execute main application function
111  return CDbapiSendDataApp().AppMain(argc, argv);
112 }
113 
114 
void CreateTable(const string &table_name)
function CreateTable is creating table in the database
void ShowResults(const string &query)
Delete table if it exists ShowResults is printing resuts on screen.
static CDB_UserHandler & GetDefault(void)
Definition: exception.cpp:619
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:611
virtual bool HandleIt(CDB_Exception *ex)=0
Handle the exceptions resulting from a native API call, one-by-one.
int main(int argc, char *argv[])
I_DriverContext & GetDriverContext(void)
Get the driver context (for the driver specified in the command line)
void DeleteTable(const string &table_name)
virtual ~CDbapiSendDataApp(void)
CDB_Connection & GetConnection(void)
Get connection created using server, username and password specified in the application command line...
CDB_Exception –.
Definition: exception.hpp:116
virtual bool SendData(I_BlobDescriptor &desc, CDB_Stream &lob, bool log_it=true)
Shortcut to send text and image to the server without using the "Send-data" command (SendDataCmd) ...
Definition: public.cpp:395
virtual int RunSample(void)
virtual bool SetMaxBlobSize(size_t nof_bytes)=0
Set maximal size for BLOB data.
virtual size_t Append(const void *buff, size_t nof_bytes)
Definition: types.cpp:2197
string GetTableName(void) const
USING_NCBI_SCOPE
Modified on Sun Jun 25 17:46:31 2017 by modify_doxy.py rev. 533848