1.3.2 Modification
- The InsertNode is modified, so that the transmitted node id is no longer incorrect and is inserted to the root by default. (Removed for security considerations)
- Improved the SubTree function.
- The path function is added to obtain the path.
- After alterNode is added, you can modify the node name and its location on the sibling node.
License: GUN LGPL
Test address: http://lxbzj.com/product/dbtree/index.asp
DBTree instructions
Directory
- Introduction
- Features
- How to Use
Introduction
DBTree is the abbreviation of database tree. It indicates the tree structure in the database.
DBTree is a fast solution that records tree data structures in databases in a database server environment. This document is collectively referred to as a tree, it is also the implementation of the tree structure in the database.
DBTree contains different versions: asp + access, and so on.
Features
In general, the tree is implemented in the database using the tree's parent-parent notation, And a number field id and a parent number field parent_id are set to implement the tree structure. This data structure is characterized by a simple operation and almost no maintenance. However, the advantage is that the system overhead is huge during tree traversal and requires recursive operations, therefore, the depth of the tree cannot be increased without limit. Asynchronous reading is widely used to reduce system overhead. Some improvement methods cannot avoid this problem.
In most cases, the server requires that tree traversal tasks occupy most of the tree operation tasks. It can be seen that Optimization Based on number traversal can greatly improve the efficiency and reduce the server load.
Or the overhead of the system can be reduced only when asynchronous reading is used in the paral expression, but this still cannot solve the problems such as the depth, path, and deletion of the tree.
In this program, a representation structure that better adapts to the number of traversal is adopted. It can greatly reduce system overhead and effectively solve advanced operations on some trees and adapt to databases.
How to Use
To use this program, you must prepare a database in advance and set the database connection.
1. database definition:
Database Table (Tree) Definition (access)
| Field name |
Field Type |
Required |
Default Value |
Others |
Index |
Description |
| Id |
Number |
|
|
Automatic ID |
Yes (no duplicates) |
Unique node ID |
| P_id |
Long Integer |
Yes |
0 |
|
|
Node parent number |
| Name |
Text |
Create folder |
Null strings are not allowed. |
|
Node name |
| Porder |
Long Integer |
|
|
Yes (repeated) |
Node preorder Order Number |
| Dep |
Long Integer |
1 |
|
|
Node depth Value |
| Del |
Boolean |
Flase |
|
|
Delete? |
| Note: The field name is only the default field name. If you do not specify another field name, the program assumes that your field and table name are the default. |
2. on the page to be used, run the following command on the server: <! -- # Include file = "dbtree. asp" -->
3. Initialize an object instance, and then initialize the database connection string and other variables.
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
<% Option explicit 'transaction = Required %>
<! -- # Include file = "dbtree. asp" -->
<%
Dim MM_btree_STRING 'database connection string
MM_btree_STRING = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & server. mappath ("tree. mdb ")
%>
<%
Dim tree
Set tree = new DBtree
Tree. conn = MM_btree_STRING 'specifies the join string
Tree. table = "tree" 'specifies the table name.
Tree. id = "id" 'specifies the column name.
Tree. p_id = "p_id"
Tree. porder = "porder"
%>
4. You can perform the following operations on the tree:
Instance:
1. display the tree as a list:
<%
Dim arr1(1,0),arr2(1,0),cache
arr1(0,0) = "<ul>"
arr1(1,0) = "</ul>"
arr2(0,0) = "<li>{name}"
arr2(1,0) = "</li>"
cache = tree.display(0,-1,arr1,arr2,"relative")
response.write(cache)
%>
2. Insert, delete, and so on
Select case request. Form ("submit ")
Case "mobile"
Msg = tree. moveNode (request. Form. Item ("src"), request. Form. Item ("des "))
Case "delete"
Msg = tree. delNode (request. Form ("node"), false)
Case "permanent deletion"
Msg = tree. delNode (request. Form ("node"), true)
Case "Restore"
Msg = tree. undel (request. Form ("undel "))
End select
3. For other operations, see instance
4. API
The entire program is a class that provides interfaces such as insert, move, delete, display, and output as List controls, which will be improved in the future.
API
| Function Name |
Function |
| InsertNode (int node_pid, str node_name) |
Insert a node as the child node of the given node. Parameters:
- Node id in the node_pid tree. 0 indicates that the node is inserted to the root.
- By default, the str node name is a new folder;
|
| MoveNode (src_id, des_id) |
Move the node and Its subtree. parameters: src_id source node id; des_id: target node id (note that a node cannot be moved to the root node temporarily (0 )) |
| DelNode (id, confirm) |
Delete a node and a subtree. Parameter: id node id; confirm: whether to directly Delete true/false. |
| Undel (id) |
Restore a node that is not directly deleted |
| String OutPutOption (root_id, selected_id, show_root, rel_deep) |
Output the tree as an option for a table-like control, that is, the <option> label Parameters:
- Root ID. The default value is 0.
- Default options in the selected_id List Option
- Show_root: whether to allow display of Root records
- Rel_deep show relative depth-1 show all 0: show only root 1 show 1 Layer
|
| Display (root_id, rel_deep, menu_tag, item_tag, options) |
Function: Read and generate the display content based on the template tag. The replace tags include: {id}, {name}, {porder}, {auto}, {pid}
- Parameter: root_id root id. 0 indicates that all are displayed.
- The relative depth to be displayed in rel_deep. Layer 1, Layer 2, etc.
- Menu_tag menu tag Array
- Item_tag project tag Array
- Menu_tag and item_tag must be arrays like arr (1, n), that is, they must be 2D arrays, and the first dimension must be the first two-dimensional storage labels.
- Arr (0, n) stores the start tag, and arr (1, n) stores the end tag. The end tag cannot contain the content to be replaced.
- Menu_tag (x, 0) and item_tag (x, 0) are used to store default template tags. For more information, see use instances.
- Option: parameter, available value: relative
|
| SubTree (node_id, order, rel_deep, with_root, with_del) |
Retrieve the subdirectory record set
- Node_id node id
- Sort: "asc" "desc"
- Rel_deep: The relative depth 1 to be displayed. Only Layer 1 is displayed.-1 is displayed. All depth 0 is displayed. Only root is displayed.
- Whether the with_root (true/false) record set contains the root
- Whether the with_del (true/false) record set contains records marked as deleted
|
| AlterNode (node_id, new_name, step) |
Modify node Information
- Node_id node id
- New_name new name
- Position of the step to be moved
|
| The program is being improved, and some interfaces need to be adjusted. |
Linzsoft. com2006-05-26