예제 #1
0
std::vector<int> insertAndIDByName(T first, T last, mysqlpp::Query& q){
  bool empty = true;
  insertAll(first, last, q, true);
  if(first == last) return std::vector<int>();
  for(T it = first; it != last; ++it){
    if(empty){
      q << "SELECT ID FROM `" << it->table() << "` WHERE (" << it->field_list()
        << ") IN ((";
    }else{
      q << ",(";
    }
    q << it->value_list() << ")";
    empty = false;
  }
  empty = true;
  for(T it = first; it != last; ++it){
    if(empty){
      q << ") ORDER BY FIELD(name, ";
    }else{
      q << ",";
    }
    q << "'" << it->name << "'";
    empty = false;
  }
  q << ")";
  mysqlpp::StoreQueryResult res = q.store();
  std::vector<int> retval;
  for(mysqlpp::StoreQueryResult::const_iterator it = res.begin();
      it != res.end(); ++it){
    retval.push_back((*it)[0]);
  }
  return retval;
}
예제 #2
0
void
AsyncDBCreateGame::HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb)
{
	query.reset();
	query
			<< "SELECT LAST_INSERT_ID()";
	mysqlpp::StoreQueryResult tmpResult = query.store();
	DB_id insertId = tmpResult[0][0];
	if (!tmpResult || tmpResult.num_rows() != 1 || insertId == 0) {
		service.post(boost::bind(&ServerDBCallback::CreateGameFailed, &cb, GetId()));
	} else {
		service.post(boost::bind(&ServerDBCallback::CreateGameSuccess, &cb, GetId()));
		idManager.AddGameId(GetId(), insertId);
	}
}