put all songs for a session into an array

practiced_songs
Matt Huntington 6 months ago
parent 34b1fabe12
commit 06281b2654

@ -174,7 +174,9 @@ int main()
prep_stmt->setInt(1, category_id); prep_stmt->setInt(1, category_id);
ResultSet *res = prep_stmt->executeQuery(); ResultSet *res = prep_stmt->executeQuery();
int i = 0; int i = -1;
int previous_session_id = 0;
int current_song_index;
while (res->next()) { while (res->next()) {
int id = res->getInt("id"); int id = res->getInt("id");
@ -184,39 +186,42 @@ int main()
string created_at = res->getString("created_at"); string created_at = res->getString("created_at");
string category = res->getString("category"); string category = res->getString("category");
string instrument = res->getString("instrument"); string instrument = res->getString("instrument");
crow::json::wvalue songs;
int song_id = res->getInt("song_id"); int song_id = res->getInt("song_id");
string song_title = res->getString("title"); string song_title = res->getString("title");
songs[0] = { if(id != previous_session_id){
{"id", song_id}, i++;
{"title", song_title}
}; previous_session_id = id;
current_song_index = 0;
//crow::json::wvalue currentSong; crow::json::wvalue songs = crow::json::wvalue::list();
//currentSong["id"] = res->getInt("song_id"); if(song_id != 0){
//currentSong["title"] = res->getString("title"); songs[current_song_index] = {
{"id", song_id},
//crow::json::wvalue currentSong = { {"title", song_title}
//{"id", res->getInt("song_id")}, };
//{"title", res->getString("title")} }
//};
//songs.push_back(std::move(currentSong)); entries[i] = {
{"id", id},
entries[i] = { {"description", description},
{"id", id}, {"seconds", seconds},
{"description", description}, {"comments", comments},
{"seconds", seconds}, {"created_at", created_at},
{"comments", comments}, {"category", category},
{"created_at", created_at}, {"instrument", instrument},
{"category", category}, {"songs", songs}
{"instrument", instrument}, };
{"songs", songs} current_song_index++;
}; } else {
i++; entries[i]["songs"][current_song_index] = {
} {"id", song_id},
{"title", song_title}
};
current_song_index++;
}
}
delete res; delete res;
return entries; return entries;
}); });

Loading…
Cancel
Save