#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "phool.h" using namespace odbc; using namespace std; extern "C" { // This constuction is used extern struct { // to pass variables to/from float xmid[24]; // named common block float ymid[24]; // common/wedgesurvey/. float wphi[24]; // } wedgesurvey_ ; // (name cannot contain underscores) } // extern "C" void fvtx_getsurvey__(int &ver, char station[3]) { Connection* con = NULL; Statement* stmt = NULL; ResultSet* rs = NULL; ostringstream cmd; int l_version, v_seen; //Connect to database fvtx as user phnxrc. Database server //name comes from /opt/phenix/etc/odbc.ini config file. The third //argument is the password and left blank because it's automatically //picked up from odbc.ini file try { con = DriverManager::getConnection("fvtx", "phnxrc", ""); } catch (SQLException& e) { cout << PHWHERE << " Exception caught during DriverManager::getConnection" << endl; cout << e.getMessage() << endl; return; } //if(con){ cout << "connected" << endl; } //printf ("args: ver %d, station %s \n\n",ver,station); cmd.str(""); cmd << "select version,object from fvtx_survey WHERE object='"<createStatement(); rs = stmt->executeQuery(cmd.str().c_str()); int nrows=0; // see if there are any rows, and how many int v_get = 0; // find highest version number while (rs->next() ) { nrows++; v_seen = rs->getInt(1); // read the version numbers //cout <<" version seen: "<< v_seen <v_get) v_get = v_seen; // get the highest version } if (ver != 0) v_get = ver; // unless a specific version was requested //cout <<" version to get: "<< v_get << endl; if (nrows==0 ) { cout <<" NO RECORD seen for "<createStatement(); try { rs = stmt->executeQuery(cmd.str().c_str()); } catch (SQLException& e) { cout << e.getMessage() << endl; } rs->next(); string dim; // Postgres array dimension has dim = ""; // the following format: [1:24] dim = rs->getString(1); // 1 - is array dim, 24 is the length dim = dim.substr(dim.size()-3,2); // Array size in ascii. Fish out the '24'. for(int i = 1; i <= atoi(dim.c_str()); i++){ // loop over array elements cmd.str(""); cmd << "select values[" << i << "] from fvtx_survey where version="<createStatement(); try { rs = stmt->executeQuery(cmd.str().c_str()); } catch (SQLException& e) { cout << e.getMessage() << endl; } rs->next(); //cout <<"getFloat: "<< rs->getFloat(1) << endl; if (xyphi==0) wedgesurvey_.xmid[i-2] = rs->getFloat(1); // copy to struct if (xyphi==1) wedgesurvey_.ymid[i-2] = rs->getFloat(1); if (xyphi==2) wedgesurvey_.wphi[i-2] = rs->getFloat(1); } // loop over array entries //cout <<" DB val: "<< wedgesurvey_.wphi[0] << endl; } // loop over x, y, phi } //if there is a record } // end of getsurvey