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);
ResultSet *res = prep_stmt->executeQuery();
int i = 0;
int i = -1;
int previous_session_id = 0;
int current_song_index;
while (res->next()) {
int id = res->getInt("id");
@ -184,25 +186,21 @@ int main()
string created_at = res->getString("created_at");
string category = res->getString("category");
string instrument = res->getString("instrument");
crow::json::wvalue songs;
int song_id = res->getInt("song_id");
string song_title = res->getString("title");
songs[0] = {
if(id != previous_session_id){
i++;
previous_session_id = id;
current_song_index = 0;
crow::json::wvalue songs = crow::json::wvalue::list();
if(song_id != 0){
songs[current_song_index] = {
{"id", song_id},
{"title", song_title}
};
//crow::json::wvalue currentSong;
//currentSong["id"] = res->getInt("song_id");
//currentSong["title"] = res->getString("title");
//crow::json::wvalue currentSong = {
//{"id", res->getInt("song_id")},
//{"title", res->getString("title")}
//};
//songs.push_back(std::move(currentSong));
}
entries[i] = {
{"id", id},
@ -214,9 +212,16 @@ int main()
{"instrument", instrument},
{"songs", songs}
};
i++;
current_song_index++;
} else {
entries[i]["songs"][current_song_index] = {
{"id", song_id},
{"title", song_title}
};
current_song_index++;
}
}
delete res;
return entries;
});

Loading…
Cancel
Save