Exemple #1
0
void DynDBDriver
  ::TracksSnapshot::Transactor::operator()(pqxx::work& transaction)
{
  for (const DynDBDriver::Track_row& track : tracks_)
  {
    const std::string sql = "INSERT INTO track_snapshots "
        "(snapshot_id,track_id,lon,lat,meters_over_sea,"
        "lon_velocity,lat_velocity,meters_over_sea_velocity,"
        "predicted_lon,predicted_lat,predicted_meters_over_sea,"
        "refresh_time) "
        "VALUES("
        + pqxx::to_string(snapshotId_) + ",'"
        + pqxx::to_string(Track_row::uuidToString(track.uuid)) + "',"
        + pqxx::to_string(track.lon) + ","
        + pqxx::to_string(track.lat) + ","
        + pqxx::to_string(track.mos) + ","
        + pqxx::to_string(track.lonVelocity) + ","
        + pqxx::to_string(track.latVelocity) + ","
        + pqxx::to_string(track.mosVelocity) + ","
        + pqxx::to_string(track.predictedLon) + ","
        + pqxx::to_string(track.predictedLat) + ","
        + pqxx::to_string(track.predictedMos) + ","
        + "to_timestamp(" + pqxx::to_string(track.refreshTime) + "))";
    transaction.exec(sql);
  }

  transaction.commit();
}
Exemple #2
0
int
DSCStrategy::get_plot_id(const string& plot, pqxx::work& pg_db_trans) {

    stringstream sql;
    pqxx::result r;
    
    try {
        sql.clear();
        sql.str("");
        sql << "SELECT id FROM dsc.dataset WHERE name = '" << plot << "'" << endl;
        r = pg_db_trans.exec(sql.str());
        if ( r.size() != 1 ) {
            cerr << "Error: Expected 1 plot with name " << plot << ", "
                 << "but found " << r.size() << endl;
            exit( EXIT_FAILURE );
        }
    }
    catch( runtime_error & e )
    {
        cerr << "Runtime error: " << e.what() << endl;
        exit( EXIT_FAILURE );
    }
    catch( std::exception & e )
    {
        cerr << "Exception: " << e.what() << sql.str() << endl;
        exit( EXIT_FAILURE );
    }
    catch( ... )
    {
        cerr << "Unknown exception caught" << endl;
        exit( EXIT_FAILURE );
    }
    return r[0][0].as<int>();

}
tmp_nodes::tmp_nodes(pqxx::work &w, const int rid)
  : work(w) {

  // hack around problem with postgres' statistics, which was 
  // making it do seq scans all the time on smaug...
  w.exec("set enable_mergejoin=false");
  w.exec("set enable_hashjoin=false");

  stringstream query;
  query << "create temporary table tmp_nodes as "
		<< "select distinct(member_id) as id from current_relation_members where member_type = 'Node' and id = " << rid;
  logger::message("Creating tmp_nodes");

  // assume this throws if it fails?
  work.exec(query);
}
Exemple #4
0
	/// Perform the transaction itself
	void operator ()(pqxx::work & t)
	{
		// Setup wci:
		t.exec("SELECT wci.begin( 'wcitest', 999, 999, 999 )");

		// Request BLOB oid:
		const pqxx::result result = t.exec(myQuery);

		// Fetch each BLOB, and store it in the return object
		for (pqxx::result::const_iterator it = result.begin(); it != result.end(); ++it )
		{
			const pqxx::result::field & f = (*it)["value"];

			// Fetch the grid, remember to check for NULL
			float value = std::numeric_limits<float>::quiet_NaN();
			if ( not f.is_null() )
				value = f.as<float>();

			// Store data:
			const std::string identifier = (*it)["validtimeto"].as<std::string>() + " - " + (*it)["valueparametername"].as<std::string>();
			internalStorage_[identifier] = value;
		}
	}