示例#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();
	}
}
示例#2
0
std::vector<Song> Song::getAllSongs_noBell() {
	Mysql db;

	MYSQL_RES* res = db.query("SELECT id FROM song WHERE id > 16");
	MYSQL_ROW row;

	std::vector<Song> rtr;

	while (row = db.next_res(res)) {
		Song s(db.stringInt(row[0]));
		rtr.push_back(s);
	}

	db.free_res(res);
	return rtr;
}