HumanWithVolumeRecordMap HumanAccessorPostgresql::prepareResultGetRecords(
    pqxx::result const & a_result,
    IDHolder     const & a_id_holder
) const
{
    // Create a result map.
    HumanWithVolumeRecordMap records;

    // Prepare types for the values to be written to.
    string key;
    Volume volume;

    for (pqxx::result::const_iterator it = a_result.begin(); it != a_result.end(); ++it)
    {
        // Get the values.
        it["human_key"].to(key);
        it["volume"].to(volume);

        // Create a corresponding record.
        HumanWithVolumeRecordShrPtr record = make_shared<HumanWithVolumeRecord>(a_id_holder, key, volume);

        // Create a pair.
        HumanWithVolumeRecordPair pair(key, record);

        // Add record to the result.
        records.insert(pair);
    }

    return records;
}
ILandRecordMap LandAccessorPostgresql::prepareResultGetRecords(
    pqxx::result const & a_result
) const
{
    string login;
    string world_name;
    string land_name;
    int turns;
    bool granted;

    ILandRecordMap records;

    for (pqxx::result::const_iterator it = a_result.begin(); it != a_result.end(); ++it)
    {
        it["login"].to(login);
        it["world_name"].to(world_name);
        it["land_name"].to(land_name);
        it["turns"].to(turns);
        it["granted"].to(granted);

        ILandRecordShrPtr record = ILandRecordShrPtr(new LandRecord(login, world_name, land_name, turns, granted));
        ILandRecordPair pair(land_name, record);
        records.insert(pair);
    }

    return records;
}
const bool tissuestack::database::LabelLookupDataProvider::persistLookupValues(const tissuestack::imaging::TissueStackLabelLookup * lookup)
{
	if (lookup == nullptr) return false;

	// request a new id
	const pqxx::result results =
		tissuestack::database::TissueStackPostgresConnector::instance()->executeNonTransactionalQuery(
			"SELECT NEXTVAL('atlas_info_id_seq'::regclass);");
	if (results.empty())
		return false;
	const unsigned long long int id =
		results[0][0].as<unsigned long long int>();

	const std::string sql =
		"INSERT INTO dataset_values_lookup (id, filename, content) VALUES("
			+ std::to_string(id)
			+ ",'"
			+ lookup->getLabelLookupId(true) + "','"
			+ lookup->getContentForSql() + "')";
	if (tissuestack::database::TissueStackPostgresConnector::instance()->executeTransaction({sql}) == 1)
	{
		const_cast<tissuestack::imaging::TissueStackLabelLookup *>(lookup)->setDataBaseInfo(id, nullptr);
		return true;
	}

	return false;
}
const tissuestack::imaging::TissueStackLabelLookup * tissuestack::database::LabelLookupDataProvider::queryLookupValuesByFileName(
		const std::string file_name) {
	if (file_name.empty())
		return nullptr;

	const std::string sql =
			"SELECT * FROM dataset_values_lookup WHERE filename='"
			+ file_name + "';";

	tissuestack::imaging::TissueStackLabelLookup * ret = nullptr;

	const pqxx::result results =
			tissuestack::database::TissueStackPostgresConnector::instance()->executeNonTransactionalQuery(sql);

	if (results.size() == 0) return ret;
	if (results.size() > 1)
		THROW_TS_EXCEPTION(tissuestack::common::TissueStackApplicationException,
			"Unique key based search returned more than 1 record!");

	for (pqxx::result::const_iterator look = results.begin(); look != results.end(); ++look)
	{
		tissuestack::database::AtlasInfo * atlasInfo = nullptr;
		if (!look["atlas_association"].is_null())
		{
			// go query associated atlas info
			const std::string innerSql =
				"SELECT * FROM atlas_info WHERE id=" +
				std::to_string(look["atlas_association"].as<unsigned long long int>()) + ";";

			const pqxx::result innerResults =
					tissuestack::database::TissueStackPostgresConnector::instance()->executeNonTransactionalQuery(innerSql);

			if (innerResults.size() == 1)
			{
				for (pqxx::result::const_iterator atlas = innerResults.begin(); atlas != innerResults.end(); ++atlas)
				{
					atlasInfo = new tissuestack::database::AtlasInfo(
						atlas["id"].as<unsigned long long int>(),
						atlas["atlas_prefix"].as<std::string>(),
						atlas["atlas_description"].as<std::string>(),
						atlas["atlas_query_url"].is_null() ? "" :
							atlas["atlas_query_url"].as<std::string>());
					break;
				}
			}
		}

		// construct lookup label from db info
		ret = const_cast<tissuestack::imaging::TissueStackLabelLookup * >(
			tissuestack::imaging::TissueStackLabelLookup::fromDataBaseId(
				look["id"].as<unsigned long long int>(),
				look["filename"].as<std::string>(),
				look["content"].as<std::string>(),
				atlasInfo));

		break;
	}
	return ret;
}
ILandRecordShrPtr LandAccessorPostgresql::prepareResultGetRecord(
    pqxx::result const & a_result
) const
{
    if (a_result.size() > 0)
    {
        string login;
        string world_name;
        string land_name;
        int turns;
        bool granted;

        a_result[0]["login"].to(login);
        a_result[0]["world_name"].to(world_name);
        a_result[0]["land_name"].to(land_name);
        a_result[0]["turns"].to(turns);
        a_result[0]["granted"].to(granted);

        return ILandRecordShrPtr(new LandRecord(login, world_name, land_name, turns, granted));
    }
    else
    {
        return ILandRecordShrPtr();
    }
}
Example #6
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;
		}
	}
    std::vector< std::map<std::string, std::string> > PostgreAdapter::parseResponse(pqxx::result response_I)
    {
        std::vector< std::map<std::string, std::string> > result;
        std::map<std::string, std::string>* tmp;

        if (response_I.size() > 0) {
            for(auto it: response_I) {
                tmp = new std::map<std::string, std::string>();
                for(auto el: it) {
                    std::cout << el.name() << " = '" << el.c_str() << "'" << std::endl;
                    (*tmp)[el.name()] = el.c_str();
                }
                result.push_back( *tmp );
            }
        }

        return result;
    }
Example #8
0
File: zou.cpp Project: yarlB/EE
//ligne résultat : (nom_programme, programme, nom_zone)
void Zou::processAll(pqxx::result const& result) {
  std::unordered_set<char const*> zones_names_tmp;

  for(pqxx::result::size_type i=0 ; i!=result.size() ; ++i) {
    field_raw_t progname_raw = result[i][0].c_str(), program_raw = result[i][1].c_str(),
      zonename_raw = result[i][2].c_str();
    zonename_t zonename(zonename_raw);
    zones_names_tmp.insert(zonename_raw);
    progset_t hmm;
    if(m_zones.count(zonename) == 0)
      hmm = m_zones.insert(zonename, progset_t());
    else
      hmm = m_zones.find(zonename);
    processProgram(hmm, program_raw);
  }

  //envoi ordre de gelement des zones de m_zones pas dans zones_names_tmp;
  //les zones gelées disparaissent (et tous leurs objets) au bout d'un certain temps
}
Example #9
0
		void getAddress(float lat, float lon,std::string &address){

			bool placeIDExist(false);
			mapValue.clear();

			pqxx::nontransaction nType((*ptrConn));

	        for (int i=0; i < 10; ++i){

	        	sql="select place_id,parent_place_id,rank_search from placex WHERE ST_DWithin(ST_SetSRID(ST_Point("+std::to_string(lon)+","+std::to_string(lat)+"),4326), "
	   		         "geometry, "+std::to_string(radius)+") and rank_search != 28 and rank_search >= 26 and (name is not null or housenumber is not null) and"
	   		         " class not in ('waterway','railway','tunnel','bridge') and indexed_status = 0 and "
	   		         "(ST_GeometryType(geometry) not in ('ST_Polygon','ST_MultiPolygon') "
	   		         "OR ST_DWithin(ST_SetSRID(ST_Point("+std::to_string(lon)+","+std::to_string(lat)+"),4326), centroid, "+std::to_string(radius)+")) "
	   		         "ORDER BY ST_distance(ST_SetSRID(ST_Point("+std::to_string(lon)+","+std::to_string(lat)+"),4326), geometry) ASC limit 1";

	        	//std::cout << sql << std::endl;

	        	resultSet = nType.exec(sql);

				if (!resultSet.empty()) {
					for (pqxx::result::const_iterator c = resultSet.begin(); c != resultSet.end(); ++c){
						//cout << '\t' << c[0].as(string()) << '\t' << c[1].as(string()) <<'\t' << c[2].as(string()) <<endl;
						place_id = c[0].as(std::string());
					}
					placeIDExist=true;
					break;
				}

				radius*=2;

	        }// end of for loop

	        if(placeIDExist){

	        	resultSet = nType.exec("select name,class,type from get_addressdata(" + place_id + ") where isaddress order by rank_address asc");

	            if (!resultSet.empty()) {
	            	for (pqxx::result::const_iterator c = resultSet.begin(); c != resultSet.end(); ++c){
	            		parseLocation( c[0].as(std::string()), c[1].as(std::string()), c[2].as(std::string()));
	            	}
	            }

	        }

	        printAddress(address);

		} // end of func getAddress
Example #10
0
#include <pqxx/pqxx>
#include <pqxx/except.hxx>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
using std::cerr;
using std::endl;
using std::cout;
using std::list;
using std::string;
int get_new_killid(pqxx::work& T,std::set<string>& new_kills) {

	pqxx::result R( T.exec("SELECT test1.\"id\", analizer_kill.\"killID\"\
					 FROM test1 LEFT OUTER JOIN analizer_kill ON \
					analizer_kill.\"killID\" = test1.\"id\"\
					WHERE analizer_kill.\"killID\" is null") );
	for (pqxx::result::const_iterator c1 = R.begin(); c1 != R.end(); ++c1)
			{
			  // Dump tuple number and column 0 value to cout.  Read the value using
			  // as(), which converts the field to the same type as the default value
			  // you give it (or returns the default value if the field is null).
			  //cout << '\t' << pqxx::to_string(c1.num()) << '\t' << c1[0].as(std::string())<<
				//	  "\t"<<c1[1].as(std::string())<< endl;
			  new_kills.insert(c1[0].as(string()));
			}
	std::cout<<" founded "<<new_kills.size()<<" new entry"<<std::endl;
	return 0;
}