Application of data package in VC

zhaozj2021-02-17  53

Application of data package in VC

1 Introduction

In the application of VC, the operation of the database is often involved. If it is a very simple application, the VC is still calculated, and for a slightly complex data application, the application developed by VC needs to write a large number of operational database, which is high, and the COM type data is operated. It is easy to make mistakes.

Although there is a guide to develop database applications in VC6 and VC7, it encapsulates data tables, but these wizards can only be adopted in the document type, if there are multiple tables, and it is possible to repeated modification, it is very It is difficult to meet the requirements. There is also the most important point, the data sheet package from the VC is aimed at the ODBC and other data connection methods. It is the application of the old cover C / S. Now most applications are based on multi-layer design, database Connection tube reasons are managed in middleware, which is no longer able to meet the requirements.

Below we will introduce a package of simple, extensive, practical databases, all discussions are VC6-based Oracle data applications, but it is not limited to these platforms, as long as they make a slight modification, the same applies to data packages under Java.

2. Code for data packaging

Before the package, the data package is required to be made, and the hierarchy of the package will be described, and the program can be written.

Specification 1: Each data table or view is created in the VC, which is a mapping of a data sheet or view. Its different types of member variables save the value of the data table or the view field, and an object of the class corresponds to A record of a data sheet or view.

Specification 2: The classes of each data table are inherited in the CDATABLE class; each view package class is inherited in cdataarec, cdataable inherits in cdataarc, cdataarec inherits in cdataModule, as shown below (user information table YHXXB and users Information watch view yhxxb_v is an example:

Instructions in data package classes:

Ø CDATAMODULE is the package class of the database operation, which can be used as a common class, which is used as a protective base class in the above figure, because the data package class Cyhxxb can only call the CDATAREC layer above the packaged function, not Call directly of the members function of the CDataModule class directly and database interaction.

Ø CDATAREC is a very critical class that saves the result set of queries, declares that the FillAllField virtual function, uses C polymorphism, calling different subclasses of the Fillage Fillage FilleField function to assemble the results data of the query to different sources Class objects.

Ø CDATABLE encapsulates some operations of the data sheet, including increase, delete, change, etc.

Ø CYHXXB encapsulates the operation of the data sheet YHXX, which can be increased, deleted, changed, and queried.

Ø CYHXXB_V encapsulates the operation of the view YHXXB_V, which can be found.

3. Excellation of data packages

The advantages of data packaging in accordance with the specifications above are as follows:

Ø CDATAMODULE encapsulates all database operations, which makes all the databases of the database, and the entire program is unified by it and the database interaction, and the use is simple. If the database selection changes, the structure has two layers to change to three layers, only only Modify this class, increase the portability of the program.

Ø The hierarchical structure is clear, clear, different classes are responsible for different levels, in addition to the final tables and views, other basic classes are easy to modify.

Ø The final class is automatically generated by the program, and the modification is also very easy. Ø Not easy to make mistakes, data is as class, the member variables of the call class are far more simple than the query database, and the code written less.

Ø Improve the efficiency of the design, as long as the database design is completed in Case Studio, you can automatically generate database scripts, database design documents, data relationship graphs, data package classes, making fast programming.

However, there are some shortcomings in the data package, which automatically generates all data tables and view package classes, including many classes in the project, find a class more time, and more compiler. However, in the VC, you can use the alphabet index to look for each class, or prefixed in front of the automatically generated class, basically does not affect its ease of use.

4. Database design specification

4.1 Design specification for data sheets

To do a data package, you need to do the following requirements for the design of the data sheet:

1. Various tables of the database must contain an ID field for the Number type, the field uniquely determines a record;

2. This ID field comes from a sequence, if the name of the table is YHXXB, the name of the sequence is SEQ_YHXXB_ID, and the CDATABLE's POST function is used to find a similar statement select seq_yhxxb_id.nextval from DUAL to find the new record ID.

3. The primary key relationship between the data sheet needs to be established, and it is necessary to clarify how the primary key is deleted after the database is deleted, and the relationship between these data is maintained by writing triggers.

4. The cascade update of the data table is to be implemented in the database layer;

4.2 View design specifications

View's SQL statement demonstration format:

Example 1: Create View ABC (A, B, C, D) AS SELECT A, B, (Select Y.cc from y where y.c = x.c) AS C, D from x;

Example 2: Create View Abc as SELECT X.A, X.B, (Select Y.cc from y where y.c = x.c) AS C, Z.D from x, z where x.c = z.c;

The specific requirements are as follows:

1. If there is 2 tables in the FROM of the primary SELECT statement, it is to be written in accordance with the specification of Example 2, which is indicated in each item (such as X.A) in the Select;

2. View naming rules, main table name "_ v";

3. SELECT queries, only items with subquery can use as;

4. Only the most basic queries, other queries such as SUM, Count functions, should check the generated class, and manually modify the content;

5. There should be an ID field in the view that is from the ID field from the primary table;

6. In the subquery, it should be guaranteed that there is no ","

7. If there is no write table name in the project, as example 1, there can only be a table in the main query from the FROM statement;

8. Not supported the alias such as from a xxx, b yyy query;

9. Only two levels of views only.

5.case studio application

5.1 Introduction to Case Studio

Case Studio is the Czech Database Development Tool, which is the concept of Create Database Structures Faster and Easier! More and more big companies and institutions use it, please refer to http://www.casestudio.com. This tool can complete the following features:

Ø Perform a visual database design, each Entity represents a database table, can quickly establish a variety of data relationships, etc.;

Ø Can check the correctness of the database design;

Ø Automatically generate documents in the detailed RTF or HTML format;

Ø Automatically generate scripts created by the database;

Ø Support script js or VB script to access each Entity, generating C classes in this specification is achieved by JS scripts;

Ø You can store the entire data to XML format, you can write other programs to take advantage of its data;

Ø You can analyze each Entity from different types of databases;

Ø Support multiple databases and can perform conversion of different databases.

5.2 Scripts in Case Studio

Supporting JS or VB scripts is an attractive place to which the database tool is based on this, we can easily generate a package class based on your own standardized data sheet and view. The following brief introduction how to write scripts:

1) Click on the button Edit Templates to open the template editor.

2) Select Branch Events-> User-Defined System Templates, right-click to add a node, set according to the content below:

3) Enter your own JS script in the Text page, the JS script has a fixed format, must have a main function, details can be downloaded on the Case Studio website, the page is as follows:

4) Relift Case Studio, you can see more adds-in menus, click on the project of the custom function, will pop up the script's execution window, click RUN, and generate the contents of the program output in the log.

Here is the YHXXB package class generated by this script:

Class Cyhxxb: Public CDATABLE

{

Private:

; // name TypeName TypeID Length

CString M_YHM; // User Name VARCHAR2 20 20

CString M_YHzWM; // User Chinese Name Varchar2 20 20

CString M_MM; // Password VARCHAR2 20 20

Private:

INT C_YHM;

INT C_YHZWM;

INT C_MM;

PUBLIC:

CYHXXB (): CDATABLE ("YHXXB")

{

C_YHM = 20;

C_yhzwm = 20;

C_mm = 20;

Find ("");

}

~ Cyhxxb ()

{

}

Void fillagefld ()

{

Beginread ();

Setfldascstring ("yhm");

Setyhzwm ("YHzWM");

Setmm (Getfldascstring ("mm");

SetID (Getfldasint ("ID")); endread ();

}

void setflddefault ()

{

Setyhm ("" ");

SETYHZWM ("");

Setmm ("" ");

}

CString getyhm ()

{

Return M_YHM;

}

Void setYhm (cstring pi_yhm)

{

CheckRecstatus (false);

IF (pi_yhm.getlength ()> c_yhm)

{

Throwzhexception ("YHM field can only accept a string of less than 20!");

}

m_yhm = pi_yhm;

}

.

.

.

}

6. Summary

This article introduces a wide range of data package, which belongs to DIY, a frame design, versatile, you do just once a development, Ery despite the reference. How to encapsulate these classes, this article only gives a simple introduction, designed to throw bricks, what kind of design you need, move right away!

转载请注明原文地址:https://www.9cbs.com/read-30727.html

New Post(0)