My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
   
SUBSCRIPTION STATUS
If you are a subscriber to this publication, sign-in to access locked articles. To subscribe or renew go to www.AdvisorStore.com.
Go to Article

VISUAL FOXPRO ADVISOR ANSWERS

Handling Multiple Attributes in Visual FoxPro

Here's a design that will streamline the maintenance of your application.

By Pamela Thalacker, contributing editor


Q: I have an application that tracks real estate properties for sale. Each property can have any number of amenities such as number of bedrooms, outdoor Jacuzzi, granite countertops, etc. Currently I track these with Boolean fields in the Property table. I have a container with a checkbox for each Boolean field where the user can specify which amenities a property has when he is adding or editing property information and when they want to query for properties that have certain amenities. Every time I add an amenity, I have to add another Boolean field to the table, another checkbox to the page where the user can specify amenities, and another case statement to the code that creates the query string. This is getting very cumbersome and I was wondering if there isn't a more generic way I might handle this scenario?

A: There are a couple of things I would do to simplify maintenance of your application. First, I would change your data structure. Although an argument can be made that having Boolean flags is faster for data retrieval than a normalized many-to-many table, with today's fast processing speeds and data connections, I don't believe the speed difference offsets the maintenance cost for such a scheme. And, as easy as it is to assign a Boolean field to a checkbox as a control source for simple data modification, I believe the cost in application maintenance is too high. Instead, I recommend you create a table (I call it the attribute table) that contains a record for each possible amenity available in a property, and another table (the many-to-many table) that links the property to its amenities.

There are many scenarios where this sort of design and data pattern would be appropriate. Other examples include a customer and his hobbies, a recipe and its ingredients, a houseplant and the nutritional inputs it needs, and a patient and the medications he takes.

To create one set of classes that can be reused, I have some rules about the structure of the two tables. I try to make my table names no more than 8 characters so that the primary key can always be named pk<table name> and remain no more than 10 characters. This allows me to have index tags with the same name as the field, and to use the field in temporary free tables. In your case, the real estate property table would be named Property, and its primary key would be pkProperty.

I always give the attribute table a cValue field in addition to the primary key field. In your case the table would be structured as in table 1.

To be consistent with my naming convention, I would name the many-to-many table something like Prop2Am and it would have the structure shown in table 2.

NameDate Type
pkAmenityI
cValueC(30)
Table 1: Amenity table -- This is the minimum structure of the attribute table for the real estate application.


NameDate Type
pkProp2AmI
fkPropertyI
fkAmenityI
Table 2: Prop2Am table -- This is the minimum structure of the many-to-many table for your real estate application.

Pamela ThalackerContributing Editor Pamela Thalacker is manager of software development for JELD-WEN Communities, a destination resort company based in central Oregon. She's a Microsoft Certified Professional, a sysop for the Compuserve MSDEVAPP forum, and has been developing applications in xBase languages since 1985. pamela@eagle-crest.com

Printer-friendly
page layout

Handling Multiple Attributes in Visual FoxPro

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    ARTICLE INFO

    Web Edition: 2008 Week 06, Doc #19398

    FREE ACCESS FREE ACCESS

    Keyword Tags: Microsoft, Microsoft Visual FoxPro, Programming

    ADVISORAMA
    Snoring is nature's way of saying, "Hey everybody, wake up and look at me. I'm sleeping."

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2010 Advisor Media, LLC. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, LLC in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    Hosted by Prominic.NET Website powered by
    LOTUS SOFTWARE
    oa granl84-03 posted 2008-2-4 mod 03/15/2010 03:10:23 AM ztdbms/ztdbms
    domino-144.advisor.com my.advisor.com 03/21/2010 02:58:23 AM