Summary of the invention
In order to overcome the deficiencies in the prior art, the invention provides a kind of disposal route and system of SQL statement, based on the present invention, can better express the understanding to SQL statement.
On the one hand, the invention discloses a kind of disposal route of SQL statement, described method comprises: analyzing step, SQL statement is resolved to the database manipulation summary, and described database manipulation summary is that database manipulation type and database object form the right ordered set of meaning guest; Wherein, described database manipulation type list shows the mode of database manipulation; Described database object table is shown an entity in the database.
The disposal route of above-mentioned SQL statement, preferred described analyzing step is: make up the SQL syntax tree, by lexical analysis, extract action type and database object, form meaning guest couple, according to the order ordering of carrying out.
The disposal route of above-mentioned SQL statement, preferred described analyzing step is: resolve and grammatical analysis by morphology, carry out character string scanning, obtain the key word of database manipulation type, with described key word as the database manipulation type, word section by extracting the character string back is as the database object part, with after database manipulation type and the pairing of database object coupling, presses execution sequence and sorts.
The disposal route of above-mentioned SQL statement, preferred described analyzing step is:, described analyzing step is: determine to extract the information source of database SQL statement operation, based on context, SQL statement is resolved to described database manipulation type and database object.
On the other hand, the invention also discloses a kind of disposal system of SQL statement, comprise parsing module, be used for SQL statement is resolved to the database manipulation summary that described database manipulation summary is that database manipulation type and database object form the right ordered set of meaning guest; Wherein, described database manipulation type list shows the mode of database manipulation; Described database object table is shown an entity in the database.
The disposal system of above-mentioned SQL statement, preferred described parsing module is used for: make up the SQL syntax tree, resolve and grammatical analysis by morphology, extract action type and database object, form meaning guest couple, according to the order ordering of carrying out.
The disposal system of above-mentioned SQL statement, preferred described parsing module is used for: carry out character string scanning, obtain the key word of database manipulation type, with described key word as the database manipulation type, word section by extracting the character string back is as the database object part, after database manipulation type and the pairing of database object coupling, press the execution sequence ordering.
The disposal system of above-mentioned SQL statement, preferred described parsing module is: determine to extract the information source of database SQL statement operation, based on context, SQL statement is resolved to described database manipulation type and database object.
In terms of existing technologies, the present invention has following advantage:
The first, extract the combination of database manipulation and operand from SQL statement, namely orderly meaning guest couple can better express the understanding to SQL statement; Simultaneously, express database manipulation authority meaning in succinct mode; And, a kind of expression of structurized SQL statement is provided.
The second, the database summary of extraction of the present invention can effectively be used for the study user right, the magnanimity SQL statement is carried out that merger is processed and to the SQL statement field such as classify.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.
The disposal route embodiment of SQL statement
Embodiment one
With reference to Fig. 1, Fig. 1 is the flow chart of steps of the disposal route embodiment of SQL statement of the present invention, comprises the steps: step S110, makes up the SQL syntax tree; Step S120 by lexical analysis, extracts action type and database object, and each action type and database object form a meaning guest couple; Step S130, according to the order of carrying out to a plurality of meaning guests to sorting; Step S140 based on described database manipulation summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is processed.
The below is further detailed above-mentioned each step.
In step S130, the order of execution refers to the order of the execution of instruction in database after SQL statement is compiled.With reference to following example ordering is understood.
The execution sequence of SELECT*FROM TABLE1 UNION SELECT * FROM TABLE2 is:
SELECT*FROM?TABLE1
SELECT*FROM?TABLE2
Below, illustrate in step S140 based on database Action Summary study user right.
For example, through the statistics that the SQL to certain user in the Database Systems makes a summary, can draw the data of following form:
|
update |
delete |
insert |
select |
usertable |
2 |
0 |
2 |
45 |
Table1 |
5 |
0 |
0 |
50 |
Table2 |
6 |
0 |
0 |
60 |
Table3 |
0 |
0 |
0 |
40 |
Table4 |
6 |
3 |
0 |
34 |
If default set the rule of following authority (can access in which way what table) for this user:
|
update |
delete |
insert |
select |
usertable |
○ |
× |
× |
○ |
Table1 |
○ |
× |
× |
○ |
Table2 |
○ |
× |
× |
○ |
Table3 |
× |
× |
× |
○ |
Table4 |
○ |
○ |
× |
○ |
So for SQL statement
INSERT?INTO?USERTABLE(NAME,AGE)?VALUES(“zhangsan”,24)
INSERT?INTO?USERTABLE(NAME,AGE)VALUES(“lisi”,23)
System can find that producing alarm does further processing in violation of rules and regulations.
That is to say that the effect of database manipulation summary is: (1) makes being structured into of SQL statement is possible, and the structure of only having generation to be similar to the database manipulation summary could generate relevant statistics.(2) structure of only having generation to be similar to the database manipulation summary could be judged the judgement for the authority of " can access in which way what table ".
Below, illustrating in step S140, the based on database Action Summary carries out merger to the magnanimity SQL statement to be processed.
What often face for the register system of the daily record of database manipulation is mass data, and the user often only is concerned about the mode of operation of database user and the object of operation, a plurality of database manipulations can corresponding a plurality of database manipulations thus, can alleviate the pressure of storage and retrieval.
Database manipulation for example
Sclcct?password?from?uscrtablc?Whcrc?uscrnamc-‘zhangsan’
Sclcct?password?from?uscrtablc?Whcrc?uscrnamc=‘lisi’
Sclcct?password?from?uscrtablc?Whcrc?uscrnamc=‘wangcrmazi’
Can correspond to:
SELECT?USERTABLE
SQL statement is classified.
Database manipulation
Sclcct?password?from?uscrtablc?Whcrc?uscmamc-‘zhangsan’
Sclcct?password?from?uscrtablc?Whcrc?uscmamc-?
Can correspond to the database manipulation summary: SELECT USERTABLE system can distribute unique ID to this database manipulation summary, and it is designated the classification of " user profile " and so on, embody professional meaning, for the further mining analysis to data lays the first stone.
Need to prove that core of the present invention is to obtain the database manipulation summary, after obtaining this summary, how to carry out the operation of follow-up data based on this database manipulation summary, is not core of the present invention.This embodiment listed, the based on database Action Summary carries out the study of merger processing or user right to the magnanimity SQL statement, only is exemplary, database manipulation summary can also be applied in other occasions, the present invention is not construed as limiting at this.
Embodiment two
With reference to Fig. 2, Fig. 2 is the flow chart of steps of another embodiment of disposal route of SQL statement of the present invention, comprising: step S210, resolve and grammatical analysis by morphology, and carry out character string scanning; Step S220 obtains the key word of database manipulation type, with described key word as the database manipulation type; Step S230 extracts the word section of character string back as database object; Step S240 after database manipulation type and the pairing of database object coupling, sorts by execution sequence.Step S250 based on described database manipulation summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is processed.Certainly, being not limited to aforesaid operations, can also be that other data that the application data base Action Summary carries out are processed.
Below, the acquisition methods of giving one example to above-mentioned database summary is described in detail.
For example: a SQL statement " SELECTAA FROM TABLE1 ";
Can get access to database manipulation type " SELECT " as action type by lexical analysis tool to its scanning, again backward scanning, " AA " of back will be resolved to field by lexical analysis tool, " FROM " can resolvedly be the SQL key word, and " TABLE1 " can resolvedly be object (need to depend on the configuration of lexical analyzer)." SELECT " " TABLE1 " made up to obtain database manipulation summary " (SELECTTABLE1) ".Like this, resolving has just been finished.
Embodiment three
With reference to Fig. 3, Fig. 3 is the flow chart of steps of another embodiment of disposal route of SQL statement of the present invention, comprising: step S310, determine to extract the information source of database SQL statement operation; Based on context step S320, resolves to database manipulation type and database object with SQL statement; Step S330 after database manipulation type and database object coupling, sorts by execution sequence.Step S340 based on described database manipulation summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is processed.Certainly, being not limited to aforesaid operations, can also be that other data that the application data base Action Summary carries out are processed.
The information source of the SQL statement operation here refers to three class database journals:
1) self (file) daily record of database;
2) SQL statement in the databases; With
3) SQL statement that is resolved to of network bypass.
The disposal system embodiment of SQL statement
Embodiment four
With reference to Fig. 4, Fig. 4 is the structured flowchart of the disposal system embodiment of SQL statement of the present invention, comprising: the SQL syntax tree makes up module 42, morphology parsing module 44 and order module 46.Wherein, the SQL syntax tree makes up module 42 for making up the SQL syntax tree; Morphology parsing module 44 is used for resolving and grammatical analysis by morphology, extracts action type and database object, and each action type and database object form a meaning guest couple; Order module 46 according to the order of carrying out to a plurality of meaning guests to sorting.Application module 48 based on described database manipulation summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is processed.Certainly, being not limited to aforesaid operations, can also be that other data that the application data base Action Summary carries out are processed.
Wherein, the order of execution refers to the order of the execution of instruction in database after SQL statement is compiled.With reference to following example ordering is understood.
The execution sequence of SELECT*FROM TABLE1 UNION SELECT * FROM TABLE2 is:
SELECT*FROM?TABLE1
SELECT*FROM?TABLE2
Embodiment five
With reference to Fig. 5, Fig. 5 is the structured flowchart of the disposal system embodiment of SQL statement of the present invention, comprising: character string scan module 52, action type acquisition module 54, object acquisition module 56 and order module 58.
Wherein, character string scan module 52 is used for resolving and grammatical analysis by morphology, carries out character string scanning; Action type acquisition module 54 is used for obtaining the key word of database manipulation type, with described key word as the database manipulation type; Object acquisition module 56 is used for extracting the word section of character string back as database object; Order module 58 is used for sorting by execution sequence after database manipulation type and the pairing of database object coupling.Application module 59 is used for the based on database Action Summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is processed.Below, giving one example is described in detail said system.
For example: a SQL statement " SELECTAA FROM TABLE1 ":
Can get access to database manipulation type " SELECT " as action type by above-mentioned lexical analysis tool to its scanning, again backward scanning, " AA " of back will be resolved to field by lexical analysis tool, " FROM " can resolvedly be the SQL key word, and " TABLE1 " can resolvedly be object (need to depend on the configuration of lexical analyzer)." SELECT " " TABLE1 " made up to obtain database manipulation summary " (SELECTTABLE1) ".Such resolving the simplest is finished.
Embodiment six
With reference to Fig. 6, Fig. 6 is the structured flowchart of the disposal system embodiment of SQL statement of the present invention, comprising: SQL statement information source determination module 62, context parsing module 64 and order module 66.Wherein, SQL statement information source determination module 62 is used for determining to extract the information source of database SQL statement operation; Based on context context parsing module 64 is used for, and SQL statement is resolved to database manipulation type and database object; Order module 66 with database manipulation type and database object coupling after, sort by execution sequence.Application module is used for the based on database Action Summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is processed.Certainly, being not limited to aforesaid operations, can also be that other data that the application data base Action Summary carries out are processed.
The information source of the SQL statement operation here refers to three class database journals:
1) self (file) daily record of database;
2) SQL statement in the databases; With
3) SQL statement that is resolved to of network bypass.
More than disposal route and the system of a kind of SQL statement provided by the present invention described in detail, used specific embodiment herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications.In sum, this description should not be construed as limitation of the present invention.