#include <stdio.h>
#include <string.h>
#include "example_fcns.h"
#include "core04_structs.h"
#include "core04_cat.h"
const char *const description =
"Demonstrates associating rows in one table with a row in another table";
const char *artistName,
*artistCursor)
{
ARTIST artist_rec;
artist_rec.artistid = 0;
strncpy (artist_rec.name, artistName, sizeof (artist_rec.name));
hDB, TABLE_ARTIST, &artist_rec, sizeof (artist_rec), artistCursor);
print_error (rc);
return rc;
}
const char *albumTitle,
const char **trackList,
size_t listSize)
{
ALBUM album_rec;
artistCursor, COL_ARTIST_ARTISTID, &album_rec.artistid,
sizeof (album_rec.artistid), NULL);
print_error (rc);
strncpy (album_rec.title, albumTitle, sizeof (album_rec.title));
album_rec.albumid = 0;
hDB, TABLE_ALBUM, &album_rec, sizeof (album_rec), &cursor);
print_error (rc);
{
int ii;
TRACK track_rec;
cursor, COL_ALBUM_ALBUMID, &track_rec.albumid,
sizeof (track_rec.albumid), NULL);
print_error (rc);
for (ii = 0; ii < (int) listSize; ii++)
{
strncpy (track_rec.title, trackList[ii], sizeof (track_rec.title));
hDB, TABLE_TRACK, &track_rec, sizeof (track_rec), NULL);
print_error (rc);
}
}
if (cursor)
return rc;
}
{
printf ("\nList all artists and their albums/tracks\n");
print_error (rc);
{
print_error (rc);
{
{
artistCursor, COL_ARTIST_NAME, Artist, sizeof (Artist),
NULL);
print_error (rc);
{
printf ("\nArtist: %s\n", Artist);
artistCursor, REF_ALBUM_ARTISTID, &albumCursor);
print_error (rc);
{
{
albumCursor, COL_ALBUM_TITLE, Title,
sizeof (Title), NULL);
print_error (rc);
{
printf ("\n\tAlbum: %s\n", Title);
albumCursor, REF_TRACK_ALBUMID,
&trackCursor);
print_error (rc);
{
trackCursor);
rc =
{
TRACK, title)];
trackCursor, COL_TRACK_TITLE, Track,
sizeof (Track), NULL);
print_error (rc);
{
printf ("\t\t%s\n", Track);
}
}
}
}
}
}
}
}
{
}
else
{
print_error (rc);
}
}
}
return rc;
}
static const char *the_doors_tracks[] = {"Break on Through (To the Other Side)",
"Soul Kitchen",
"The Crystal Ship",
"Twentieth Century Fox",
"Alabama Song (Whisky Bar)",
"Light My Fire",
"Back Door Man",
"I Looked at You",
"End of the Night",
"Take It as It Comes",
"The End"};
static const char *strange_days_tracks[] = {"Strange Days",
"You're Lost Little Girl",
"Love Me Two Times",
"Unhappy Girl",
"Horse Latitudes",
"Moonlight Drive",
"People Are Strange",
"My Eyes Have Seen You",
"I Can't See Your Face in My Mind",
"When the Music's Over"};
static const char *waiting_tracks[] = {
"Hello, I Love You", "Love Street", "Not to Touch the Earth",
"Summer's Almost Gone", "Wintertime Love", "The Unknown Soldier",
"Spanish Caravan", "My Wild Love", "We Could Be So Good Together",
"Yes, the River Knows", "Five to One"};
static const char *the_rolling_stones_tracks[] = {
"Not Fade Away",
"Route 66",
"I Just Want to Make Love to You",
"Honest I Do",
"Now I've Got a Witness",
"Little by Little",
"I'm a King Bee",
"Carol",
"Tell Me",
"Can I Get a Witness",
"You Can Make It If You Try",
"Walking the Dog"};
static const char *out_of_our_heads_tracks[] = {
"She Said Yeah",
"Mercy, Mercy",
"Hitch Hike",
"That's How Strong My Love Is",
"Good Times",
"Gotta Get Away",
"Talkin' Bout You",
"Cry to Me",
"Oh, Baby (We Got a Good Thing Going)",
"Heart of Stone",
"The Under Assistant West Coast Promotion Man",
"I'm Free"};
static const char *beggars_banquet_tracks[] = {
"Sympathy for the Devil", "No Expectations", "Dear Doctor",
"Parachute Woman", "Jig-Saw Puzzle", "Street Fighting Man",
"Prodigal Son", "Stray Cat Blues", "Factory Girl",
"Salt of the Earth"};
static const char *tattoo_you_tracks[] = {"Start Me Up",
"Hang Fire",
"Slave",
"Little T&A",
"Black Limousine",
"Neighbours",
"Worried About You",
"Tops",
"Heaven"};
static const char *bleach_tracks[] = {
"Blew", "Floyd The Barber", "About a Girl", "School",
"Love Buzz", "Paper Cuts", "Negative Creep", "Scoff",
"Swap Meet", "Mr. Moustache", "Sifting"};
static const char *nevermind_tracks[] = {"Smells Like Teen Spirit",
"In Bloom",
"Come as You Are",
"Breed",
"Lithium",
"Polly",
"Territorial Pissings",
"Drain You",
"Lounge Act",
"Stay Away",
"On a Plain",
"Something in the Way",
"Endless, Nameless"};
static const char *in_utero_tracks[] = {
"Serve the Servants",
"Scentless Apprentice",
"Heart-Shaped Box",
"Rape Me",
"Frances Farmer Will Have Her Revenge on Seattle",
"Dumb",
"Very Ape",
"Milk It",
"Pennyroyal Tea",
"Radio Friendly Unit Shifter",
"tourette's",
"All Apologies"};
#define RLEN(x) (sizeof (x) / sizeof (x[0]))
{
print_error (rc);
{
insertArtist (hDB, "The Doors", &artistCursor);
insertAlbum (
hDB, artistCursor, "The Doors", the_doors_tracks,
RLEN (the_doors_tracks));
insertAlbum (
hDB, artistCursor, "Strange Days", strange_days_tracks,
RLEN (strange_days_tracks));
insertAlbum (
hDB, artistCursor, "Waiting for the Sun", waiting_tracks,
RLEN (waiting_tracks));
else
}
print_error (rc);
{
insertArtist (hDB, "The Rolling Stones", &artistCursor);
insertAlbum (
hDB, artistCursor, "The Rolling Stones", the_rolling_stones_tracks,
RLEN (the_rolling_stones_tracks));
insertAlbum (
hDB, artistCursor, "Out of our Heads", out_of_our_heads_tracks,
RLEN (out_of_our_heads_tracks));
insertAlbum (
hDB, artistCursor, "Beggars Banquest", beggars_banquet_tracks,
RLEN (beggars_banquet_tracks));
insertAlbum (
hDB, artistCursor, "Tattoo You", tattoo_you_tracks,
RLEN (tattoo_you_tracks));
else
}
print_error (rc);
{
insertArtist (hDB, "Nirvana", &artistCursor);
insertAlbum (
hDB, artistCursor, "Bleach", bleach_tracks, RLEN (bleach_tracks));
insertAlbum (
hDB, artistCursor, "Nevermind", nevermind_tracks,
RLEN (nevermind_tracks));
insertAlbum (
hDB, artistCursor, "In Utero", in_utero_tracks,
RLEN (in_utero_tracks));
else
}
return rc;
}
int main_core04 (int argc, const char *const *argv)
{
print_error (rc);
{
rc = exampleOpenEmptyDatabase (&hTFS, &hDB, "core04", core04_cat);
{
rc = insertAllArtists (hDB);
{
rc = readAllAlbums (hDB);
}
exampleCleanup (hTFS, hDB);
}
}
return (int) rc;
}