settings::settings() // default values : verbosity_(0), port_ (DB_PORT ), server_ (DB_SERVER ), user_ (DB_USER ), password_(DB_PASSWORD), dataBase_(DB_ID ), log_ (LOGPATH ) { // null pointer, safe ? dictionary_ = std::shared_ptr<FIX::DataDictionary>( new FIX::DataDictionary(DICT)); connect_ = mysql_init(NULL); // initialize a null connection if (!connect_) // fails to initialize mySQL throw std::exception("mySQL initialization failed"); connect_ = mysql_real_connect( // open a new connection to the database connect_, server().c_str(), user().c_str(), password().c_str(), dataBase().c_str(), port(), NULL, 0); if (!connect_) // fails to initialize mySQL throw std::exception("unable to reach mySQL database"); }
void settings::updateConnection() { // need to lock guard all the components boost::lock_guard<boost::mutex> guard(connectionMutex_); if (connect_) { // need to delete the previous connection mysql_close(connect_); // close the previous connection connect_ = mysql_init(NULL); // reset the MYSQL handle connect_ = mysql_real_connect( // open a new connection connect_, server().c_str(), user().c_str(), password().c_str(), dataBase().c_str(), port(), NULL, 0); } if (!connect_) // check throw std::exception("unable to reach mySQL database"); }
settings::settings() // default values : verbosity_(0), port_ (PORT ), server_ (SERVER ), user_ (USER ), password_(PASSWORD), dataBase_(DATABASE), log_ (LOGPATH ), ibPort_ (IBPORT ) { connect_ = mysql_init(NULL); // initialize null connection if (!connect_) // fails to initialize mySQL throw std::exception("mySQL initialization failed"); connect_ = mysql_real_connect( // open a new connection connect_, server().c_str(), user().c_str(), password().c_str(), dataBase().c_str(), port(), NULL, 0); if (!connect_) // fails to initialize mySQL throw std::exception("unable to reach mySQL database"); }
void readDataBase(string path){ map = new Graph<Intersection>(); ifstream dataBase(path.c_str()); //**pode variar string line; string args[10]; //0-id 1-nome 2-source 3-target 4-km 5-kmh 6-x1 7-y1 8-x2 9-y2 while(getline(dataBase,line)){ stringstream linestream(line); string value; args->clear(); int i=0; while(getline(linestream, value, ';')){ args[i]=value; i++; } Intersection source(atoi(args[2].c_str()), atof(args[6].c_str()), atof(args[7].c_str())); Intersection target(atoi(args[3].c_str()), atof(args[8].c_str()), atof(args[9].c_str())); if(atof(args[6].c_str()) > longitudeMin && atof(args[6].c_str()) < longitudeMax && atof(args[7].c_str()) > latitudeMin && atof(args[7].c_str() ) < latitudeMax ) { if(atof(args[8].c_str()) > longitudeMin && atof(args[8].c_str()) < longitudeMax && atof(args[9].c_str()) > latitudeMin && atof(args[9].c_str() ) < latitudeMax ) { map->addVertex(source); map->addVertex(target); map->addEdge(source, target, args[1], atof(args[4].c_str()), atof(args[5].c_str())); } } } cout << "Nodes: " << map->getNumVertex() << endl; }