show category creates additional rows for each song practiced in a session

practiced_songs
Matt Huntington 6 months ago
parent 29a6b36315
commit e77bce71da

@ -166,7 +166,11 @@ int main()
connect();
crow::json::wvalue entries;
ResultSet *res = stmt->executeQuery("call show_category("+to_string(category_id)+");");
//prep_stmt = con->prepareStatement("INSERT INTO practice_sessions (description, seconds, practice_category_id) VALUES (?, ?, ?)");
//ResultSet *res = stmt->executeQuery("call show_category("+to_string(category_id)+");");
prep_stmt = con->prepareStatement("SELECT practice_sessions.id, practice_sessions.description, seconds, songs.id AS song_id, songs.title, comments, created_at, practice_categories.name AS category, instruments.name AS instrument FROM practice_sessions JOIN practice_categories ON practice_category_id = practice_categories.id JOIN instruments ON instrument_id = instruments.id LEFT JOIN songs_practiced ON practice_sessions.id = songs_practiced.practice_session_id LEFT JOIN songs ON songs_practiced.song_id = songs.id WHERE practice_category_id = ? ORDER BY practice_sessions.id DESC;");
prep_stmt->setInt(1, category_id);
ResultSet *res = prep_stmt->executeQuery();
int i = 0;
res->afterLast();
@ -176,7 +180,6 @@ int main()
int seconds = res->getInt("seconds");
string comments = res->getString("comments");
string created_at = res->getString("created_at");
int category_id = res->getInt("category_id");
string category = res->getString("category");
string instrument = res->getString("instrument");
entries[i] = {
@ -185,7 +188,6 @@ int main()
{"seconds", seconds},
{"comments", comments},
{"created_at", created_at},
{"category_id", category_id},
{"category", category},
{"instrument", instrument}
};

Loading…
Cancel
Save