Anton, Thanks. Little by little you are helping me understand how things work. Thanks for your time.
Louis At 02:53 PM 4/15/2002 +1000, you wrote: >First of all, I have never bothered to use >hash before, so perhaps I will miss some >hash specific details. > >As far as I know, hash!s are very similar to blocks. >That means you can put in any number of any >datatype. > >There is, due to the key, duplication of data in >the database. The code appears before each >object and within each object. I would try to >eliminate one of them. >I would simplify your hash to a series of >objects only (with the keys in the objects.) > >However, that may well not be very speedy. > >So you may decide to have two keys then an object, >or store all your keys and data in the objects. >You will need to modify your functions either way. > >With your two key example, this line will not work: > > all [find database code find database chknum] > >It would find code somewhere, then chknum somewhere else, >but who says they are together? Nobody. ;) >Use this instead: > > find/skip database reduce [key1 key2] 3 > >The skip refinement treats the series as records >of fixed number of objects, which is 3 in this case >(2 keys and 1 object). > >Anton. > > > From studying what both of you have said, I think that the root problem > > may be that I have a basic design flaw in my database. This is (I think) > > what has confused me, and also is perhaps what has made it difficult for > > you to understand my problem. I think I only have one key but need two > > keys. (Or maybe I don't need any keys at all! Is only one key > > per record > > allowed?) > > > > Here are the first few records from the database: > > > > >> probe database > > make hash! ["bbi" > > make object! [ > > code: "bbi" > > chknum: "298" > > date: 26-Jan-2001 > > amount: $40.00 > > special: $0.00 > > ] "bbi" > > make object! [ > > code: "bbi" > > chknum: "315" > > date: 9-Feb-2001 > > amount: $40.00 > > special: $0.00 > > ] "boo" > > make object! [ > > code: "boo" > > chknum: "9898" > > date: 19-Jan-2001 > > amount: $100.00 > > special: $0.00 > > ] "boo" > > make object! [ > > code: "boo" > > chknum: "" > > date: 20-Apr-2001 > > amount: $100.00 > > special: $0.00 > > ] "bho" > > make object! [ > > code: "bho" > > chknum: "5259" > > date: 27-Jul-2001 > > amount: $100.00 > > special: $0.00 > > > > What I am wanting to do is to make sure that the record is not already in > > the database before I insert it. In other words, no duplicate _records_ > > are allowed. Note, however, that although the records are all > > unique, the > > code data is not necessarily unique, nor is the chknum data. There may be > > many records with the same code, and also many records with the same > > chknum. Only the code / chknum combination is unique. > > > > So, do I perhaps need the records to look like this?: > > > > ] "bho" "5259" ; <===<<< TWO KEYS. > > make object! [ > > code: "bho" > > chknum: "5259" > > date: 27-Jul-2001 > > amount: $100.00 > > special: $0.00 > > > > Would not this line then return none if the unique record does not exist, > > and return the chknum otherswise?: > > > > all [find database code find database chknum] > > > > Am I correct about all this? If so, won't the following > > functions have to > > be rewritten?: > > > > load-data: has [data] [ > > if exists? db-file [ > > data: reduce load/all db-file > > clear database > > if data [ > > foreach item data [ > > item: make record item > > repend database [item/code item] ;item/key_field item > > ] > > ] > > database: make hash! database > > ] > > > > ] > > > > > > update-key-data: func [code-old code-new /local record] [ > > record: find database code-old > > if none? record [alert reform ["Missing record:" code-old] exit] > > insert clear first record code-new > > ] > > > > > > save-data: has [data] [ > > data: copy [] > > foreach [key obj] database [ > > append/only data obj 5 ; number of fields in each record > > ] > > save db-file data > > ] > > > > > > > > find-data: func [code] [select database code] > > > > > > remove-data: func [code] [remove/part find database code 2] > > > > > > insert-data: func [code' chknum' date' amount' special'] [ > > repend database [ > > code' > > make record [ > > code: code' > > chknum: chknum' > > date: date' > > amount: amount' > > special: special' > > ] > > ] > > ] > > > > These are the functions that Carl wrote for me several years ago for a > > database that only had one key. Thanks again Carl! They have served me > > well in several databases. This is my first need for two keys. > > > > Thanks again for your help. > > > > Louis > >-- >To unsubscribe from this list, please send an email to >[EMAIL PROTECTED] with "unsubscribe" in the >subject, without the quotes. -- To unsubscribe from this list, please send an email to [EMAIL PROTECTED] with "unsubscribe" in the subject, without the quotes.
