Re: Rock Band Clone - Update

new topic     » goto parent     » topic index » view thread      » older message » newer message
Lone_EverGreen_Ranger said...

I appericate the help, but I am still having trouble getting the database created. I've tried multiple things. Would it be possible that anyone could use my code and apply it, so that it is done correctly? I'd greatly appericate it. I did this before, but its been so long, I've forget how to do it.

This might help...

include std/eds.e 
 
sequence SongDB = "songs.edb" 
sequence SongTable = "song" 
atom song_id 
sequence song_data 
integer idkey 
 
if db_select(SongDB) != DB_OK then  
    if db_open(SongDB, DB_LOCK_NO) != DB_OK then  
        if db_create(SongDB, DB_LOCK_NO) != DB_OK then  
            puts(1,"Database could not be created\n")  
            abort(1)  
        end if  
    end if  
	db_select(SongDB) -- Select the database after open/create 
      
end if  
 
  
if db_select_table(SongTable) != DB_OK then  
    if db_create_table(SongTable) != DB_OK then  
          
        puts(1,"Could not create table\n")  
        abort(1)  
          
    end if  
	db_select_table(SongTable) -- Select the table after create. 
      
end if  
 
-- example data  
song_data = {"I Wanna Hold Your Hand", "The Beatles", {1963,10,17}, {"rock","pop"},"Lennon/McCartney"} 
-- Generate a unique ID for this song. 
song_id = hash(song_data[1..3], SongTable) 
 
idkey = db_find_key( song_id ) 
if idkey < 0 then 
	if db_insert(song_id,{song_data}) != DB_OK then  
      
    	puts(1,"Could not insert song table\n")  
    	abort(1)  
    else 
       	printf(1, " Song ID: %d added.\n", song_id) 
    end if 
else 
	song_data = db_record_data(idkey) 
   	printf(1, " Song ID: %d\n", song_id) 
   	if length(song_data) = 1 then 
   		song_data = song_data[1] 
	   	printf(1, "   Title: %s\n", {song_data[1]}) 
	   	printf(1, "  Artist: %s\n", {song_data[2]}) 
	   	printf(1, "Recorded: %02dd%02dm%4d\n", {song_data[3][3],song_data[3][2],song_data[3][1]}) 
	   	printf(1, "Composer: %s\n", {song_data[5]}) 
	   	if length(song_data[4]) > 0 then 
	   		puts(1, "   Genre: ") 
	   		for i = 1 to length(song_data[4]) do 
	   			printf(1, "%s ", {song_data[4][i]}) 
	   		end for 
	   		puts(1, "\n") 
	   	end if 
	else 
		puts(1, "data no longer exists\n") 
	end if   	 
end if 
 
db_close()  
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu