Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:36

0001 #include "ODBCInterface.h"
0002 
0003 #include <odbc++/connection.h>
0004 #include <odbc++/resultset.h>
0005 #include <odbc++/statement.h>
0006 #include <odbc++/types.h>
0007 
0008 #include <iostream>
0009 #include <string>
0010 
0011 int main()
0012 {
0013   try
0014   {
0015     std::cout << "Testing ODBC." << std::endl;
0016 
0017     odbc::Statement* stmt = ODBCInterface::instance()->getStatement("spinDB");
0018     std::string query = "SELECT mbdvtx FROM spin WHERE runnumber = 45876";
0019 
0020     odbc::ResultSet* rs = stmt->executeQuery(query);
0021 
0022     while (rs->next())
0023     {
0024       // ======== Using getString() ============ //
0025       std::cout << "getString method:" << std::endl;
0026       std::string mbdvtx = rs->getString("mbdvtx");
0027       std::cout << mbdvtx << std::endl;
0028       // ======================================= //
0029 
0030       // ======== Using getBytes() ============ //
0031       std::cout << "getBytes method:" << std::endl;
0032       odbc::Bytes bytes = rs->getBytes("mbdvtx");
0033       const signed char* data = bytes.getData();
0034       std::string strdata(reinterpret_cast<const char*>(data));
0035       std::cout << strdata << std::endl;
0036       // ======================================= //
0037     }
0038 
0039     delete rs;
0040   }
0041   catch (odbc::SQLException& e)
0042   {
0043     std::cerr << "SQL Error: " << e.getMessage() << std::endl;
0044   }
0045   delete ODBCInterface::instance();
0046   return 0;
0047 }