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 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 are formed 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, it is right to form the meaning guest, according to the rank order 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, speech 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 are formed 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, it is right to form the meaning guest, according to the rank order 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, speech 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, promptly orderly meaning guest is right, 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 to learn user right, the magnanimity SQL statement is carried out that merger is handled and to 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 comprises the steps: step S110 for the flow chart of steps of the disposal route embodiment of SQL statement of the present invention, makes up the SQL syntax tree; Step S120 by lexical analysis, extracts action type and database object, and it is right that each action type and database object are formed a meaning guest; 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 handled.
Below above-mentioned each step is further detailed.
In step S130, the order of execution is meant that SQL statement is by the order of the execution of the instruction after compiling in database.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 manipulation 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 visit in which way what table) at this user:
|
update |
delete |
insert |
select |
usertable |
○ |
× |
× |
○ |
Table1 |
○ |
× |
× |
○ |
Table2 |
○ |
× |
× |
○ |
Table3 |
× |
× |
× |
○ |
Table4 |
○ |
○ |
× |
○ |
So at SQL statement
INSERT?INTO?USERTABLE(NAME,AGE)?VALUES(“zhangsan”,24)
INSERT?INTO?USERTABLE(NAME,AGE)VALUES(“lisi”,23)
System can find that producing alarm in violation of rules and regulations does further processing.
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 having only generation to be similar to the database manipulation summary could generate relevant statistics.(2) structure of having only generation to be similar to the database manipulation summary could be judged the judgement at the authority of " can visit what table in which way ".
Below, illustrate in step S140, based on the database manipulation summary magnanimity SQL statement is carried out merger and handle.
What often face at 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 thus database manipulations can corresponding a plurality of database manipulations, 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, based on database manipulation summary the magnanimity SQL statement is carried out the study of merger processing or user right, only be exemplary, the database manipulation summary can also be applied in other occasions, the present invention does not limit 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, the speech section of extracting the character string back is 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 handled.Certainly, being not limited to aforesaid operations, can also be other data processing that the application data base Action Summary carries out.
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, scanning backward again, " AA " of back will be resolved to field by lexical analysis tool, " FROM " meeting is resolved to be the SQL key word, and " TABLE1 " can resolvedly be object (need 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 handled.Certainly, being not limited to aforesaid operations, can also be other data processing that the application data base Action Summary carries out.
The information source of the SQL statement operation here is meant 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, SQL syntax tree structure module 42 is used to make 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 it is right that each action type and database object are formed a meaning guest; 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 handled.Certainly, being not limited to aforesaid operations, can also be other data processing that the application data base Action Summary carries out.
Wherein, the order of execution is meant that SQL statement is by the order of the execution of the instruction after compiling in database.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 comprises: character string scan module 52, action type acquisition module 54, object acquisition module 56 and order module 58 for the structured flowchart of the disposal system embodiment of SQL statement of the present invention.
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 to obtain the key word of database manipulation type, with described key word as the database manipulation type; Object acquisition module 56 is used to extract the speech 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 based on the database manipulation summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is handled.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, scanning backward again, " AA " of back will be resolved to field by lexical analysis tool, " FROM " meeting is resolved to be the SQL key word, and " TABLE1 " can resolvedly be object (need 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 comprises: SQL statement information source determination module 62, context parsing module 64 and order module 66 for the structured flowchart of the disposal system embodiment of SQL statement of the present invention.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 based on the database manipulation summary, comprises the study of user right and the magnanimity SQL statement is carried out the operation that merger is handled.Certainly, being not limited to aforesaid operations, can also be other data processing that the application data base Action Summary carries out.
The information source of the SQL statement operation here is meant 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 the 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, part in specific embodiments and applications all can change.In sum, this description should not be construed as limitation of the present invention.