Beispiel #1
0
void avlog_do_search(boost::asio::io_service & io_service,
	std::string c, std::string q, std::string date,
	boost::function<void (boost::system::error_code, pt::ptree)> handler,
	soci::session & db)
{
	pt::ptree outjson;
	std::string q_escaped;
	// 根据 channel_name , query string , date 像数据库查找
	AVLOG_DBG << " c = " << c << " q =  " << q << " date= " << date ;

	std::vector<std::string>	r_date(1000);
	std::vector<std::string>	r_channel(1000);
	std::vector<std::string>	r_nick(1000);
	std::vector<std::string>	r_message(1000);
	std::vector<std::string>	r_rowid(1000);

	avhttp::detail::unescape_path(q, q_escaped);

	boost::timer::cpu_timer cputimer;

	cputimer.start();

	db << "select date,channel,nick,message,rowid from avlog where channel=:c "
		"and message like \"%" << q_escaped << "%\" order  by strftime(`date`) DESC"
		, soci::into(r_date)
		, soci::into(r_channel)
		, soci::into(r_nick)
		, soci::into(r_message)
		, soci::into(r_rowid)
		, soci::use(c);

	pt::ptree results;
	// print out the result
	for (int i = 0; i < r_date.size() ; i ++)
	{
		pt::ptree onemsg;
		onemsg.put("date", r_date[i]);
		onemsg.put("channel", r_channel[i]);
		onemsg.put("nick", r_nick[i]);
		onemsg.put("channel", r_channel[i]);
		onemsg.put("message", r_message[i]);
		onemsg.put("id", r_rowid[i]);

		results.push_back(std::make_pair("", onemsg));
	}

	outjson.put("params.num_results", r_date.size());
	outjson.put_child("data", results);

	outjson.put("params.time_used", boost::timer::format(cputimer.elapsed(), 6, "%w"));

	io_service.post(
		boost::asio::detail::bind_handler(handler,
			boost::system::error_code(),
			outjson
		)
	);
};
Beispiel #2
0
Course* info_course(char *id_course){
	FILE *f_course;
	

	Course *course = (Course*) malloc (sizeof (Course));

	course->title = r_title(id_course, f_course);
	course->program =  r_program(id_course, f_course);
	course->date = r_date(id_course, f_course);
	course->comment = r_comment(id_course, f_course);


	return course;		
}