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