Up until now, we've looked at how to create parent-children data shape relationships. We are restricted, however, to limiting our shapes to parents and immediate children. We can
APPEND data shapes to our children, creating grandchildren! You may be wondering when you would need to use grandchildren. Well, imagine that each class could have zero to many text books assigned to it. We could modify our ASP page to display, under each class, the list of text books required for that class.
The syntax for grandchildren is a little complex. What you need to do, is in the child statement, instead of using a child SQL statement, you will use another
SHAPE statement. Here is the syntax for creating a grandchild:
Wow, looks a little bewildering, eh? Well, let's look at it in action with the text book example discussed. Here is the table definition for the
Note that each class can have zero to many books assigned. The
ClassID column is a foreign key to the
ClassID in the
Class table. Now, the actual
SHAPE command we will use is as follows:
We are using data shaping to create TWO children and one grandchild! Isn't this freakin' awesome? Anyway, to loop through the recordsets, we will modify the code we used in Part 2 to include this loop inside of the loop that loops through the
With some sample data entered, this will generate the following output:
Dr. Smith (Phone: 123-4567) Classes: Analysis of Algorithms (CS355) Books: Algorithmics Explained ($65.95) Algorithm Theory ($99.95) Artificial Intelligence (CS341) Books: Applied A.I. ($79.50) Projects: Self-Documenting Programming Optimization Routines Dr. Johnson (Phone: 123-8901) Classes: Distributed Systems (CS333) Books: None... Projects: A.I. In the Workplace Dr. Mitchell (Phone: 123-1234) Classes: Formal Languages & Automata Theory (CS330) Books: Automata Theory ($69.95) A Study of Linguistics ($72.25) Study of Film (ART85) Books: Film History ($39.95) Software Engineering (CS301) Books: Software Engineering Practices ($79.25) Projects: Software Reuse Study Image Processing Image Recognition
I sure do like data shaping, it is really neat and powerful. The syntax is cool too. :) Not only is data shaping cool, but it is also very useful! Try generating a nice, hierarchical report showing professors, their classes taught (the classes text books), and the research projects worked on by the professors. You would not only have a nasty
JOIN for your SQL statement, but you would also be returning a lot of redundant information.
Hope you learned something new and had fun! Happy Programming!