Multiple Keys
[1/6] from: louisaturk:eudoramail at: 13-Jul-2001 15:21
Hi Rebol Experts,
I need to use two keys in order to search for unique records in a database
(to make sure I don't insert duplicates). The following line does not work:
if all [not find database code not find database chknum] [
insert-data code chknum date amount special
]
The problem is that the two finds are finding different records. I need
for both finds to check each record in the database simultaneously for the
two keys.
It seems to me that this should have a real simple answer, but I was up too
late last night trying to finish this program, and now my brain doesn't
want to function. :>)
Do I perhaps need a new function here?
Louis
[2/6] from: ryanc:iesco-dms at: 13-Jul-2001 14:19
What do you mean by "database?"
database: ["col1" "col2" "col3" "xxx1" "xxx2" "xxx3"]
or
database: [["col1" "col2" "col3"] ["xxx1" "xxx2" "xxx3"]]
or something else?
Anyways is this what you want?
if all [not db-mark: find database code not find db-mark chknum] [
insert-data code chknum date amount special
]
--Ryan
Dr. Louis A. Turk
wrote:
> Hi Rebol Experts,
> I need to use two keys in order to search for unique records in a database
<<quoted lines omitted: 14>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
[3/6] from: agem::crosswinds::net at: 14-Jul-2001 0:17
RE: [REBOL] Multiple Keys
[louisaturk--eudoramail--com] wrote:
> Hi Rebol Experts,
> I need to use two keys in order to search for unique records in a database
<<quoted lines omitted: 5>>
> for both finds to check each record in the database simultaneously for the
> two keys.
find record for key 1 and check if it has key 2
i expect you have
code chknum date amount special
code chknum date amount special
...
then
here: find database code would position 'here :
code chknum date amount special
^^^^
thus chknum is [second here] and
if all[(found? here) (chknum = second here)] [wrong-record]
[4/6] from: louisaturk:eudoramail at: 13-Jul-2001 18:17
Ryan,
Many thanks for replying.
At 02:19 PM 7/13/2001 -0700, you wrote:
>What do you mean by "database?"
It is an object database, as follows:
>> database
== ["bbi"
make object! [
code: "bbi"
chknum: "298"
date: 26-Jan-2001
amount: $40.00
sp...
>>
>Anyways is this what you want?
>
>if all [not db-mark: find database code not find db-mark chknum] [
> insert-data code chknum date amount special
>]
>
>--Ryan
Your code produced the following error message:
** Script Error: find expected series argument of type: series port bitset
** Where: forever
** Near: if all [not db-mark: find database code not find db-mark chknum] [
insert-data code chknum date amount special
]
What now?
Louis
[5/6] from: ryanc:iesco-dms at: 13-Jul-2001 17:23
Dr. Louis A. Turk
wrote:
<snip>
> Your code produced the following error message:
<<quoted lines omitted: 3>>
> insert-data code chknum date amount special
> ]
logic error on my part.
howabout somthing like...
forskip database 2 [
if not all [in database/1 'code in database/1 'chknum] [
; do something about it
]
]
database: head database
> What now?
>
> Louis
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
[6/6] 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 [
<<quoted lines omitted: 3>>
>]
>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
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted