Two ways to develop Oracle database applications with VC

zhaozj2021-02-08  231

1. Introduction Oracle Company launched the SQL standard relational database products from 1979 to the introduction of the 1997 version 8, the Oracle database supports the high-performance transaction processing of large databases, multi-users, and is supported by industry standards. Safety and integrity control, support distributed database and distribution processing, portability, compatibility, and connectivity, etc., the advantages of user favorite, according to the market report of the IdG1992 global UNIX database, Oracle accounts for market sales 50%. In terms of development tools in the client, Visual C is also popular among the majority of programmers due to its strong function and high flexibility, so this article is intended to introduce two ways to develop Oracle Database applications using Visual C . 2. Using Pro * C Develop Database Applications 2.1 Pro * C Working Principle The PRO Series is a set of pre-compiled programs that are embedded in the third-generation advanced programming language to access the SQL statement in the third-generation advanced programming language, including Pro * ADA, PRO * C, Pro * Cobol, Pro * Fortran, Pro * Pascal and Pro * PL / I Six kinds. 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 Precipile Program provides the following features: (1) You can write an application in any of six universal advanced programming languages. (2) Follow the ANSI standard and embed the SQL statement in advanced languages. (3) Dynamic SQL methods can be used to allow the program to accept or construct a valid SQL statement at runtime. ⑷ Realize the automatic conversion between Oracle internal data types and advanced language data types. ⑸ You can improve performance by embedding the PL / SQL transformation block in the application. ⑹能 You can specify the required precompiled options on the procedure line and command line and change their values ​​during the precompiled process. ⑺能 can fully check the grammar and semantics of embedded SQL data manipulation schemas and PL / SQL blocks. ⑻ The Oracle database that can be accessed with multiple locations in parallel with SQL * NET. ⑼ You can use the array as an input and output program variable. ⑽能 Conditions to code segments in the application. ⑾ provides a strong exception handling function. It can be seen that by the combination of precompile procedures and other advanced languages, it can provide powerful means with SQL powerful functions and flexibility for the development of database application systems, but also make full use of high-level language itself in system development. Advantages provide a complete development solution based on Oracle database applications. 2.2 Using Pro * C in VC Each Pro * C source file is typically composed of two parts: the program head and the program body. The program header contains a host variable (the variable included in the SQL statement) description, the communication area definition, and the C-external representation, etc. Program is generally composed of several functions, including SQL statements (starting with 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 binary Number, long (viable long string), varchar (variable length string), ROWID (binary value), Date, Varraw, Varraw, RAW (fixed length binary data) LongRaw, unsigned (no symbol integer), longvarchar, longvarraw, char (pixel string), Charz (Class C) is ending with NULL String), MLSLabel (becoming long binary data).

Do not use 'L' or 'u' 作 作 or ɔX '作X' in Pro * C; use single quotes in the SQL statement to define strings, define specific or lowercase identifiers with double quotes ( Such as a table name, etc.); the address, indirect, bit logic, composite assignment, =, -, ,%, <<, >> operator is not allowed in the SQL statement and use not, AND, or OR , = Instead!, &&, ||, ==. The following program is an example of the Pro * C source program of the coupling database. #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 () {structure ((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 Handling EXEC SQL Connect: UserNameIdentified by: password Using: DBName; / * If (Sqlca.sqlcode! = 0) // Explicit exception Handling {AFXMESSAGEBOX ("/ N and Oracle Database Connection Fails!"); Return;} * /} When using Pro * C in VC, first use Pro * C to write subroutines required for the required operational database, then run Pro * C precompiled The program converts 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 call the desired function in this module. . 3. Access Database Using ODBC 3.1 ODBC Working Principle ODBC is an open database interconnection, which is a unified interface standard for accessing the database by Microsoft in 1991. It is an application and database. The middleware between the system. It implements the operation of the database by using the driver corresponding to the application platform and the required database to interact with the application, avoiding the operation of directly calling with the database directly in the application, providing the independence of the database. ODBC is mainly composed of drivers and driver managers. 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 manager (included in ODBC32.DLL) can be linked to all ODBC applications, which is responsible for managing the binding of the ODBC function in the application to the DLL.

ODBC uses a hierarchical approach to manage the database, in each layer of the database communication structure, the ODBC introduces a public interface to solve the potential inconsistency, which is well solved based on the database. The relative independence of the system application is one of the important reasons for ODBC to achieve great success. From the structure, ODBC is divided into single-type and multi-type. (1) Single-type driver Single-type driver is between applications and databases, as the intermediary driver provides a unified data access method. When the user performs a database operation, the application passes an ODBC function call to the ODBC driver manager, and it is determined by the ODBC API to process it directly and the result is returned or the driver is executed and the result is returned. As can be seen, the homogeneous driver itself is a database engine, which can be done directly to the database, although the database may be located anywhere in the network. (2) Multi-type driver multi-beam driver is responsible for transmitting commands and data between database engines and client applications, which do not perform data processing operations and an interface for remotely operated network communication protocols. The front-end application proposes a request for database processing. The request forwards to the ODBC driver manager, the driver manager is done or transmits the multi-beam driver in accordance with the request, and the multi-beam driver will be translated into specific The manufacturer's database communication interface (such as Oracle's SQLNET) can understand and handle the interface to process, the interface transmits the request via the network to the server, then send the result back to the database communication interface, database The interface passes the result to the multi-style ODBC driver, and then transmits the result to the application. 3.2 Five classes of CDatabase, CRecordset, CRecordView, CDBException, and CFieldView, CDBException, and CFieldView, CDBException, and CFIELDVIEW, CDBEXCETSET, CRECORDEXCHANGE are provided in VC. These classes enable users to easily support the ODBC database without having to understand the SDK function. CDATABASE Class: Encapsulates and controls the method of submitting and rollback and executing a SQL statement. CRecordset class: Most ways to encapsulate the manipulation of the database, including browsing, modifying records, control cursors, sorting. CRecordView Class: Provides a view that is connected to the Recordset object, can establish a corresponding control and database data, and support mobile cursors, modify the record, etc. CDBEXCEPTION Class: Provides an exception handling of database operations, and you can get a related return code for operation anomalies. CFIELDEXCHANGE Class: Provides data exchange between user variables and database fields, and if you don't need to use a custom type, you will not need to call the function directly, the MFC Wizard will automatically establish a connection to programmers. 4. Comparison of the two methods, using these two methods can be easily developed in Visual C , and the two methods have their own advantages and disadvantages. Due to the MFC powerful class support, ODBC makes programming makes it very convenient, while portability is also very strong, transplantation between heterogeneous databases simply changes some part of the program, but the implementation mechanism of ODBC It can be seen that the application needs to connect to the ODBC driver manager and the ODBC driver two-layer talents and the database communication interface, and Pro * c is directly connected to the communication interface, so established in ODBC. The execution efficiency of the application is relatively low.

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

New Post(0)