7 Replies Latest reply on Jul 11, 2006 12:23 PM by dbohea

    Returning values from nested property lists

    dbohea
      Hi.

      I'm trying to build a basic database system that stores user profiles (just a basic username & password for each user).

      I'm using a nested list like this:

      gDatabase = [[#user: "bholly", #Password: "buddy"], [#user: "mpatton", #Password: "mike"] ]

      I've been looking at things like getaProp , getPos and getOne in order to try and find a way to search my database for a specific username but I keep getting error messages saying that the handler is expecting a list. For example:

      put getaProp (gDatabase, #user) -- this will generate the error message

      I think the problem lies in the fact that I am not addressing the nested property list correctly (I'm still trying to address it as though it were a standard, un-nested property list).

      Once I've conquered this - all I have to do is come up with a way to then return the #password value that immediately follows the previously rerturned username (and then perfrom all the checks against what the user actually entered etc).

      Can anybody give me some tips on getting values out of nested property lists?

      Thanks.
        • 1. Re: Returning values from nested property lists
          Level 7
          Using your structure, you'd have to search for a list in your main list. So
          you'd assemble a user and password, create the prop list and use getOne ()
          to identify it's position (0 means not found)

          Otherwise, you'd have to loop through the list and that would be slow.

          I'd suggest creating a property out of each user name and pairing that with
          the password

          [#user1: "bholly", #user2: "mpatton"] but of course you'd be stuck when a
          duplicate user was to be entered.

          So, to suggest a solution using your structure...

          on FindUser userName
          returnVar = ""
          cnt = gDatabase.count
          repeat with x = 1 to cnt
          nextValue = gDatabase [x][1]
          if nextValue = userName then
          returnVar = gDatabase [x][2]
          end if
          end repeat
          return returnVar
          end

          call it using:

          passwrd = FindUser ("bholly")

          --
          Craig Wollman
          Word of Mouth Productions

          phone 212 928 9581
          fax 212 928 9582
          159-00 Riverside Drive West #5H-70
          NY, NY 10032
          www.wordofmouthpros.com


          "dbohea" <webforumsuser@macromedia.com> wrote in message
          news:e8uakk$3gu$1@forums.macromedia.com...
          > Hi.
          >
          > I'm trying to build a basic database system that stores user profiles
          > (just a
          > basic username & password for each user).
          >
          > I'm using a nested list like this:
          >
          > gDatabase = [[#user: "bholly", #Password: "buddy"], [#user: "mpatton",
          > #Password: "mike"] ]
          >
          > I've been looking at things like getaProp , getPos and getOne in order to
          > try
          > and find a way search my database for a specific username but I keep
          > getting
          > error messages saying that the handler is expecting a list. For example:
          >
          > put getaProp (gDatabase, #user)
          >
          > I think the problem lies in the fact that I am not addressing the nested
          > nature of the property list correctly (I'm still trying to address it as
          > though
          > it were a standard, un-nested property list).
          >
          > Once I've conquered this - all I have to do is come up with a way to then
          > return the #password value that immediately follows the previously
          > rerturned
          > username (and then perfrom all the checks against what the user actually
          > entered).
          >
          > Can anybody give me some tips on getting values out of nested property
          > lists?
          >
          > Thanks.
          >


          • 2. Re: Returning values from nested property lists
            Level 7
            I found a flaw in my code. It will always overwrite found users and only
            return the last user's password in the list whose username matches the
            parameter used to call the function.

            So here is my modification:

            on FindUser userName
            returnList = []
            cnt = gDatabase.count
            repeat with x = 1 to cnt
            nextValue = gDatabase [x][1]
            if nextValue = userName then
            returnList.add (gDatabase [x][2])
            end if
            end repeat
            return returnList
            end

            It will return a list of passwords associated with all usernames that match
            the one sent to the function. If you don't anticipate duplicate usernames
            then the returned list will always return either and empy list or one
            password.
            --
            Craig Wollman
            Word of Mouth Productions

            phone 212 928 9581
            fax 212 928 9582
            159-00 Riverside Drive West #5H-70
            NY, NY 10032
            www.wordofmouthpros.com


            "Word of Mouth Productions" <lingoboy@spamershaveforcedmetofakethisname.com>
            wrote in message news:e8ufa1$98o$1@forums.macromedia.com...
            > Using your structure, you'd have to search for a list in your main list.
            > So you'd assemble a user and password, create the prop list and use getOne
            > () to identify it's position (0 means not found)
            >
            > Otherwise, you'd have to loop through the list and that would be slow.
            >
            > I'd suggest creating a property out of each user name and pairing that
            > with the password
            >
            > [#user1: "bholly", #user2: "mpatton"] but of course you'd be stuck when a
            > duplicate user was to be entered.
            >
            > So, to suggest a solution using your structure...
            >
            > on FindUser userName
            > returnList = ""
            > cnt = gDatabase.count
            > repeat with x = 1 to cnt
            > nextValue = gDatabase [x][1]
            > if nextValue = userName then
            > returnList.add (gDatabase [x][2])
            > end if
            > end repeat
            > return returnList end
            >
            > call it using:
            >
            > passwrd = FindUser ("bholly")
            >
            > --
            > Craig Wollman
            > Word of Mouth Productions
            >
            > phone 212 928 9581
            > fax 212 928 9582
            > 159-00 Riverside Drive West #5H-70
            > NY, NY 10032
            > www.wordofmouthpros.com
            >
            >
            > "dbohea" <webforumsuser@macromedia.com> wrote in message
            > news:e8uakk$3gu$1@forums.macromedia.com...
            >> Hi.
            >>
            >> I'm trying to build a basic database system that stores user profiles
            >> (just a
            >> basic username & password for each user).
            >>
            >> I'm using a nested list like this:
            >>
            >> gDatabase = [[#user: "bholly", #Password: "buddy"], [#user: "mpatton",
            >> #Password: "mike"] ]
            >>
            >> I've been looking at things like getaProp , getPos and getOne in order to
            >> try
            >> and find a way search my database for a specific username but I keep
            >> getting
            >> error messages saying that the handler is expecting a list. For example:
            >>
            >> put getaProp (gDatabase, #user)
            >>
            >> I think the problem lies in the fact that I am not addressing the nested
            >> nature of the property list correctly (I'm still trying to address it as
            >> though
            >> it were a standard, un-nested property list).
            >>
            >> Once I've conquered this - all I have to do is come up with a way to then
            >> return the #password value that immediately follows the previously
            >> rerturned
            >> username (and then perfrom all the checks against what the user actually
            >> entered).
            >>
            >> Can anybody give me some tips on getting values out of nested property
            >> lists?
            >>
            >> Thanks.
            >>
            >
            >


            • 3. Re: Returning values from nested property lists
              Level 7
              I"ve given you a brute force method which has no relationship to the way
              databases search.

              --
              Craig Wollman
              Word of Mouth Productions

              phone 212 928 9581
              fax 212 928 9582
              159-00 Riverside Drive West #5H-70
              NY, NY 10032
              www.wordofmouthpros.com


              "dbohea" <webforumsuser@macromedia.com> wrote in message
              news:e8uakk$3gu$1@forums.macromedia.com...
              > Hi.
              >
              > I'm trying to build a basic database system that stores user profiles
              > (just a
              > basic username & password for each user).
              >
              > I'm using a nested list like this:
              >
              > gDatabase = [[#user: "bholly", #Password: "buddy"], [#user: "mpatton",
              > #Password: "mike"] ]
              >
              > I've been looking at things like getaProp , getPos and getOne in order to
              > try
              > and find a way search my database for a specific username but I keep
              > getting
              > error messages saying that the handler is expecting a list. For example:
              >
              > put getaProp (gDatabase, #user)
              >
              > I think the problem lies in the fact that I am not addressing the nested
              > nature of the property list correctly (I'm still trying to address it as
              > though
              > it were a standard, un-nested property list).
              >
              > Once I've conquered this - all I have to do is come up with a way to then
              > return the #password value that immediately follows the previously
              > rerturned
              > username (and then perfrom all the checks against what the user actually
              > entered).
              >
              > Can anybody give me some tips on getting values out of nested property
              > lists?
              >
              > Thanks.
              >


              • 4. Re: Returning values from nested property lists
                Level 7
                Yes, you need to walk the list that contains the lists that you want to
                look into. Here's a very simple way to do this:

                ---------
                on findItem (thisList,name)
                thisMany = thisList.count
                repeat with n = 1 to thisMany
                if thisList[n].getaProp(#User) = name then
                return thisList[n].getaProp(#Password)
                end if
                end repeat
                end
                ----------

                you could put this into a movie script window and then call it like this:

                passwordINeed = findItem (gDatabase,"mpatton")


                gDatabase needs to be defined in the same script window as the call to
                use it or it needs be a global variable, but I'm guessing that's why
                you've named it starting with a "g".

                --
                Rob
                _______
                Rob Dillon
                Adobe Community Expert
                http://www.ddg-designs.com
                412-243-9119

                http://www.macromedia.com/software/trial/
                • 5. Re: Returning values from nested property lists
                  Level 7
                  Keep in mind that this will only return the first occurance of a user
                  password. If there are identical user names any after the first will be
                  ignored since the loop is written to abort upon a return.

                  This is also not a very clean method since if there is not match the
                  function will return void so you'll have to test for that as well.

                  --
                  Craig Wollman
                  Word of Mouth Productions

                  phone 212 928 9581
                  fax 212 928 9582
                  159-00 Riverside Drive West #5H-70
                  NY, NY 10032
                  www.wordofmouthpros.com


                  "Rob Dillon - Adobe Community Expert" <rob@-remove-ddg-designs.com> wrote in
                  message news:rob-848195.17284310072006@forums.macromedia.com...
                  > Yes, you need to walk the list that contains the lists that you want to
                  > look into. Here's a very simple way to do this:
                  >
                  > ---------
                  > on findItem (thisList,name)
                  > thisMany = thisList.count
                  > repeat with n = 1 to thisMany
                  > if thisList[n].getaProp(#User) = name then
                  > return thisList[n].getaProp(#Password)
                  > end if
                  > end repeat
                  > end
                  > ----------
                  >
                  > you could put this into a movie script window and then call it like this:
                  >
                  > passwordINeed = findItem (gDatabase,"mpatton")
                  >
                  >
                  > gDatabase needs to be defined in the same script window as the call to
                  > use it or it needs be a global variable, but I'm guessing that's why
                  > you've named it starting with a "g".
                  >
                  > --
                  > Rob
                  > _______
                  > Rob Dillon
                  > Adobe Community Expert
                  > http://www.ddg-designs.com
                  > 412-243-9119
                  >
                  > http://www.macromedia.com/software/trial/


                  • 6. Re: Returning values from nested property lists
                    Level 7
                    "I'd suggest creating a property out of each user name and pairing that with
                    the password"

                    I would agree, this approach seems more direct. User names are usually
                    supposed to be unique anyway, so there should be code preventing duplicates
                    from being created.


                    • 7. Re: Returning values from nested property lists
                      dbohea Level 1
                      Thanks for all the suggestions.

                      My brief has now changed a bit and it means that I can go for the option to create properties out of each username and then assign the passwords as the values (which is what I'd done before any of this nested list confusion).

                      Nice one people.