Developed two methods based on Oracle data library applications with VC

zhaozj2021-02-17  51

Developed two methods based on Oracle data library applications with VC

North Beijing Airlines Airlines Tianshi Research Machine Science Research and Technology Department Li Jie

---- 1. Introduction ---- Oracle has launched the SQL standard relational database products from 1979 to the 1997 version 8, the Oracle database is supported by its support, multi-user high-performance transaction, industry Support, complete safety and integrity control of various industrial standards, support distributed database and distribution processing, portability, compatibility, and connectivity, etc. Highlight users, according to IDG1992 global UNIX database Market report, Oracle accounts for 50% of the market sales. In the past, Visual C is also aware of Guangshang's favorite because of its strong sense of function and high degree of flexibility, and this article is intended to introduce two methods of using Visual C to develop Oracle Database applications. ---- 2. Develop database applications using Pro * C ---- 2.1 Pro * C Working principle ---- Pro series is an embedded SQL statement in the third-generation advanced programming language in the third-generation advanced programming language to access the database A set of pre-compiled procedures, including Pro * ADA, Pro * C, Pro * Cobol, Pro * Fortran, Pro * Pascal, and Pro * PL / I. The programmer writes the PRO source that embeds the SQL statement with the corresponding advanced language (if the C language is called the Pro * C source program), the program is called the Pro * C source program, and the embedded SQL statement is converted into a standard Oracle call and generated. The target source program, that is, the source program of pure high-level language format, and then call these source programs to the user's program, the processing process is shown below. ---- Oracle pre-compiling procedure provides as the following function: ---- (1) Any write application programming in the speech of the six generic high-level programming. ---- (2) Follow the ANSI standards, embed the SQL statement in the high-level language. ---- (3) A dynamic SQL method can be used to allow the program to accept or construct an effective SQL statement when running. --- ⑷⑷ Realize the autonomous conversion between the Oracle internal data type and the high-level language data type. ---- ⑸ can be changed through the embedding blocks into the PL / SQL event block in the application program. ---- ⑹能 can specify the required pre-editing options on the program line and the command line, and can change their values ​​in the pre-compiled process. ---- ⑺⑺ 全 全 检 检 数 据 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法 法---- ⑻ You can use SQL * NET to save the Oracle data library of multiple locations in parallel. ---- ⑼ can use the array as an input and output order variable. ---- ⑽能 can pre-edipulate the code segment in the application program. ---- ⑾ provides a strong different constant work.

--- This shows that the combination of precompile procedures and other advanced languages ​​can be utilized to provide powerful means for the development of SQL powerful functions and flexibility for database application systems, but also make full use of senior languages ​​themselves. The advantages of system development provide a complete development solution based on Oracle database applications. ---- 2.2 Use Pro * C ---- Each Pro * C source file in VC, is divided into two partial components and procedures. The program header contains the host variable (variable contained in the SQL statement), said that the communication area definition and the C-external table character are said. The program is usually composed of a trunk function, and such a function contains a SQL statement (starting with an Exec SQL). ---- Pro * c Supported data types include varchar2 (variable length strings), Number (two-in number), int GER, FLOAT, String (string with NULL), Varnum (Becoming long binary), long (becoming long string), varchar (variable length string), ROWID (binary value), Date (duration date / time value), Varraw (becoming long binary data), RAW Long binary data), LongRaw, unsigned (no symbol integer), longvarchar, longvarraw, char (generous string), Charz (CHARZ) Strings ending with NULL), MLSLabel (becoming long binary data). ---- You cannot use 'L' or 'u' omnipotent or '0x' 作 头 修 or '0x' in Pro * C; use single quotes in the SQL statement to define strings, define special or lowercases with double quotes. The identifier of the character (such as a table name, etc.); the address, indirect, bit logic, composite assignment, =, -, ,%, <<, >> operator is not allowed in the SQL statement. NOT, AND, OR, = Replace!, &&, ||, ==. ---- The program of the lower surface is a pro * C source example of a joint agricultural library. #include // Declare SQL Communication Zone #include

#include

EXEC SQL Begin Declare Section;

VARCHAR Username [20]; // Declaration Host variable

VARCHAR Password [20];

VARCHAR DBNAME [20];

Exec SQL End Declare Section;

Void DB_Connect ()

{

STRCPY ((char *) Username.arr, "scott");

Username.len = Strlen ((char *) Username.arr);

STRCPY ((char *) Password.arr, "tiger");

Password.len = strlen (char *) Password.arr); strcpy ((char *) DBNAME.ARR, "sundb");

DBName.len = Strlen ((char *) DBNAME.ARR);

EXEC SQL WHENEVER SQLERROR STOP; // Implicit Overnormal Processing

EXEC SQL Connect: Username

Identified by: Password Using: DBNAME;

/ * if (sqlca.sqlcode! = 0) // Explicit exception handling

{

AFXMessageBox ("/ N failed with the Oracle database!");

Return;

} * /

}

---- When using Pro * C in the VC, first write the subroutine of the required operational database with Pro * c, then run the Pro * C precompiled program to transfer the Pro * C source program to the corresponding CPP source program. Insert the program into the user engineering file and describe the function in the module that needs to be called to the insert function, and then you can call the desired function in this module. ---- 3. Using ODBC Middleware Access Database ---- 3.1 ODBC Working Principle ---- ODBC is an Open Database Connect, which is an open database interconnect, it is used by Microsoft's 1991 in 1991. The unified interface criterion of the access database is the middleware between the application and the database system. It achieves the operation of the data library with the interaction of the drive program and the required data library with the required data library, and avoids the operation of the data library and the agriculture of the data library in the application program. ---- ODBC master is composed of drivers and drive program devices. The driver is a module for supporting the ODBC function (usually a DLL under Win95), each driver corresponding to the corresponding database, and simply change the application when the application is transplanted from a database system to another The alias corresponding to the corresponding database system is set by the ODBC Manager. The driver program deraser (including in ODBC32.DLL) can be linked to all ODBC applications, which is responsible for the binding of the ODBC function and the function of the function in the DLL in the program. ---- ODBC uses hierarchical methods to manage the database, in each layer of the database communication structure, the ODBC introduces a public interface to solve potential inconsistency, thus good Solved the relative independence based on the database system application, which is also one of the important reasons for ODBC to achieve great success. ---- From the structure, ODBC is divided into two types of single-class formulas and multi-beam types. ---- (1) Single-bundled driver program ---- A single bundle drive program is between the application program and the data library, and the morbidity of the diaphragm is provided with a uniform data access method. ---- When the user performs a database operation, the application passes an ODBC function to call to the ODBC driver manager, determined by the ODBC API, is handled by it directly and the result is returned or the driver is executed and the result is returned. .

---- According to the above, the single bundle drive program is a data library engine, which is directly completed to the data library, and the data library can be located in the network. ---- (2) Multi-type driver ---- multi-type driver is responsible for transferring commands and data between database engines and client applications, which do not perform data processing operations and network communication for remote operations An interface of the agreement. ---- Front-end application proposes a request for database processing, which forwards to the ODBC driver manager, the driver manager is completed or transmitted to the multi-beam driver in place according to the request, and the multi-active driver will Request to translate a database communication interface (such as Oracle's SQLNET), which can be understood and handed over to the interface. The interface transmits the request to the server on the server. After the server is processed, send the result back to the database. Communication interface, the database interface transmits the result to the multi-type ODBC driver, and then passes the result to the application. ---- 3.2 Using ODBC in VC - CDATABASE, CRecord, CRecordView, CDBException, and CFieldView, CDBEXCEPTION, and CFIELDEXCHANGE, using ODBC ---- Visual C , which encapsulates the ODBC SDK function, so that users can do not need to know the SDK function. It is convenient to operate the database of ODBC. ---- CDATABASE Class: Encapsulated and rollback and rollback and execution of SQL statements. ---- CRECORDSET Class: Encapsulated larger estimated data libraries, including browsing, repair records, controlled marking movements, sequencing and other operations. ---- CRecordView class: The view is provided with the RECORDSET pair, and the control of the control and the data library data can be established, and the transformation of the number of operations, repair records. ---- CDBEXCEPTION Class: Provision for different constant processing of data library operations can be obtained to obtain a different phase-off return code. ---- CfieldExchange class: Provides the data exchange between the user variable and the data library field. If you don't need to use a custom type, you will not have to call the function of this class, MFC Wizard will serve as a serial staff.

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

New Post(0)