CN112051991A - General data triggering method based on trigger rule description file - Google Patents
General data triggering method based on trigger rule description file Download PDFInfo
- Publication number
- CN112051991A CN112051991A CN202010766242.7A CN202010766242A CN112051991A CN 112051991 A CN112051991 A CN 112051991A CN 202010766242 A CN202010766242 A CN 202010766242A CN 112051991 A CN112051991 A CN 112051991A
- Authority
- CN
- China
- Prior art keywords
- trigger
- abstract syntax
- data
- syntax tree
- statement
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/205—Parsing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/253—Grammatical analysis; Style critique
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Artificial Intelligence (AREA)
- Computing Systems (AREA)
- Devices For Executing Special Programs (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides a trigger rule description file-based data general trigger method, which is characterized in that a trigger rule is defined in a file, lexical and syntactic analyses are carried out through Lex and Yacc to generate an abstract syntax tree, and then a trigger statement is obtained according to the traversal of a corresponding syntax tree linked list structure of submitted data, so that the triggering of the data is finally realized.
Description
Technical Field
The invention belongs to the technical field of research and application of intelligent power grid power transmission and transformation equipment model data triggering, and particularly relates to a data universal triggering method based on a triggering rule description file.
Background
Commercial database triggers are used in existing systems to achieve data triggering functions. The commercial library trigger mainly completes cascade data triggering and data validity checking, and mainly utilizes the implicit transaction characteristic of the trigger to ensure that modified records and triggered records are submitted in the same transaction, thereby ensuring the integrity of service data. However, as the business logic of the system is diversified, the complexity and the data volume are increased, the excessive use of the database triggers will have negative effects on the aspects of the expansion and portability of the system functions.
For a service scene triggered by power grid equipment model data, the following two schemes are mainly adopted at present:
(1) with traditional relational database triggers, the disadvantages of this approach are: for different databases, the data generation of the same set of service logic is realized, different trigger codes need to be maintained respectively, and the reusability and the transportability are poor;
(2) an application program writes a business data table trigger statement, and submits the business data table trigger statement to a database for execution through the program; the disadvantages of this solution are: in the future, if a triggering table and functions are required to be newly added or modified, the original codes are required to be recompiled and replaced by the original programs, and different scheduling systems have different requirements on individual functions in the later period, so that different codes of different systems are easily generated.
Disclosure of Invention
The purpose of the invention is as follows: in order to solve the problems in the prior art, the invention provides a general data triggering method based on a trigger rule description file, so as to provide an efficient and accurate power grid equipment model data triggering scheme and solve the problems of poor reusability and poor portability of a relational database trigger used in a regulation and control system.
The technical scheme is as follows: a data universal triggering method based on a trigger rule description file comprises the following steps:
step 1: defining trigger rules by adopting a data trigger description language, combining a plurality of trigger rules on a base table to construct a trigger for processing different problems, and embedding the trigger into a functional script language used by an application program;
step 2: when the data trigger service is started, analyzing all triggers to obtain an abstract syntax tree set linked list, wherein the abstract syntax tree set linked list comprises a plurality of abstract syntax trees, and each trigger corresponds to one abstract syntax tree;
and step 3: according to the submitted data, searching whether a corresponding abstract syntax tree exists in an abstract syntax tree set linked list according to the base table name and the trigger type, and traversing the abstract syntax tree set linked list according to the execution sequence and the statement type to obtain a trigger statement if the corresponding abstract syntax tree exists;
and 4, step 4: taking the obtained trigger statement as submitted data, and repeatedly executing the step 3 until the corresponding trigger statement cannot be searched in the abstract syntax tree set linked list;
step 5; and returning all the obtained trigger statements to the client as a set according to the execution sequence.
Further, the syntax format of the trigger is:
CREATE TRIGGER < trigger name > BEFORE | AFTER < trigger event >
ON (base name) FOR ONE ROW
< trigger body >
Wherein < trigger name > indicates the name of the trigger, BEFORE or AFTER indicates whether the trigger fires BEFORE or AFTER executing the trigger statement, < trigger event > indicates the event that fires the trigger, < base table name > indicates the name of the base table of the trigger, and the FOR ONE ROW clause indicates a ONE-line level trigger; the trigger body comprises a variable declaration statement block and a process program block, wherein one or more variable declaration statements are arranged in the variable declaration statement block.
Further, the syntax format of the trigger body is as follows:
< trigger body >:
DECLARE
< variable declaration statement Block >
BEGIN
< program statement Block >
END;
Wherein the variable declaration statement in the variable declaration statement block supports the basic data type and the vernier variable declaration.
Further, the analyzing all triggers in the step 2 to obtain the abstract syntax tree set linked list includes the following steps:
defining an abstract syntax tree construction function;
performing grammar analysis on the trigger through Lex and Yacc to obtain a grammar analysis code file; adopting a grammar parsing code file to construct left and right subtree nodes of an abstract grammar tree;
according to a top-down rule, generating an abstract syntax tree by calling a corresponding abstract syntax tree construction function based on the left and right subtree nodes and the node types;
and defining a node base class ast in all the abstract syntax trees, and connecting the node base class ast with other abstract syntax trees to form an abstract syntax tree set linked list.
Further, the parsing the trigger through Lex and Yacc to obtain a syntax parsing code file specifically includes:
firstly, key reserved words, variable names and numerical values to be analyzed in a lexical language definition trigger of a Lex are used to obtain a lexical analysis code file;
and on the basis of the lexical analysis file, a grammar structure in the trigger is defined through a grammar language of Yacc to obtain a grammar analysis code file.
Has the advantages that: compared with the prior art, the invention has the following advantages:
1. the method is mainly used for embedding the conventional function of the database trigger into the application program, providing a flexible and extensible service logic processing function for the application program, solving the problems of complex database structure, difficult maintenance and the like caused by excessive use of the trigger in a project and improving the extensibility of a system architecture;
2. the method can be used for replacing the traditional commercial database trigger and realizing the function of executing specific operations required by the application program before and after writing the table data;
3. the method is characterized in that a trigger is defined based on a data trigger description language, the data trigger description language is analyzed by using Lex and Yacc, whether a corresponding trigger exists or not is searched according to submitted data, and if the trigger exists, a trigger statement is returned; compared with the traditional commercial database, the reusability and the portability of the data general triggering method based on the trigger rule description file are greatly improved.
Drawings
FIG. 1 is a triggering rule describing a file parsing process of the present invention;
FIG. 2 is a flow chart of the method of the present invention.
Detailed Description
The technical solution of the present invention will be further explained with reference to the accompanying drawings and examples.
The method defines the trigger rule in the file, generates an abstract syntax tree by lexical and syntax analysis through Lex and Yacc, and acquires the trigger statement by traversing the corresponding syntax tree linked list structure according to the submitted data, thereby finally realizing the triggering of the data. As shown in fig. 2, the method specifically includes the following steps:
step 1: defining a trigger rule based on a grammar definition method of a data trigger description language, and realizing basic functions of cascade data trigger and data validity check;
in this step, the data trigger description language is a functional script language independent of the database and embedded in the application program, and provides the application program with the following functions similar to the database trigger, such as the functions of implementing the cascade trigger between the data tables and implementing the table data validity check. The data trigger description language describes the data trigger relationship through a trigger, and the trigger is a data trigger action triggered by operating on the in-line data. The user can create triggers on a base table using trigger definition statements similar to the database. The syntax of the trigger definition statement is as follows:
CREATE TRIGGER < trigger name > BEFORE | AFTER < trigger event >
ON (base name) FOR ONE ROW
< trigger body >
Where < trigger name > indicates the name of the trigger being created. BEFORE or AFTER indicates whether the trigger fires BEFORE or AFTER the trigger statement is executed. < trigger event > indicates the event that triggered the trigger, which may be insert, update or delete. < base table name > indicates the name of the base table of the created trigger. The FOR ONE ROW clause is designated as a single ROW level trigger, which triggers a record corresponding to a statement once, i.e. the statement is required to uniquely match a ROW of records. The user needs to declare variables between eclaree … BEGIN reserved words in the < trigger body >. The syntax format of the trigger body is as follows:
< trigger body >:
DECLARE
< variable declaration statement Block >
BEGIN
< program statement Block >
END;
The < trigger body > contains both variable declaration statement block and procedure block, where there may be no variable declaration statement in the trigger body. The statement block has one or more variable statement statements supporting both base data types and vernier variable statements.
The smallest independent unit in the data trigger description language trigger program is a statement, which may be multi-lined, with a semicolon indicating the end of the statement. Multiple sentences are combined to form a control structure for processing different problems, and the data trigger description language is used for three important control structures: the order, condition, and iteration all provide the corresponding statements. Statements specifically supported by the data trigger description language include: assignment statements, conditional IF statements, loop statements, EXIT statements, RETURN statements, cursor statements, function call statements, print statements, throw exception statements, SQL statements, comment statements, and the like.
Step 2: and (3) analyzing the syntax of the trigger defined in the step (1) based on the Lex and Yacc abstract syntax tree construction method, and constructing and generating an abstract syntax tree.
As shown in fig. 1, the abstract syntax tree construction method based on Lex and Yacc is now described as follows:
lex is a tool that generates a lexical analyzer program. And triggering key reserved words, variable names and numerical values needing to be analyzed in the description language by using special syntax structure definition data of the Lex in the trigger.l file, and then generating a lexical analysis C program file by using a Lex tool.
The Lex source program style is as follows:
%{
definition section/optional, including header file, macro definition, or global C code +
%}
Auxiliary definition section/optional, here macro name/greater/less can be defined for regular expression
%%
The body of the regular section/source program, indispensable, is composed of patterns (FLex regular expressions) and actions (C-codes)
%%
The C language user subprogram section/optional comprises the local C function ^ used by the rule section
Yacc stands for Yet Another Compiler, a tool for generating a parser program, which uses Yacc's syntax language to define the syntax structure of the trigger logic description language in trigger _ parser.
The Yacc source program style is as follows:
%{
assertion section/optional, will be copied as is
%}
Auxiliary definition section/optional, definition grammar related name and attribute-
%%
Syntax rule section/. defines syntax rules and semantic actions, and the production format in yacc is non-terminal: right end { semantic action represented by C statement }. } +
%%
Support function section/optional, including local C function/used by rule section
Lex and Yacc have produced lexical and syntax analysis C program file, only need to include these files while compiling, do not need to quote any other header file or quote other dynamic libraries, therefore can use in a plurality of operating systems such as AIX, HPUX, Linux, etc. A grammar analysis program calls a defined node construction function to a trigger rule matched with a predefined grammar to generate a node pointer, the node construction function takes information of left and right sub-nodes obtained by grammar analysis, the type of the node and the like as parameters of the construction function to generate the node pointer, the node pointer is returned to $, "$" represents a node in an internal stack of a grammar analyzer, the grammar analyzer calls corresponding node construction functions to all the nodes obtained by grammar analysis according to the node type according to a top-down rule, a complete grammar analysis tree is generated step by step from bottom to top, the trigger rule is seen to be specifically defined, the grammar analysis tree has various forms, and the following examples only explain the grammar analysis tree generated aiming at a certain trigger rule: the root node is a function node, the left child node of the root node is a general leading node of all parameters of the function, and the right child node of the root node is a statement node inside the function. And the left child node of the general node of all the parameters of the function is a parameter variable input node, and the right child node of all the parameters of the function is a variable node declared in the function. And the right child node of the statement node in the function is an assignment node.
The pseudo code of the node constructor of the present embodiment is expressed as:
function:CREATE FUNCTION NAME'('paralist')'DECLARE declare_stmt BODY stmt END';'{$$=newfunction($3,$5,$8,$10);}
and step 3: node base class ast is designed in the abstract syntax tree, wherein the node base class ast comprises a node type variable, the node type variable represents node types (variable nodes, assignment statement nodes and the like), other type node pointers are converted into ast nodes through (struct ast) nodes and are pointed by left and right subtree nodes to form a linked list structure of the syntax tree set.
And 4, step 4: when data are submitted, traversing an abstract syntax tree generated by previous syntax analysis, and searching whether corresponding trigger information exists according to the table name and the trigger type; and if so, traversing the corresponding linked list structure according to the execution sequence and the statement type to acquire the corresponding trigger statement information. And the statement generated by triggering is also required to be used as submitted data to search whether cascading triggering exists. And finally, returning the statements generated by triggering as a whole according to the execution sequence.
Example (b):
in this embodiment, the trigger rule description file is defined as follows:
when submitted data operation is to delete data with id 1 in TABLEA, triggering the generated statement as delete from table B where id is '1' according to the rule; delete from table a where id ═ 1'.
Claims (5)
1. A data general triggering method based on a triggering rule description file is characterized in that: the method comprises the following steps:
step 1: defining trigger rules by adopting a data trigger description language, combining a plurality of trigger rules on a base table to construct a trigger for processing different problems, and embedding the trigger into a functional script language used by an application program;
step 2: when the data trigger service is started, analyzing all triggers to obtain an abstract syntax tree set linked list, wherein the abstract syntax tree set linked list comprises a plurality of abstract syntax trees, and each trigger corresponds to one abstract syntax tree;
and step 3: according to the submitted data, searching whether a corresponding abstract syntax tree exists in an abstract syntax tree set linked list according to the base table name and the trigger type, and traversing the abstract syntax tree set linked list according to the execution sequence and the statement type to obtain a trigger statement if the corresponding abstract syntax tree exists;
and 4, step 4: taking the obtained trigger statement as submitted data, and repeatedly executing the step 3 until the corresponding trigger statement cannot be searched in the abstract syntax tree set linked list;
step 5; and returning all the obtained trigger statements to the client as a set according to the execution sequence.
2. The data universal triggering method based on the triggering rule description file according to claim 1, characterized in that: the grammar format of the trigger is as follows:
CREATE TRIGGER < trigger name > BEFORE | AFTER < trigger event >
ON (base name) FOR ONE ROW
< trigger body >
Wherein < trigger name > indicates the name of the trigger, BEFORE or AFTER indicates whether the trigger fires BEFORE or AFTER executing the trigger statement, < trigger event > indicates the event that fires the trigger, < base table name > indicates the name of the base table of the trigger, and the FOR ONE ROW clause indicates a ONE-line level trigger; the trigger body comprises a variable declaration statement block and a process program block, wherein one or more variable declaration statements are arranged in the variable declaration statement block.
3. The data universal triggering method based on the triggering rule description file according to claim 2, characterized in that: the syntax format of the trigger body is as follows:
< trigger body >:
DECLARE
< variable declaration statement Block >
BEGIN
< program statement Block >
END;
Wherein the variable declaration statement in the variable declaration statement block supports the basic data type and the vernier variable declaration.
4. The data universal triggering method based on the triggering rule description file according to claim 1, characterized in that: analyzing all triggers in the step 2 to obtain an abstract syntax tree set linked list, comprising the following steps:
defining an abstract syntax tree construction function;
performing grammar analysis on the trigger through Lex and Yacc to obtain a grammar analysis code file; adopting a grammar parsing code file to construct left and right subtree nodes of an abstract grammar tree;
according to a top-down rule, generating an abstract syntax tree by calling a corresponding abstract syntax tree construction function based on the left and right subtree nodes and the node types;
and defining a node base class ast in all the abstract syntax trees, and connecting the node base class ast with other abstract syntax trees to form an abstract syntax tree set linked list.
5. The data universal triggering method based on the triggering rule description file according to claim 4, characterized in that: the syntax parsing is performed on the trigger through Lex and Yacc to obtain a syntax parsing code file, and the syntax parsing code file specifically comprises the following steps:
firstly, key reserved words, variable names and numerical values to be analyzed in a lexical language definition trigger of a Lex are used to obtain a lexical analysis code file;
and on the basis of the lexical analysis file, a grammar structure in the trigger is defined through a grammar language of Yacc to obtain a grammar analysis code file.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010766242.7A CN112051991B (en) | 2020-08-03 | 2020-08-03 | General data triggering method based on trigger rule description file |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010766242.7A CN112051991B (en) | 2020-08-03 | 2020-08-03 | General data triggering method based on trigger rule description file |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112051991A true CN112051991A (en) | 2020-12-08 |
CN112051991B CN112051991B (en) | 2022-11-11 |
Family
ID=73602259
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010766242.7A Active CN112051991B (en) | 2020-08-03 | 2020-08-03 | General data triggering method based on trigger rule description file |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112051991B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113609845A (en) * | 2021-08-13 | 2021-11-05 | 南京艾科朗克信息科技有限公司 | Method for real-time analysis of template engine |
CN115481932A (en) * | 2022-10-20 | 2022-12-16 | 广州市扬海数码科技有限公司 | ERP system database trigger generation method, storage medium and electronic device |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108377211A (en) * | 2018-01-31 | 2018-08-07 | 湖南戎腾网络科技有限公司 | Dynamic rules chain type recurrence triggering method and its system based on message content perception |
CN111176615A (en) * | 2018-11-12 | 2020-05-19 | 商派软件有限公司 | Trigger and triggering method |
-
2020
- 2020-08-03 CN CN202010766242.7A patent/CN112051991B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108377211A (en) * | 2018-01-31 | 2018-08-07 | 湖南戎腾网络科技有限公司 | Dynamic rules chain type recurrence triggering method and its system based on message content perception |
CN111176615A (en) * | 2018-11-12 | 2020-05-19 | 商派软件有限公司 | Trigger and triggering method |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113609845A (en) * | 2021-08-13 | 2021-11-05 | 南京艾科朗克信息科技有限公司 | Method for real-time analysis of template engine |
CN115481932A (en) * | 2022-10-20 | 2022-12-16 | 广州市扬海数码科技有限公司 | ERP system database trigger generation method, storage medium and electronic device |
Also Published As
Publication number | Publication date |
---|---|
CN112051991B (en) | 2022-11-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Singh et al. | Transforming spreadsheet data types using examples | |
Chen et al. | The C information abstraction system | |
US8516458B2 (en) | System representation and handling techniques | |
Caballero et al. | A survey of algorithmic debugging | |
Chin et al. | Yedalog: Exploring knowledge at scale | |
CN112051991B (en) | General data triggering method based on trigger rule description file | |
Mitschke et al. | i3QL: Language-integrated live data views | |
US11294665B1 (en) | Computerized software version control with a software database and a human database | |
Gao et al. | Feedback-driven semi-supervised synthesis of program transformations | |
Hirn et al. | PL/SQL Without the PL | |
CN111367893A (en) | Method and device for database version iteration | |
Strein et al. | An extensible meta-model for program analysis | |
CN115757462A (en) | Object-oriented database dynamic interface generation method and operation method | |
Fegaras et al. | Compile-time code generation for embedded data-intensive query languages | |
Panchenko et al. | Precise and scalable querying of syntactical source code patterns using sample code snippets and a database | |
US10409815B2 (en) | SQLScript compilation tracing system | |
EP2096534A1 (en) | System representation and handling techniques | |
Hanus et al. | A typeful integration of SQL into Curry | |
Rompf et al. | A SQL to C compiler in 500 lines of code | |
CA2714189C (en) | System representation and handling techniques | |
Marin et al. | Towards a framework for generating program dependence graphs from source code | |
WO2022098253A1 (en) | System and method for creating and executing highly scaled cloud applications | |
Courtney et al. | Vetting anti-patterns in Java to Kotlin translation | |
Ivan | Building a fast in-memory database using efficient query compilation and a tuned data-centric IR | |
Hirzel et al. | Streams that compose using macros that oblige |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |