YAPOG  0.0.1
Yet Another Pokemon Online Game
PokemonInsertRequest.cpp
Go to the documentation of this file.
3 
6 
7 namespace yse
8 {
10  (const PokemonTable& pokemonTable)
11  : pokemonTable_ (pokemonTable)
12  , id_ ()
13  {
14  }
15 
17  {
18  }
19 
21  (yap::DatabaseManager& databaseManager)
22  {
23  yap::String query_string =
24  "INSERT INTO pokemon ("
25  "account_id, "
26  "pokemon_static_id, "
27  "pokemon_experience, "
28  "pokemon_hp, "
29  "pokemon_gender, "
30  "pokemon_nickname, "
31  "pokemon_shiny, "
32  "pokemon_loyalty, "
33  "pokemon_nature, "
34  "pokemon_trading_number, "
35  "pokemon_trader_account_id, "
36  "pokemon_box_number, "
37  "pokemon_box_index, "
38  "pokemon_catch_date, "
39  "pokemon_status) "
40  "VALUES ("
41  ":accountID, "
42  ":staticID, "
43  ":experience, "
44  ":hp, "
45  ":gender, "
46  ":nickname, "
47  ":shiny, "
48  ":loyalty, "
49  ":nature, "
50  ":tradingNumber, "
51  ":traderAccountID, "
52  ":boxNumber, "
53  ":boxIndex, "
54  "NOW (), "
55  ":status "
56  ")"
57  "RETURNING pokemon_id";
58 
59  yap::DatabaseStream query
60  (query_string, databaseManager.GetConnection ());
61 
62  try
63  {
64  query.Write (pokemonTable_.accountID_.GetValue ());
65  query.Write (pokemonTable_.staticID_);
66  query.Write (pokemonTable_.experience_);
67  query.Write (pokemonTable_.hp_);
68  query.Write (static_cast<yap::UInt8>(pokemonTable_.gender_));
69  query.Write (pokemonTable_.nickname_);
70  query.Write (pokemonTable_.shiny_);
71  query.Write (pokemonTable_.loyalty_);
72  query.Write (pokemonTable_.nature_);
73  query.Write (pokemonTable_.tradingNumber_);
74  query.Write (pokemonTable_.traderAccountID_);
75  query.Write (pokemonTable_.boxNumber_);
76  query.Write (pokemonTable_.boxIndex_);
77  query.Write (static_cast<yap::UInt8>(pokemonTable_.status_));
78 
79  id_ = yap::ID (query.ReadInt ());
80 
81  return true;
82  }
83  catch (const pgs::pg_excpt& e)
84  {
85  std::cerr << e.errmsg () << std::endl;
86  }
87  }
88 
90  {
91  return id_;
92  }
93 
94 } // namespace yse