1 Reply Latest reply on Feb 14, 2007 2:37 AM by duckets

    Creating a Dynamic Property LIst

      Hi everyone,

      How to make a dynamic Property list in lingo
      Actually the problem is I am fetching a list of Columns from the databse which may vary so I want to make a dynamic PropertyList in which I can Set the property and the values based on the number of colums in a Database

      For Example: In the DB, I have a Table which contains follwing columns
      FName, LName,CompName, Age, Address1, Address2, Email, website

      Now I will select specific colums based on some condition. So I will be storing the result which would come in a property list. So this List needs to be Dynamic i.e it should be getting created based on the colums returned from the query.

      Suppose for a specific condition i get Fname, Lname, Email as a result so my List should look some thing like This

      objRecord = objResult.rows[1] --Row Returned from the Database

      listQueryResult = [#FirstName : objRecord[1], #LastName : objRecord[2], #Email : objRecord[3] ]
      The Above List shoud be based on nos of colums returned from the Query

      Is there any way by which i can create such a Dynamic Property List.

      I hope the Question is Clear
      Hope to get the answer at the earliest

      -Thanks and Regards
      -Atul Saxena
        • 1. Re: Creating a Dynamic Property LIst
          duckets Level 1
          You can create a new empty property list like this:

          listQueryResult = [:]

          To add a property/value pair, you can use:

          listQueryResult[ <propertyName> ] = <value>


          listQueryResult.setaProp( <propertyName> , <value> )

          The above two commands will add the property if it doesn't exist, or update a value if the property name is already present in the list.

          You may not be aware that you can use strings as property names instead of symbols if you like, which you might find easier.

          Couple of examples following your example:

          listQueryResult = [:]

          objRecord = objResult.rows[1] --Row Returned from the Database

          listQueryResult["FName"] = objRecord[1]
          listQueryResult["LName"] = objRecord[2]

          Or, if you also have a list of the fieldnames returned from the db:

          listQueryResult = [:]

          fieldNames = objResult.fieldNames --Field names for records returned from Database
          objRecord = objResult.rows[1] --Row Returned from the Database

          repeat with n=1 to fieldNames.count
          thisFieldName = fieldNames[n]
          thisFieldValue = objRecord[n]
          listQueryResult[thisFieldName] = thisFieldValue
          end repeat

          hope this helps!

          - Ben