[REBOL] Re: Multiple Keys
From: louisaturk:eudoramail at: 14-Jul-2001 0:02
Hi Ryan and Volker and other Rebols,
At 05:23 PM 7/13/2001 -0700, Ryan wrote:
>howabout somthing like...
>
>forskip database 2 [
> if not all [in database/1 'code in database/1 'chknum] [
> ; do something about it
> ]
>]
>database: head database
I still get an error message:
** Script Error: in expected object argument of type: object
** Where: forskip
** Near: if not all [in database/1 'code in database/1 'chknum] [
insert-data code chknum date amount special
]
>>
I have probably not made clear how the code is being used. Here is a
section of code to hopefully make the context clear:
if choice = #"7" [
print cls
print "^/Import Records From a CSV File.^/"
csv: ask "Name of CSV File to Read From: "
either not csv = "" [
csv-file: to-file csv
data: read/lines csv-file
foreach line data [
foreach [name state chknum date amount special code] parse
line "," [
code: to-string code
chknum: to-string chknum
; Convert to rebol style date
date: parse date "/"
month: date/1
day: date/2
yr: date/3
date: rejoin [day "-" month "-20" yr]
date: to-date date
amount: to-money amount
special: to-money special
;print [code chknum date amount special] ; remove
after debug
;******************** Begin Problem
**************************
;*** Need to check fields code and chknum to prevent
;*** duplicate records. The line below with the <==<<
remark works
;*** fine by itself importing data without duplicate
checking.
;*** It doesn't seem to me that forskip should be needed.
;*************************************************************
forskip database 2 [
if not all [in database/1 'code in database/1
'chknum] [
insert-data code chknum date amount
special ; <==<<
]
]
database: head database
;********************* End Problem
***************************
save-data
] ; end foreach
] ; end foreach line data
prin "^/Number of records in database = "
print length? database
prin "^/The Data Has Been Appended to the Database. Continue?
kbhit
][prin
^/You forgot to enter a file name. Continue? " kbhit
] ; end either not csv.
;close %db-file
] ; end if choice 7.
Here's some sample data from the csv file being imported into the object
database:
Parkview
,"Tx",4014,"1/12/01",25.00,0.00,"pct"
Parkview
,"Tx",4097,"2/2/01",25.00,0.00,"pct"
Parkview
,"Tx",4069,"3/9/01",25.00,0.00,"pct"
Parkview
,"Tx",4127,"4/12/01",25.00,0.00,"pct"
Parkview
,"Tx",4167,"5/4/01",25.00,0.00,"rct"
Parkview
,"Tx",4197,"6/8/01",25.00,0.00,"pct"
Penrose
,"Co",1656,"1/5/01",100.00,0.00,"ppc"
Penrose
,"Co",1674,"2/2/01",40.00,0.00,"ppc"
Penrose
,"Co",1692,"3/2/01","0","130.00","ppc"
Penrose
,"Co",1693,"3/2/01",40.00,0.00,"ppc"
Penrose
,"Co",1738,"5/4/01",40.00,0.00,"ppc"
Penrose
,"Co",1757,"6/8/01",40.00,0.00,"ppc"
Peoples
,"Oh",654,"1/5/01",50.00,0.00,"pco"
Peoples
,"Oh",658,"2/9/01",50.00,0.00,"pco"
Peoples
,"Oh",662,"3/2/01",50.00,0.00,"pco"
Peoples
,"Oh",666,"4/5/01",50.00,0.00,"pco"
Peoples
,"Oh",671,"5/4/01",50.00,0.00,"pco"
Peoples
,"Oh",675,"6/1/01",50.00,0.00,"pco"
Plack Road
,"Ar",7713,"1/12/01",50.00,0.00,"pna"
Plack Road
,"Ar",7759,"2/9/01",50.00,0.00,"pna"
Plack Road
,"Ar",7807,"3/9/01",50.00,0.00,"pna"
Plack Road
,"Ar",7850,"4/5/01",50.00,0.00,"pna"
Plack Road
,"Ar",7907,"5/11/01",50.00,0.00,"pna"
Plack Road
,"Ar",7962,"6/8/01",50.00,0.00,"pna"
Pleasant Valley
,"Tx",3504,"1/12/01",35.00,0.00,"pmt"
Pleasant Valley
,"Tx",3527,"2/16/01",35.00,0.00,"pmt"
Pleasant Valley
,"Tx",3556,"3/16/01",35.00,0.00,"pmt"
Pleasant Valley
,"Tx",3592,"4/20/01",35.00,0.00,"pmt"
Pleasant Valley
,"Tx",3623,"5/18/01",35.00,0.00,"pmt"
Pleasant Valley
,"Tx",3649,"6/22/01",35.00,0.00,"pmt"
Reily
,"Oh",2596,"1/26/01",50.00,0.00,"roo"
Reily
,"Oh",2613,"2/23/01",50.00,0.00,"roo"
Reily
,"Oh",2628,"3/29/01",50.00,0.00,"roo"
Reily
,"Oh",2642,"4/27/01",50.00,0.00,"roo"
I know how to check for duplicates on one key, but the problem is that I
need to check two keys in each record.
Thanks for your help.
Louis