Research on Key Technology of GKD-BASE PL / SQL Engine

Abstract: A PL / SQL engine compatible with Oracle PL / SQL V2.3 language specification is designed and implemented on the database management system GKD-BASE, which extends the GKD-BASE process processing function.

GKD-BASE database is a database management system with independent intellectual property rights, with SQL engine compatible with SQL89 standard, which can provide users with a unified and effective database access interface to achieve various operations on the database. However, the SQL language lacks the ability to describe algorithms, which makes it difficult to perform complex programming. In order to integrate the powerful collection data processing capabilities of the SQL language and the flexible process processing capabilities of the third generation language (3GL), mainstream database management system products have provided support for procedural SQL languages, such as Oracle's PL / SQL [1] . In order to adapt GKD-BASE to the development status and meet the needs of managers and developers, it is urgent to develop GKD-BASE's own PL / SQL engine.

This paper designs and implements a PL / SOL engine compatible with Oracle PL / SQL V2.3 language specification on the database management system GKD-BASE, which extends the GKD-BASE process processing function.

1 Architecture of GKD-BASE PL / SQL engine

The basic function of GKD-BASE PL / SQL engine is to analyze the program written by the user in PL / SQL language through lexical analysis program and grammatical analysis program, generate intermediate code and explain and execute it. If errors are found in the analysis phase or the interpretation execution phase, the error number and corresponding error information are reported to the user so that the user can troubleshoot [2]. According to the characteristics of PL / SQL language with both procedural statements and SQL statements, a divide-and-conquer strategy is adopted to separate procedural statements and SQL statements. When the PL / SQL engine compiles and executes the PL / SQL source program, it first performs preprocessing to separate the SQL statement and the procedural statement; then it parses the SQL statement and the procedural statement separately to generate a syntax tree; and finally executes the intermediate code through the execution module Explain execution.

figure 1

The GKD-BASE PL / SQL engine compiles the source code to generate intermediate code, which cannot be executed directly on the target machine. An environment for interpreting the intermediate code is required to provide support for the data types in the PL / SQL language to ensure the correct PL / SQL carried out. Therefore, the GKD-BASE PL / SQL engine can be divided into two parts: compiler and interpreter, as shown in Figure 1. The compiler performs preprocessing after receiving the PL / SQL statement block, and divides the sentence into a SQL statement and a procedural statement. For SQL statements, the compiler establishes SQL statement nodes and performs corresponding variable binding and grammar checks; intermediate codes are generated after the checks are correct. For procedural statements, the compiler grammatically analyzes the statement components and establishes the corresponding symbol table, and also generates intermediate code. Therefore, the compiler can be divided into modules such as SQL language analysis, procedural language analysis, symbol table generation and management, and intermediate code representation and management. The role of the interpreter is to interpret and execute the intermediate code generated by the compiler [3], corresponding to the compiler, with independent SQL statement interpretation module and procedure statement interpretation module. The interpreter also includes management of the execution state stack and a call interface with the GKD-BASESQL engine. The exception handling module mainly implements error checking and reporting while the program is running, and supports user-defined exceptions and pre-defined exception checking and handling.

2 Some key issues in the implementation of GKD-BASE PL / SQL compiler

The GKD-BASE PL / SQL compiler mainly performs lexical analysis, grammatical analysis and semantic processing on the PL / SQL source program [4]. This article uses the Lex to build the lexical analyzer and the automatic generation tool Yacc [5] to compile the PL / SQL source program. The following describes the design and management of the symbol table, SQL statement analysis and cursor analysis.

2.1 Design and management of symbol table

The symbol table is a database that contains information about variables, custom types, and functions in the program. The index corresponds to a record in the library; each record corresponds to the information of an object, such as the type of variable or the return value of the function [2].

Considering the block structure and name scope of the PL / SQL language, you can use the name stack to store the index, name, and type of the identifier used in the source program. Each item only includes the name itself and the flag value used to indicate its type, and the item index of the name in the symbol table. The name stack adopts a hierarchical structure, which is a linked list stack. Each layer of the stack stores all the name information in the nested layer of the parsed statement blocks, as shown in Figure 2. When entering or exiting a nested layer, the corresponding push and pop operations are called; when searching for symbols, search from the top to the bottom of the stack. The name stack implements the mapping between the name of the marker and the corresponding index of the symbol table, solves the problem of the scope and visibility of the marker, and meets the requirements for the management and calling of the symbol table.

2.2 Analysis of SQL statements

In order to avoid syntax errors in the execution of SQL statements, you need to check the correctness of their syntax in advance. SQL statements are a collection-oriented data manipulation language that can only be handled by the SQL engine. However, in order to enhance the interactive ability of SQL statements and procedural statements, the PL / SQL language introduces variables in the SQL statements. The SQL engine of GKD-BASE cannot recognize them. The variables must be extracted before submission and replaced with a format recognized by the SQL engine. Such as: SELECT empno, name INTO v_empno, v_name FROM empWHERE birthday = v_date;

This SELECT statement first binds the variable v_date to the column name birthday, and then finds the corresponding result (empno, name) according to the condition, and assigns it to the pre-defined variable (v_empno, v_name). For the SQL engine of GKD-BASE, only SELECT statements in the following format can be recognized:

SELECT empno, name INTO: v_empno ,: v_nameFROM emp WHERE birthday =: 1;

Before submitting the SQL statement to the GKD-BASE SQL engine for processing, the variables v_empno, v_name, and v_date are identified for format conversion, and ":" is added before the variable after the into. Construct a statement that meets the requirements of the SQL engine; after completing these processes, submit the new statement as a character string to the SQL engine for syntax analysis to check whether the syntax of the statement is correct and whether the variables in the statement match the corresponding columns; Finally return the result, report an error or generate a syntax tree.

2.3 Analysis of cursor

A cursor is a handle or pointer to a context area in memory. With the help of cursors, PL / SQL programs can control the changes of the cursors in the context area and statement processing. PL / SQL cursors can be divided into explicit cursors and implicit cursors according to their usage.

The use of explicit cursors includes four steps: declaring cursors, opening cursors, cursor retrieval, and closing cursors. When compiling the cursor declaration statement, first call the SQL engine to analyze the SQL statement components, convert to a format recognized by the SQL engine, and add the cursor index information to the name stack and symbol table. The cursor open operation searches for the cursor name in the name stack, obtains the relevant information saved in the symbol table at the declaration stage, and adds it to the syntax tree. The compilation of the cursor retrieval statement first obtains the information of the cursor's symbol table; then associates the information of the SQL statement in the cursor with the information of the value variable linked list, checks whether the cursor variable and the cursor reference column match; finally saves the relevant information, and adds the syntax tree. The closing operation of the cursor releases resources and initializes the cursor state, saves the information of the cursor in the symbol table and adds it to the syntax tree.

Implicit cursors are generally used to process DML statements. Each DML statement corresponds to an implicit cursor, which can be handled as a general SQL statement when compiling, and directly call the SQL engine of GKD-BASE to compile it. Cursor processing of these statements is done automatically by the SQL engine and does not require PL / SQL engine intervention.

image 3

3 Some key issues in the implementation of GKD-BASE PL / SQL interpreter

The key issues in the implementation of the interpreter are the execution of statements, the design of the execution state stack, and the processing of return values.

For the execution of statements, it can be divided into two parts: SQL statement execution and procedure statement execution. Write functions to complete the interpretation tasks according to the corresponding nodes on the syntax tree. There is also a tree-like hierarchical call structure between these function routines, and the interpretation execution of the root of the tree depends on the successful operation of the interpretation function of each node in its subtree.

In the interpreter of the GKD-BASE PL / SQL engine, a data structure of "execution status" is designed to record the execution status information of the function. All interpreter functions in the interpreter have a pointer parameter to this structure, and the information that needs to be passed between these functions will be copied to this structure. When the PL / SQL engine calls a subroutine, it constructs an "execution state stack." Before the call, save the scene and push the execution state onto the stack; after the call ends, restore the scene, pop up the current execution state, and return to the previous layer to continue, as shown in Figure 3.

After the execution of the statement block is completed, the interpreter will give three types of return status according to the situation: ok, exit, return. When a procedure statement or SQL statement is executed normally, it returns ok; or when all statements in the current layer of the execution state are executed normally, it returns ok to the upper layer. When the EXIT keyword is encountered during execution, if the exit label in the execution state is the same as the exit label in the input parameter, it means normal exit and return to exit. When the RETURN keyword is encountered during execution, it indicates that all statements in the statement chain have been executed and returns. Until the top level of the execution state is reached and the return value is given, the entire interpretation execution process is ended.

Outdoor LED Screen

Outdoor Led Screen,Outdoor Waterproof Led Screen,Waterproof Led Screen,Outdoor Led Display Screen

ALLIN , https://www.displayapio.com

Posted on