dbapi_sample.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:24k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: dbapi_sample.cpp,v $
  4.  * PRODUCTION Revision 1000.2  2004/06/01 18:31:51  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: dbapi_sample.cpp,v 1000.2 2004/06/01 18:31:51 gouriano Exp $
  10. * ===========================================================================
  11. *
  12. *                            PUBLIC DOMAIN NOTICE
  13. *               National Center for Biotechnology Information
  14. *
  15. *  This software/database is a "United States Government Work" under the
  16. *  terms of the United States Copyright Act.  It was written as part of
  17. *  the author's official duties as a United States Government employee and
  18. *  thus cannot be copyrighted.  This software/database is freely available
  19. *  to the public for use. The National Library of Medicine and the U.S.
  20. *  Government have not placed any restriction on its use or reproduction.
  21. *
  22. *  Although all reasonable efforts have been taken to ensure the accuracy
  23. *  and reliability of the software and data, the NLM and the U.S.
  24. *  Government do not and cannot warrant the performance or results that
  25. *  may be obtained by using this software or data. The NLM and the U.S.
  26. *  Government disclaim all warranties, express or implied, including
  27. *  warranties of performance, merchantability or fitness for any particular
  28. *  purpose.
  29. *
  30. *  Please cite the author in any work or product based on this material.
  31. *
  32. * ===========================================================================
  33. *
  34. * Author: Michael Kholodov
  35. *
  36. * File Description:
  37. *   String representation of the database character types.
  38. *
  39. * ===========================================================================
  40. */
  41. #include <ncbi_pch.hpp>
  42. #include <corelib/ncbiapp.hpp>
  43. #include <corelib/ncbiargs.hpp>
  44. #include <corelib/ncbienv.hpp>
  45. #include <dbapi/dbapi.hpp>
  46. #include <dbapi/driver/drivers.hpp>
  47. #include <vector>
  48. USING_NCBI_SCOPE;
  49. /////////////////////////////////////////////////////////////////////////////
  50. //  MAIN
  51. class CDbapiTest : public CNcbiApplication
  52. {
  53. private:
  54.     virtual void Init();
  55.     virtual int Run();
  56.     virtual void Exit();
  57.   
  58.     CArgDescriptions *argList;
  59. };
  60. void CDbapiTest::Init()
  61. {
  62.     argList = new CArgDescriptions();
  63.     argList->SetUsageContext(GetArguments().GetProgramBasename(),
  64.                              "DBAPI test program");
  65. #ifdef WIN32
  66.    argList->AddDefaultKey("s", "string",
  67.                            "Server name",
  68.                            CArgDescriptions::eString, "MSSQL2");
  69.    argList->AddDefaultKey("d", "string",
  70.                            "Driver <ctlib|dblib|ftds|odbc>",
  71.                            CArgDescriptions::eString, 
  72.                            "odbc");
  73. #else
  74.     argList->AddDefaultKey("s", "string",
  75.                            "Server name",
  76.                            CArgDescriptions::eString, "STRAUSS");
  77.     argList->AddDefaultKey("d", "string",
  78.                            "Driver <ctlib|dblib|ftds>",
  79.                            CArgDescriptions::eString, 
  80.                            "ctlib");
  81. #endif
  82.     SetupArgDescriptions(argList);
  83. }
  84.   
  85. int CDbapiTest::Run() 
  86. {
  87.     CArgs args = GetArgs();
  88.     IDataSource *ds = 0;
  89.     try {
  90.         
  91.         CDriverManager &dm = CDriverManager::GetInstance();
  92.         string server = args["s"].AsString();
  93.         string driver = args["d"].AsString();
  94.         // Register driver explicitly for static linkage if needed
  95. #ifdef WIN32
  96.         DBAPI_RegisterDriver_ODBC(dm);
  97. #endif
  98.         //DBAPI_RegisterDriver_DBLIB(dm);
  99.         // Create data source - the root object for all other
  100.         // objects in the library.
  101.         //
  102.         // set TDS version for STRAUSS
  103.         if( NStr::CompareNocase(server, "STRAUSS") == 0 ) {
  104.             map<string,string> attr;
  105.             attr["version"] = "100";
  106.             ds = dm.CreateDs(driver, &attr);
  107.         }
  108.         else
  109.             ds = dm.CreateDs(driver);
  110.         // Redirect error messages to CMultiEx storage in the
  111.         // data source object (global). Default output is sent
  112.         // to standard error
  113.         //
  114.         //ds->SetLogStream(0);
  115.         // Create connection. 
  116.         IConnection* conn = ds->CreateConnection();
  117.         // Set this mode to be able to use bulk insert
  118.         conn->SetMode(IConnection::eBulkInsert);
  119.         // To ensure, that only one database connection is used
  120.         // use this method. It will throw an exception, if the
  121.         // library tries to open additional connections implicitly, 
  122.         // like creating multiple statements.
  123.         //conn->ForceSingle(true);
  124.         conn->Connect("anyone",
  125.                       "allowed",
  126.                       server,
  127.                       "DBAPI_Sample");
  128.     
  129.         NcbiCout << "Using server: " << server
  130.                  << ", driver: " << driver << endl;
  131. /*
  132.         // Test section start
  133.         try {
  134.             IDataSource *ds2 = dm.CreateDs(driver);
  135.             IConnection* conn2 = ds2->CreateConnection();
  136.             
  137.             conn2->Connect("kholodov",
  138.                            "newuser",
  139.                            "MOZART");
  140.             IStatement *stmt = conn2->CreateStatement();
  141.             stmt->ExecuteUpdate("print 'Test print from MOZART'");
  142.             delete conn2;
  143.         }
  144.         catch (exception& e) {
  145.             NcbiCerr << e.what() << endl;
  146.         }
  147.         exit(0);
  148.         // Test section end
  149. */    
  150.         IStatement *stmt = conn->CreateStatement();
  151.         string sql = "select int_val, fl_val, date_val, str_val 
  152. from SelectSample ";
  153.         NcbiCout << endl << "Testing simple select..." << endl
  154.                  << sql << endl;
  155.         conn->MsgToEx(true);
  156.         try {
  157.             stmt->Execute(sql);
  158.     
  159.             while( stmt->HasMoreResults() ) {
  160.                 if( stmt->HasRows() ) {   
  161.                     IResultSet *rs = stmt->GetResultSet();
  162.                     const IResultSetMetaData* rsMeta = rs->GetMetaData();
  163.                     rs->BindBlobToVariant(true);
  164.                     for(unsigned int i = 1; i <= rsMeta->GetTotalColumns(); ++i )
  165.                         NcbiCout << rsMeta->GetName(i) << "  ";
  166.                     NcbiCout << endl;
  167.                     while(rs->Next()) { 
  168.                         for(unsigned int i = 1;  i <= rsMeta->GetTotalColumns(); ++i ) {
  169.                             if( rsMeta->GetType(i) == eDB_Text
  170.                                 || rsMeta->GetType(i) == eDB_Image ) {
  171.                                 CDB_Stream *b = dynamic_cast<CDB_Stream*>(rs->GetVariant(i).GetData());
  172.                                 _ASSERT(b);
  173.                                 char *buf = new char[b->Size() + 1];
  174.                                 b->Read(buf, b->Size());
  175.                                 buf[b->Size()] = '';
  176.                                 NcbiCout << buf << "|";
  177.                                 delete buf;
  178.                                 
  179.                             }
  180.                             else
  181.                                 NcbiCout << rs->GetVariant(i).GetString() << "|";
  182.                         }
  183.                         NcbiCout << endl;
  184.                                 
  185.                             
  186. #if 0
  187.                         NcbiCout << rs->GetVariant(1).GetInt4() << "|"
  188.                                  << rs->GetVariant(2).GetFloat() << "|"
  189.                                  << rs->GetVariant("date_val").GetString() << "|"
  190.                                  << rs->GetVariant(4).GetString()
  191.                                  << endl;
  192. #endif
  193.                     
  194.                     } 
  195.                     // Use Close() to free database resources and leave DBAPI framwork intact
  196.                     // All closed DBAPI objects become invalid.
  197.                     rs->Close();
  198.                     
  199.                     // Delete object to get rid of it completely. All child objects will be also deleted
  200.                     delete rs;
  201.                 }
  202.             }
  203.         }
  204.         catch(CDB_Exception& e) {
  205.             NcbiCout << "Exception: " << e.what() << endl;
  206.             NcbiCout << conn->GetErrorInfo();
  207.         } 
  208.         NcbiCout << "Rows : " << stmt->GetRowCount() << endl;
  209.         conn->MsgToEx(false);
  210. /*
  211.         // Testing MSSQL XML output
  212.         sql += " for xml auto, elements";
  213.         NcbiCout << "Testing simple select with XML output..." << endl
  214.                  << sql << endl;
  215.         conn->MsgToEx(true);
  216.         try {
  217.             stmt->Execute(sql);
  218.     
  219.             while( stmt->HasMoreResults() ) {
  220.                 if( stmt->HasRows() ) {   
  221.                     IResultSet *rs = stmt->GetResultSet();
  222.                     const IResultSetMetaData *rsMeta = rs->GetMetaData();
  223.                     rs->BindBlobToVariant(true);
  224.                     for(int i = 1; i <= rsMeta->GetTotalColumns(); ++i )
  225.                         NcbiCout << rsMeta->GetName(i) << "  ";
  226.                     NcbiCout << endl;
  227.                     while(rs->Next()) { 
  228.                         for(int i = 1;  i <= rsMeta->GetTotalColumns(); ++i ) {
  229.                             if( rsMeta->GetType(i) == eDB_Text
  230.                                 || rsMeta->GetType(i) == eDB_Image ) {
  231.                                 CDB_Stream *b = dynamic_cast<CDB_Stream*>(rs->GetVariant(i).GetData());
  232.                                 _ASSERT(b);
  233.                                 char *buf = new char[b->Size() + 1];
  234.                                 b->Read(buf, b->Size());
  235.                                 buf[b->Size()] = '';
  236.                                 NcbiCout << buf << "|";
  237.                                 delete buf;
  238.                                 
  239.                             }
  240.                             else
  241.                                 NcbiCout << rs->GetVariant(i).GetString() << "|";
  242.                         }
  243.                         NcbiCout << endl;
  244.                     
  245.                     } 
  246.                     
  247.                 }
  248.             }
  249.         }
  250.         catch(CDB_Exception& e) {
  251.             NcbiCout << "Exception: " << e.what() << endl;
  252.             NcbiCout << ds->GetErrorInfo();
  253.         } 
  254.         
  255.         exit(1);
  256.         //delete stmt;
  257. */
  258.         // Testing bulk insert w/o BLOBs
  259.         NcbiCout << endl << "Creating BulkSample table..." << endl;
  260.         sql = "if exists( select * from sysobjects 
  261. where name = 'BulkSample' 
  262. AND type = 'U') 
  263. begin 
  264. drop table BulkSample 
  265. end";
  266.         stmt->ExecuteUpdate(sql);
  267.         sql = "create table BulkSample (
  268. id int not null, 
  269. ord int not null, 
  270.     mode tinyint not null, 
  271.     date datetime not null)";
  272.         stmt->ExecuteUpdate(sql);
  273.         //I_DriverContext *ctx = ds->GetDriverContext();
  274.         //delete ctx;
  275.         try {
  276.             //Initialize table using bulk insert
  277.             NcbiCout << "Initializing BulkSample table..." << endl;
  278.             IBulkInsert *bi = conn->CreateBulkInsert("BulkSample", 4);
  279.             CVariant b1(eDB_Int);
  280.             CVariant b2(eDB_Int);
  281.             CVariant b3(eDB_TinyInt);
  282.             CVariant b4(eDB_DateTime);
  283.             bi->Bind(1, &b1);
  284.             bi->Bind(2, &b2);
  285.             bi->Bind(3, &b3);
  286.             bi->Bind(4, &b4);
  287.             int i;
  288.             for( i = 0; i < 10; ++i ) {
  289.                 b1 = i;
  290.                 b2 = i * 2;
  291.                 b3 = Uint1(i + 1);
  292.                 b4 = CTime(CTime::eCurrent);
  293.                 bi->AddRow();
  294.                 //bi->StoreBatch();
  295.             }
  296.             
  297.             bi->Complete();
  298.         }
  299.         catch(...) {
  300.             throw;
  301.         }
  302.         // create a stored procedure
  303.         sql = "if exists( select * from sysobjects 
  304. where name = 'SampleProc' 
  305. AND type = 'P') 
  306. begin 
  307. drop proc SampleProc 
  308. end";
  309.         stmt->ExecuteUpdate(sql);
  310.         sql = "create procedure SampleProc 
  311. @id int, 
  312. @f float, 
  313.     @o int output 
  314. as 
  315. begin 
  316.   select int_val, fl_val, date_val from SelectSample 
  317.   where int_val < @id and fl_val <= @f 
  318.   select @o = 555 
  319.   select 2121, 'Parameter @id:', @id, 'Parameter @f:', @f, 'Parameter @o:', @o  
  320.   print 'Print test output' 
  321.   return @id 
  322. end";
  323.         //  raiserror('Raise Error test output', 1, 1) 
  324.         stmt->ExecuteUpdate(sql);
  325.         stmt->ExecuteUpdate("print 'test'");
  326.         float f = 2.999f;
  327.         // call stored procedure
  328.         NcbiCout << endl << "Calling stored procedure..." << endl;
  329.         
  330.         ICallableStatement *cstmt = conn->PrepareCall("SampleProc", 3);
  331.         cstmt->SetParam(CVariant(5), "@id");
  332.         cstmt->SetParam(CVariant::Float(&f), "@f");
  333.         cstmt->SetOutputParam(CVariant(eDB_Int), "@o");
  334.         cstmt->Execute(); 
  335.     
  336.         // Below is an example of using auto_ptr to avoid resource wasting
  337.         // in case of multiple resultsets, statements, etc.
  338.         // NOTE: Use it with caution, when the wrapped parent object
  339.         // goes out of scope, all child objects are destroyed.
  340.         while(cstmt->HasMoreResults()) {
  341.             auto_ptr<IResultSet> rs(cstmt->GetResultSet());
  342.             //NcbiCout << "Row count: " << cstmt->GetRowCount() << endl;
  343.             if( !cstmt->HasRows() ) {
  344.                 continue;
  345.             }
  346.             switch( rs->GetResultType() ) {
  347.             case eDB_ParamResult:
  348.                 while( rs->Next() ) {
  349.                     NcbiCout << "Output param: "
  350.                              << rs->GetVariant(1).GetInt4()
  351.                              << endl;
  352.                 }
  353.                 break;
  354.             case eDB_RowResult:
  355.                 while( rs->Next() ) {
  356.                     if( rs->GetVariant(1).GetInt4() == 2121 ) {
  357.                             NcbiCout << rs->GetVariant(2).GetString() << " "
  358.                                      << rs->GetVariant(3).GetString() << " "
  359.                                      << rs->GetVariant(4).GetString() << " "
  360.                                      << rs->GetVariant(5).GetString() << " "
  361.                                      << rs->GetVariant(6).GetString() << " "
  362.                                      << rs->GetVariant(7).GetString() << " "
  363.                                      << endl;
  364.                     }
  365.                     else {
  366.                         NcbiCout << rs->GetVariant(1).GetInt4() << "|"
  367.                                  << rs->GetVariant(2).GetFloat() << "|"
  368.                                  << rs->GetVariant("date_val").GetString() << "|"
  369.                                  << endl;
  370.                     }
  371.                 }
  372.                 break;
  373.             }
  374.         }
  375.         NcbiCout << "Status : " << cstmt->GetReturnStatus() << endl;
  376.         NcbiCout << endl << ds->GetErrorInfo() << endl;
  377.        
  378.         delete cstmt;
  379.         // call stored procedure using language call
  380.         NcbiCout << endl << "Calling stored procedure using language call..." << endl;
  381.         
  382.         sql = "exec SampleProc @id, @f, @o output";
  383.         stmt->SetParam(CVariant(5), "@id");
  384.         stmt->SetParam(CVariant::Float(&f), "@f");
  385.         stmt->SetParam(CVariant(5), "@o");
  386.         stmt->Execute(sql); 
  387.     
  388.         while(stmt->HasMoreResults()) {
  389.             IResultSet *rs = stmt->GetResultSet();
  390.             //NcbiCout << "Row count: " << stmt->GetRowCount() << endl;
  391.             if( rs == 0 )
  392.                 continue;
  393.             switch( rs->GetResultType() ) {
  394.             case eDB_ParamResult:
  395.                 while( rs->Next() ) {
  396.                     NcbiCout << "Output param: "
  397.                              << rs->GetVariant(1).GetInt4()
  398.                              << endl;
  399.                 }
  400.                 break;
  401.             case eDB_StatusResult:
  402.                 while( rs->Next() ) {
  403.                     NcbiCout << "Return status: "
  404.                              << rs->GetVariant(1).GetInt4()
  405.                              << endl;
  406.                 }
  407.                 break;
  408.             case eDB_RowResult:
  409.                 while( rs->Next() ) {
  410.                     if( rs->GetVariant(1).GetInt4() == 2121 ) {
  411.                             NcbiCout << rs->GetVariant(2).GetString() << "|"
  412.                                      << rs->GetVariant(3).GetString() << "|"
  413.                                      << rs->GetVariant(4).GetString() << "|"
  414.                                      << rs->GetVariant(5).GetString() << "|"
  415.                                      << rs->GetVariant(6).GetString() << "|"
  416.                                      << rs->GetVariant(7).GetString() << "|"
  417.                                      << endl;
  418.                     }
  419.                     else {
  420.                         NcbiCout << rs->GetVariant(1).GetInt4() << "|"
  421.                                  << rs->GetVariant(2).GetFloat() << "|"
  422.                                  << rs->GetVariant("date_val").GetString() << "|"
  423.                                  << endl;
  424.                     }
  425.                 }
  426.                 break;
  427.             }
  428.         }
  429.         stmt->ClearParamList();
  430.         //exit(1);
  431.         // Reconnect
  432.         NcbiCout << endl << "Reconnecting..." << endl;
  433.         delete conn;
  434.         conn = ds->CreateConnection();
  435.         conn->SetMode(IConnection::eBulkInsert);
  436.         conn->Connect("anyone",
  437.                       "allowed",
  438.                       server,
  439.                       "DBAPI_Sample");
  440.         stmt = conn->CreateStatement();
  441.         NcbiCout << endl << "Reading BLOB..." << endl;
  442.         // Read blob to vector
  443.         vector<char> blob;
  444.  
  445.         NcbiCout << "Retrieve BLOBs using streams" << endl;
  446.         stmt->ExecuteUpdate("set textsize 2000000");
  447.     
  448.         stmt->Execute("select str_val, text_val, text_val 
  449. from SelectSample where int_val = 1");
  450.     
  451.         while( stmt->HasMoreResults() ) { 
  452.             if( stmt->HasRows() ) {
  453.                 IResultSet *rs = stmt->GetResultSet();
  454.                 int size = 0;
  455.                 while(rs->Next()) { 
  456.                     NcbiCout << "Reading: " << rs->GetVariant(1).GetString() 
  457.                              << endl;
  458.                     istream& in1 = rs->GetBlobIStream();
  459.                     int c = 0; 
  460.                     NcbiCout << "Reading first blob..." << endl;
  461.                     for( ;(c = in1.get()) != CT_EOF; ++size ) {
  462.                         blob.push_back(c);
  463.                     }
  464.                     istream& in2 = rs->GetBlobIStream();
  465.                     NcbiCout << "Reading second blob..." << endl;
  466.                     
  467.                     for( ;(c = in2.get()) != CT_EOF; ++size ) { 
  468.                         blob.push_back(c);
  469.                     }
  470.                 } 
  471.                 NcbiCout << "Bytes read: " << size << endl;
  472.             }
  473.         }
  474.     
  475.         // create a table
  476.         NcbiCout << endl << "Creating BlobSample table..." << endl;
  477.         sql = "if exists( select * from sysobjects 
  478. where name = 'BlobSample' 
  479. AND type = 'U') 
  480. begin 
  481. drop table BlobSample 
  482. end";
  483.         stmt->ExecuteUpdate(sql);
  484.         sql = "create table BlobSample (
  485. id int null, 
  486. blob text null, unique (id))";
  487.         stmt->ExecuteUpdate(sql);
  488.         // Write BLOB several times
  489.         const int COUNT = 5;
  490.         int cnt = 0;
  491.         // Create alternate blob storage
  492.         char *buf = new char[blob.size()];
  493.         char *p = buf;
  494.         vector<char>::iterator i_b = blob.begin();
  495.         for( ; i_b != blob.end(); ++i_b ) {
  496.             *p++ = *i_b;
  497.         }
  498.         //Initialize table using bulk insert
  499.         NcbiCout << "Initializing BlobSample table..." << endl;
  500.         IBulkInsert *bi = conn->CreateBulkInsert("BlobSample", 2);
  501.         CVariant col1 = CVariant(eDB_Int);
  502.         CVariant col2 = CVariant(eDB_Text);
  503.         bi->Bind(1, &col1);
  504.         bi->Bind(2, &col2);
  505.         for(int i = 0; i < COUNT; ++i ) {
  506.             string im = "BLOB data " + NStr::IntToString(i);
  507.             col1 = i;
  508.             col2.Truncate();
  509.             col2.Append(im.c_str(), im.size());
  510.             bi->AddRow();
  511.         }
  512.         bi->Complete();
  513.         
  514.         NcbiCout << "Writing BLOB using cursor..." << endl;
  515.         ICursor *blobCur = conn->CreateCursor("test", 
  516.            "select id, blob from BlobSample for update of blob");
  517.     
  518.         IResultSet *blobRs = blobCur->Open();
  519.         while(blobRs->Next()) {
  520.                 NcbiCout << "Writing BLOB " << ++cnt << endl;
  521.                 ostream& out = blobCur->GetBlobOStream(2, blob.size(), eDisableLog);
  522.                 out.write(buf, blob.size());
  523.                 out.flush();
  524.         }
  525.      
  526.         blobCur->Close();
  527. #ifndef WIN32 // Not supported by ODBC driver
  528.         NcbiCout << "Writing BLOB using resultset..." << endl;
  529.         sql = "select id, blob from BlobSample";
  530.         if( NStr::CompareNocase(driver, "ctlib") == 0 )
  531.             sql += " at isolation read uncommitted";
  532.         stmt->Execute(sql);
  533.     
  534.         cnt = 0;
  535.         while( stmt->HasMoreResults() ) {
  536.             if( stmt->HasRows() ) {
  537.                 IResultSet *rs = stmt->GetResultSet();
  538.                 while(rs->Next()) {
  539.                     NcbiCout << "Writing BLOB " << ++cnt << endl;
  540.                     ostream& out = rs->GetBlobOStream(blob.size(), eDisableLog);
  541.                     out.write(buf, blob.size());
  542.                     out.flush();
  543.                 }
  544.             }
  545.         }
  546. #endif
  547. #if 0
  548.         while( stmt->HasMoreResults() ) {
  549.             if( stmt->HasRows() ) {
  550.                 IResultSet *rs = stmt->GetResultSet();
  551.                 while(rs->Next()) {
  552.                     ostream& out = rs->GetBlobOStream(blob.size());
  553.                     vector<char>::iterator i = blob.begin();
  554.                     for( ; i != blob.end(); ++i )
  555.                         out << *i;
  556.                     out.flush();
  557.                 }
  558.             }
  559.         }
  560. #endif
  561.         delete buf;
  562.         // check if Blob is there
  563.         NcbiCout << "Checking BLOB size..." << endl;
  564.         stmt->Execute("select 'Written blob size' as size, datalength(blob) 
  565. from BlobSample where id = 1");
  566.     
  567.         while( stmt->HasMoreResults() ) {
  568.             if( stmt->HasRows() ) {
  569.                 IResultSet *rs = stmt->GetResultSet();
  570.                 while(rs->Next()) {
  571.                     NcbiCout << rs->GetVariant(1).GetString() << ": " 
  572.                              << rs->GetVariant(2).GetInt4() << endl;
  573.                 }
  574.             }
  575.         }
  576.         // Cursor test (remove blob)
  577.         NcbiCout << "Cursor test, removing blobs" << endl;
  578.         ICursor *cur = conn->CreateCursor("test", 
  579.                                           "select id, blob from BlobSample for update of blob");
  580.     
  581.         IResultSet *rs = cur->Open();
  582.         while(rs->Next()) {
  583.             cur->Update("BlobSample", "update BlobSample set blob = ' '");
  584.         }
  585.      
  586.         cur->Close();
  587.         // drop BlobSample table
  588.         NcbiCout << "Deleting BlobSample table..." << endl;
  589.         sql = "drop table BlobSample";
  590.         stmt->ExecuteUpdate(sql);
  591.         NcbiCout << "Done." << endl;
  592.     }
  593.     catch(out_of_range) {
  594.         NcbiCout << "Exception: Out of range" << endl;
  595.     }
  596.     catch(exception& e) {
  597.         NcbiCout << "Exception: " << e.what() << endl;
  598.         NcbiCout << ds->GetErrorInfo();
  599.     }
  600.     return 0;
  601. }
  602. void CDbapiTest::Exit()
  603. {
  604. }
  605. int main(int argc, const char* argv[])
  606. {
  607.     return CDbapiTest().AppMain(argc, argv, 0, eDS_Default, 0);
  608. }
  609. /*
  610. * ---------------------------------------------------------------------------
  611. * $Log: dbapi_sample.cpp,v $
  612. * Revision 1000.2  2004/06/01 18:31:51  gouriano
  613. * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12
  614. *
  615. * Revision 1.12  2004/05/21 21:41:41  gorelenk
  616. * Added PCH ncbi_pch.hpp
  617. *
  618. * Revision 1.11  2004/03/01 21:03:47  kholodov
  619. * Added comments
  620. *
  621. * Revision 1.10  2004/02/27 14:35:44  kholodov
  622. * Comments added, work in progress
  623. *
  624. * Revision 1.9  2003/10/09 21:25:36  kholodov
  625. * Several tests added
  626. *
  627. * Revision 1.8  2003/03/06 16:17:21  kholodov
  628. * Fixed: incorrect TDS version for STRAUSS
  629. *
  630. * Revision 1.7  2002/10/23 13:32:59  kholodov
  631. * Fixed: extra exit() call removed
  632. *
  633. * Revision 1.6  2002/10/03 18:59:55  kholodov
  634. * *** empty log message ***
  635. *
  636. * Revision 1.5  2002/10/02 15:06:58  kholodov
  637. * Modified: default connection settings for UNIX and NT platforms
  638. *
  639. * Revision 1.4  2002/10/01 18:57:45  kholodov
  640. * Added: bulk insert test
  641. *
  642. * Revision 1.3  2002/09/19 14:38:49  kholodov
  643. * Modified: to work with ODBC driver
  644. *
  645. * Revision 1.2  2002/09/17 21:17:15  kholodov
  646. * Filed moved to new location
  647. *
  648. * Revision 1.5  2002/09/16 21:08:33  kholodov
  649. * Added: bulk insert operations
  650. *
  651. * Revision 1.4  2002/09/03 18:41:53  kholodov
  652. * Added multiple BLOB updates, use of IResultSetMetaData
  653. *
  654. * Revision 1.3  2002/07/12 19:23:03  kholodov
  655. * Added: update BLOB using cursor for all platforms
  656. *
  657. * Revision 1.2  2002/07/08 16:09:24  kholodov
  658. * Added: BLOB update thru cursor
  659. *
  660. * Revision 1.1  2002/07/02 13:48:30  kholodov
  661. * First commit
  662. *
  663. *
  664. */