Exemplo n.º 1
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);
	}
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
int insertAll(T first, T last, mysqlpp::Query& q, bool ignore){
  bool empty = true;
  std::string ignore_cmd = ignore ? " IGNORE " : " ";
  if(first == last) return 0;
  for(T it = first; it != last; ++it){
    if(empty){
      q << "INSERT" << ignore_cmd << "INTO `" << it->table() << "` (" 
        << it->field_list() << ") VALUES (";
    }else{
      q << ",(";
    }
    q << it->value_list() << ")";
    empty = false;
  }
  q.execute();
  return q.insert_id();
}