Question: I ' m using the chinook database. For some reason, the error message for failing to connect always defaults to print out that it opened
Im using the chinook database. For some reason, the error message for failing to connect always defaults to print out that it opened successfully. Also, I think something is wrong with my sql statement because it sometimes prints double of some tracks and will also print some tracks that don't exist. Here is a description of the problem. Write a C program that opens a connection to the Chinook database chinook.db Download chinook.db If the connection doesn't open successfully print an error message Error in connection: unable to open database file" from the database and end the program. Print a success message when it opens successfully. Then use sqliteexec and a callback function which may require more than one callback function to print the albums in the database. For each album, there should be a track listing. Each album will appear in the results only once. After running the query close the database to prevent corrupting it Here is my code: Program name: jbtictactoe.cpp
Author: John Doe
Date last updated:
Purpose: Play the game of TicTacToe
#include
#include
#include "sqliteh
Callback function to print album details
int callbackvoid data int argc, char argv char azColName
Extract album details
std::cout "AlbumId: argv std::endl;
std::cout "Album Name: argv std::endl;
std::cout "Artist Name: argv std::endl;
Extract and print track listing
std::cout "Tracks:" std::endl;
std::cout argv std::endl;
std::cout std::endl;
return ;
int main
sqlitedb;
char zErrMsg nullptr;
int rc;
Open connection to the database
rc sqliteopenchinookdb &db;
if rc SQLITEOK
std::cerr "Error in connection: sqliteerrmsgdb std::endl;
sqliteclosedb;
return ;
else
std::cout "Database opened successfully" std::endl;
Query to retrieve albums and their tracks
const char sql "SELECT albums.AlbumId, albums.Title, artists.Name, groupconcattracksName,
FROM albums
INNER JOIN artists ON albums.ArtistId artists.ArtistId
INNER JOIN tracks ON albums.AlbumId tracks.AlbumId
GROUP BY albums.AlbumId";
Execute the query
rc sqliteexecdb sql callback, nullptr, &zErrMsg;
Close the database connection
sqliteclosedb;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
