hi, I have an app which requires a lot of data access and modification. I'm going with the flat-file DB model, but was wondering which was the best way to structure my data. Maybe there is only one way (see below), or maybe you could suggest something better? Oh, and I have a problem with my code below. It looks like it stores correctly in the block 'db', but then writing to the file, I can't get it to keep its block structure -- which I need to start playing with it later on. Thanks Code: rebol[ file: %make-club-data2.r ] club-id-record: 0 add-club-id-record: func ["Increment the ID."] [ club-id-record: club-id-record + 1 ] teams: [ "Liverpool" "Manchester United" "Everton" "Tranmere" "Bolton" "etc..." ] club-data: [ add-club-id-record teams/(club-id-record) none none none none ] db-file: %clubs-db.txt db: [] enter-db-new-club: func ["Writes club data to DB."] [ append db to-block mold/all reduce club-data ] loop length? teams [enter-db-new-club] write %clubs-db.txt to-block mold/all db
Change the write to: Code: save %clubs-db.txt db and it should work. To reload the data: Code: db: load %clubs-db.txt
I think it's safer to save in a serialized format so use save/all instead of save. Also, I think it's safer to store your records in a block .. like this Code: enter-db-new-club: func ["Writes club data to DB."] [ append/only db copy reduce club-data ]
Thanks for the tips Could you tell me the difference between SAVE and WRITE? Apart from the obvious refinements, I think they fundamentally do the same thing. But to me, SAVE just seemed to magically do what WRITE couldn't. How come it worked? Code: >> ? save DESCRIPTION: Saves a value or a block to a file or url. >> ? write DESCRIPTION: Writes to a file, url, or port-spec (block or object).