Well, Sharriff, it depends on what you want to select...
Using cut-n-paste from your original note:
>> foo: [
[ admin [
[ name "Sharriff Aina"
[ password "gong"
[ email [EMAIL PROTECTED]
[ dept "Administration"
[ view "yes"
[ ]
[
[ sharriff [
[ name "Sharriff Aina"
[ password "jungle"
[ email [EMAIL PROTECTED]
[ dept "Administration"
[ view "yes"
[ ]
[ ]
== [
admin [
name "Sharriff Aina"
password "gong"
email [EMAIL PROTECTED]
dept "Admini...
>> select foo 'admin
== [
name "Sharriff Aina"
password "gong"
email [EMAIL PROTECTED]
dept "Administration"
view "yes"
]
>> select foo "admin"
== none
>> select foo admin
** Script Error: admin has no value.
** Where: select foo admin
Note that all of your "key" values are of type word! and NOT of
type string! which means you must use a literal word or an
expression that evaluates to a value of type word! in order to
get a match.
OTOH, if you want to search by name, you can either write
a function to search the nested blocks, as in
>> searchname: func [who [string!] /local k v] [
[ foreach [k v] foo [
[ if v/name = who [return v]
[ ]
[ ]
>> searchname "Sharriff Aina"
== [
name "Sharriff Aina"
password "gong"
email [EMAIL PROTECTED]
dept "Administration"
view "yes"
]
OTOH, (wait a minute... I don't have three hands! Can somebody
give me a hand? ;-) if you're going to do lots of searching in
that data structure, it's worthwhile to pre-build another data
structure that can serve as an index or cross-reference to the
original one:
>> buildxref: func [/local xref k v] [
[ xref: copy []
[ foreach [k v] foo [
[ append xref v/name
[ append/only xref v
[ ]
[ xref
[ ]
>> fum: buildxref
== ["Sharriff Aina" [
name "Sharriff Aina"
password "gong"
email [EMAIL PROTECTED]
dept "A...
>> select fum "Sharriff Aina"
== [
name "Sharriff Aina"
password "gong"
email [EMAIL PROTECTED]
dept "Administration"
view "yes"
]
Modifying either of the above to return both the key and value from
the ORIGINAL block (e.g., getting back BOTH the key 'admin and the
block of associated data), is a minor tweak that is left to the
reader.
(That's academicspeak for
"I don't have time to type it right now."
but feel free to ask if you want any followup! ;-)
-jn-
[EMAIL PROTECTED] wrote:
>
> Just when I thought my problems were solved..sorry to bother you guys again
>
> [
> admin [
> name "Sharriff Aina"
> password "gong"
> email [EMAIL PROTECTED]
> dept "Administration"
> view "yes"
> ]
>
> sharriff [
> name "Sharriff Aina"
> password "jungle"
> email [EMAIL PROTECTED]
> dept "Administration"
> view "yes"
> ]
> ]
>
> a "SELECT" or "FIND" always results in a " NONE" how do I iterate? the path
> "test-path: admin/name" for example works. I would to be able to search the
> database given the first name (login name) of the user with a function...
>
> Thanks and much appreciation for your help
> I�ll get the hang of this one day, this is my second REBOL week!
>
> Sharriff Aina
> med.iq information & quality in healthcare AG