Example #1
0
void Config::_loadFromDB()
{
	Mysql sql;
	if (!connectDb(sql)) {
		printf("Cannot connect to db, check db parameters\n");
		throw std::exception();
	}
	enum EServerFlds
	{
		FLD_IP,
		FLD_PORT,
		FLD_STATUS
	};
	auto res = sql.query(sql.createQuery() << "SELECT ip, port, status FROM storage WHERE id=" << ESC << _serverID);
	if (!res || !res->next())	{
		printf("Cannot get information about %u storage\n", _serverID);
		throw std::exception();
	}
	_listenIp = res->get<decltype(_listenIp)>(FLD_IP);
	_port = res->get<decltype(_port)>(FLD_PORT);
	_storageStatus = res->get<decltype(_storageStatus)>(FLD_STATUS);
	if (!(_storageStatus & ST_STORAGE_ACTIVE)) {
		printf("Cannot load an inactive storage %u\n", _serverID);
		throw std::exception();
	}
}