Data Shaping Technology

Source: Internet
Author: User
Tags ole

Data shaping (which can also be called Hierarchical recordsets)
If you are familiar with access, it is similar to a child table. When you use VB
Database development is the best choice for you.
This technology has a strong application environment, especially for the development of enterprise-class applications such as OLTP.
It allows you to use a tree-like structure to represent your data, so it is particularly suitable for
To display the associated data table Form to the user.
In simple terms, it has a master table (Recordset) and then
One of the fields in the master table can hold a second child table (Recordset)
Of course, in general, one of the fields in the child table (such as the primary index) and the field in the master table
is associated (relationship) so that when you execute a query, the result returns a
Multiple recordsets. This data shaping technology brings us the following benefits:
1. Performance improvement, as long as the rational use of this technology, can greatly improve
ASP connects the performance of the database program. And you don't have to show complicated
Interrelated data forms and worry about them.
2. Greatly simplifies programming: Because of the hierarchical Recordset structure it introduces,
Using the tree view to display records, you will find that you use the data shaping technology to display
The data is very beautiful.
Or the previous method, the nonsense less to say, let the code to speak put:
This example will use the example database in SQL Server, pubs

How to use data shaping programming:
The preparatory work is as follows:
1. You should install a MSDataShape OLE DB Provider (in MDAC2. More than 0 versions are available with this data source provider)
2. You should be able to write the shape language, note that this is not a general SQL statement, you can view the specific syntax
The Help file in Access.
A couple of places to pay attention to.
(i) Establishment of a MSDataShape OLE DB provider connectionstring as follows (hehe, it seems that my piece
The database connection manual can be added to the new stuff.
' This is a very common connection string, hehe, where the Kanga is actually SQL Server in Microsoft internal code
strconn = "Provider=sqloledb;data source=kanga;" &_
"Initial catalog=pubs; User Id=sa; Passwprd= "
' Well, now join the MSDataShape OLE DB provider section
strconn = "Provider=msdatashape; Data "& strconn
Well, now that you've set the data provider for MSDataShape,
Note that the data source provider is your real DSN section.
(II) Shape language
Shape syntax You can find detailed descriptions in the help of ADO, and I'm not wordy.
The most commonly used statements are as follows:
SHAPE {Parent Command} [as parent alias]
APPEND ({Child Command} [as child alias]
RELATE Parent_column to Child_column) [as Parent_column_name]
One of the simplest examples is as follows:
SHAPE {SELECT * from publishers}
APPEND ({SELECT * from Titles}
RELATE pub_id to pub_id) as Rstitles
The above statement associates the titles table with a child table of publishers, so how to access it
Data, the syntax is as follows:
Set rstitles = rspublishers ("Rstitles"). Value
Now the Rstitles is a recordset, which is the data in the child table.
The aspshape.asp file code is as follows:
<%
Dim rspublishers
Dim Rstitles
Dim Strshapeconn
Dim Strshape
Dim strconn

strconn = "Provider=sqloledb;data source=kanga;" &_
"Initial catalog=pubs; User Id=sa; Passwprd= "

Set rspublishers = Server.CreateObject ("ADODB. RecordSet ")
Strshapeconn = "Provider=msdatashape; Data "& strconn
Strshape = "SHAPE {SELECT * from publishers}" & _
"APPEND ({SELECT * from Titles}" & _
"RELATE pub_id to pub_id) as Rstitles"

Rspublishers.open Strshape,strshapeconn
Response.Write "<UL>"
While not rspublishers.eof
Response.Write "<LI>" & Rspublishers ("Pub_name")
Response.Write "<UL>"
' Start displaying data for the child table below
Set rstitles = rspublsihers ("Rstitles"). Value
While not rstitles.eof
Response.Write "<LI>" & Rstitles ("title")
Rstitles.movenext
Wend
Response.Write "</UL>"
Rspublishers.movenext
Wend
Response.Write "</UL>"

Rspublishers.close
Set rspublishers = Nothing
Set rstitles = Nothing
%>
You can run the code above and watch the results, and then the usual The
uses SQL queries to compare them.
Note: This is the time to add a few DHTML statements to make the
tree's pull up and expand effect (which is similar to the one on the left of the resource manager)
Oh, this is very good to fall off.
Hehe, the above is just a very simple child table, the following is a brief description of the case of
multiple child tables.
If you have only one child table in your datasheet, in fact, the use of SQL can also be done, the
can not fully display the advantages of the data shaping technology, but if you have more than one field in the master table and other tables associated with it, you can fully see the technology The
is powerful.
Here is an example of a two child table
SHAPE {select * from publishers}
APPEND ({select * from Titles}
RELATE pub_id to pub_id) as RsT Itles,
({SELECT * from Employee}
RELATE pub_id to pub_id) as Rsemployees
Simple, hehe.
This is nothing, you know. If you have a
child table in your datasheet with a child table (this is the so-called layered recordset)
you will find it more convenient to use the data shaping technology. And that's why
I said at the beginning. This technology is particularly useful with OLTP and enterprise-class complex database development.
The following is an example of a two-level child table
SHAPE {select * from publishers}
APPEND (SHAPE {select * from Titles}
APPEND ({select * from S Ales}
RELATE title_id to title_id) as Rssales)
RELATE pub_id to pub_id) as Rstitles

In fact, not only can you use SQL statements in data shaping, but you can also use stored procedures.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.