CN104252511A - SQL (Structural Query Language) command compiling method and SQL command compiling device - Google Patents
SQL (Structural Query Language) command compiling method and SQL command compiling device Download PDFInfo
- Publication number
- CN104252511A CN104252511A CN201310538677.6A CN201310538677A CN104252511A CN 104252511 A CN104252511 A CN 104252511A CN 201310538677 A CN201310538677 A CN 201310538677A CN 104252511 A CN104252511 A CN 104252511A
- Authority
- CN
- China
- Prior art keywords
- grammar rule
- syntax tree
- abstract syntax
- sql command
- sql
- 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.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides an SQL (Structural Query Language) command compiling method which comprises the following steps: acquiring an abstract syntax tree corresponding to an inquiry command; compiling the abstract syntax tree according to preset grammar rules so as to obtain an SQL command conforming to the grammar rules. The embodiment of the invention also provides a corresponding device. According to the method, grammar rules of a database management system of a belonged database are acquired, then a dialect SQL command which is resolved into the abstract syntax tree is compiled according to management rules, and thus the SQL command conforming to the grammar rules is formed, so that different database management systems are inquired by virtue of SQL commands conforming to other rules.
Description
Technical field
The application relates to database management technology field, particularly relates to a kind of sql command Compilation Method and device.
Background technology
Data base management system (DBMS) has multiple kind, such as ORACLE, SQL Server, MySQL, PostgreSQL, DB2, Sybase, Teradata and SQLite; Sql command can be adopted to inquire about the inquiry of database, this SQL has unified standard, but each data base management system (DBMS) does not strictly observe this standard, to cause in some details the sql command that can be identified in a data base management system (DBMS) wherein, be not identified in other data base management system (DBMS).
In order to address this problem, if data base administrator needs the database managing multiple kind, then must the data base management system (DBMS) that each is managed all be known about, otherwise there will be management input such as the sql command of ORACLE system by the nonrecognition of DB2 system, thus inoperable situation.If keeper needs to carry out inquiring about for DB2, must understand the syntax gauge of DB2.Cause operation inconvenience, manage relatively loaded down with trivial details.Need a kind ofly to become the method for the discernible sql command of each data base management system (DBMS) by other sql command of automatic compiling.
Summary of the invention
Technical problems to be solved in this application are to provide a kind of method and apparatus according to affiliated database grammar rule compiling sql command.
In order to solve the problem, this application discloses a kind of sql command Compilation Method, comprising:
Obtain the abstract syntax tree that querying command is corresponding;
Compile described abstract syntax tree according to preset grammar rule and obtain the sql command meeting described grammar rule.
Further, described compiling before the acquisition of described abstract syntax tree meets the sql command of described grammar rule according to preset grammar rule also comprises:
The grammar rule of data base management system (DBMS) belonging to obtaining.
Further, also comprise before the abstract syntax tree that described acquisition querying command is corresponding:
Obtain the sql command of other grammar rule or standard grammar rule;
The sql command of resolving other grammar rule described or standard grammar rule obtains abstract syntax tree.
Further, describedly obtain according to grammar rule compiling abstract syntax tree the sql command meeting described grammar rule and comprise:
Described abstract syntax tree is configured according to current grammar rule;
Abstract syntax tree after editor's configuration obtains the sql command meeting current grammar rule.
Present invention also provides a kind of sql command compilation device, comprising:
Syntax tree acquisition module, for obtaining abstract syntax tree corresponding to querying command;
Collector, obtains for compiling described abstract syntax tree according to preset grammar rule the sql command meeting described grammar rule.
Further, described device also comprises:
Rule acquisition module, for obtaining the grammar rule of affiliated data base management system (DBMS).
Further, described device also comprises:
Order acquisition module, for obtaining the sql command of other grammar rule or standard grammar rule;
Parsing module, obtains abstract syntax tree for the sql command of resolving other grammar rule described or standard grammar rule.
Further, described collector also for:
Described abstract syntax tree is configured according to current grammar rule;
Abstract syntax tree after editor's configuration obtains the sql command meeting current grammar rule.
Compared with prior art, the application comprises following advantage: by obtaining the grammar rule of affiliated wide area information server management system in advance, then the dialect sql command of abstract syntax tree has been resolved into according to the compiling of this rule, form the sql command meeting this grammar rule, achieve Else Rule sql command inquiry different pieces of information base management system.
accompanying drawing explanation
Fig. 1 is the process flow diagram of a kind of sql command Compilation Method one of the present invention embodiment;
Fig. 2 is the structural representation of a kind of sql command compilation device one of the present invention embodiment.
Embodiment
For enabling above-mentioned purpose, the feature and advantage of the application more become apparent, below in conjunction with the drawings and specific embodiments, the application is described in further detail.
With reference to Fig. 1, show the process flow diagram of a kind of sql command Compilation Method one of the application embodiment.
A kind of sql command Compilation Method that the present embodiment provides, comprising:
Step S101, the abstract syntax tree that acquisition querying command is corresponding;
Further, described compiling before the acquisition of described abstract syntax tree meets the sql command of described grammar rule according to preset grammar rule also comprises:
The grammar rule of data base management system (DBMS) belonging to obtaining.
Further, also comprise before the abstract syntax tree that described acquisition querying command is corresponding:
Obtain the sql command of other grammar rule or standard grammar rule;
The sql command of resolving other grammar rule described or standard grammar rule obtains abstract syntax tree.
In embodiments of the present invention, the grammatical rule of data base management system (DBMS) need be got in advance, the such as embodiment of the present invention is applied in DB2, then need the grammar rule getting DB2 in advance, the sql command of the user then obtained input can be the sql command that user inputs according to stsndard SQL rule or other data base management system (DBMS) grammar rule.Need after getting this sql command first to resolve to abstract syntax tree.
Step S102, to compile described abstract syntax tree according to preset grammar rule and obtain the sql command meeting described grammar rule.
Further, describedly obtain according to grammar rule compiling abstract syntax tree the sql command meeting described grammar rule and comprise:
Described abstract syntax tree is configured according to current grammar rule;
Abstract syntax tree after editor's configuration obtains the sql command meeting current grammar rule.
For abstract syntax tree, according to the database grammar rule obtained in advance, recompilate this abstract syntax tree, the sql command obtained after compiling meets this database grammar rule.
In embodiments of the present invention, if input stsndard SQL order for user need be compiled into DB2 database grammar rule sql command, after getting stsndard SQL order, be first abstract syntax tree by this stsndard SQL command analysis, then this abstract syntax tree is compiled according to DB2 grammar rule, get the sql command meeting DB2 grammar rule.
The embodiment of the present invention, by carrying out the compiling of abstract syntax tree according to the grammar rule of affiliated database, is formed and meets the expensive sql command of the affiliated database syntax, achieve the application of different sql command in disparate databases.
With reference to the structural representation that Fig. 2 is a kind of sql command compilation device one of the present invention embodiment.
A kind of sql command compilation device that the application provides, comprising:
Syntax tree acquisition module 21, for obtaining abstract syntax tree corresponding to querying command;
Collector 22, obtains for compiling described abstract syntax tree according to preset grammar rule the sql command meeting described grammar rule.
Further, described device also comprises:
Rule acquisition module 23, for obtaining the grammar rule of affiliated data base management system (DBMS).
Further, described device also comprises:
Order acquisition module 24, for obtaining the sql command of other grammar rule or standard grammar rule;
Parsing module 25, obtains abstract syntax tree for the sql command of resolving other grammar rule described or standard grammar rule.
Further, described collector 22 also for:
Described abstract syntax tree is configured according to current grammar rule;
Abstract syntax tree after editor's configuration obtains the sql command meeting current grammar rule.
In embodiments of the present invention, rule acquisition module 23 need get the grammatical rule of data base management system (DBMS) in advance, the such as embodiment of the present invention is applied in DB2, rule acquisition module 23 need get the grammar rule of DB2 in advance, and the sql command that the user that then order acquisition module 24 obtains inputs can be the sql command that user inputs according to stsndard SQL rule or other data base management system (DBMS) grammar rule.After order acquisition module 24 gets this sql command, parsing module 12 first need resolve to abstract syntax tree.
For abstract syntax tree, collector 22, according to the database grammar rule obtained in advance, recompilates this abstract syntax tree, and the sql command obtained after compiling meets this database grammar rule.
For device embodiment, due to itself and embodiment of the method basic simlarity, so description is fairly simple, relevant part illustrates see the part of embodiment of the method.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, between each embodiment identical similar part mutually see.
Above to a kind of sql command Compilation Method that the application provides, be described in detail, apply specific case herein to set forth the principle of the application and embodiment, the explanation of above embodiment is just for helping method and the core concept thereof of understanding the application; Meanwhile, for one of ordinary skill in the art, according to the thought of the application, all will change in specific embodiments and applications, in sum, this description should not be construed as the restriction to the application.
Claims (8)
1. a sql command Compilation Method, is characterized in that, comprising:
Obtain the abstract syntax tree that querying command is corresponding;
Compile described abstract syntax tree according to preset grammar rule and obtain the sql command meeting described grammar rule.
2. method according to claim 1, is characterized in that, described compiling before the acquisition of described abstract syntax tree meets the sql command of described grammar rule according to preset grammar rule also comprises:
The grammar rule of data base management system (DBMS) belonging to obtaining.
3. method according to claim 2, is characterized in that, also comprises before the abstract syntax tree that described acquisition querying command is corresponding:
Obtain the sql command of other grammar rule or standard grammar rule;
The sql command of resolving other grammar rule described or standard grammar rule obtains abstract syntax tree.
4. method according to claim 3, is characterized in that, describedly obtains according to grammar rule compiling abstract syntax tree the sql command meeting described grammar rule and comprises:
Described abstract syntax tree is configured according to current grammar rule;
Abstract syntax tree after editor's configuration obtains the sql command meeting current grammar rule.
5. a sql command compilation device, is characterized in that, comprising:
Syntax tree acquisition module, for obtaining abstract syntax tree corresponding to querying command;
Collector, obtains for compiling described abstract syntax tree according to preset grammar rule the sql command meeting described grammar rule.
6. device according to claim 5, is characterized in that, described device also comprises:
Rule acquisition module, for obtaining the grammar rule of affiliated data base management system (DBMS).
7. device according to claim 6, is characterized in that, described device also comprises:
Order acquisition module, for obtaining the sql command of other grammar rule or standard grammar rule;
Parsing module, obtains abstract syntax tree for the sql command of resolving other grammar rule described or standard grammar rule.
8. device according to claim 7, is characterized in that, described collector also for:
Described abstract syntax tree is configured according to current grammar rule;
Abstract syntax tree after editor's configuration obtains the sql command meeting current grammar rule.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310538677.6A CN104252511A (en) | 2013-11-05 | 2013-11-05 | SQL (Structural Query Language) command compiling method and SQL command compiling device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310538677.6A CN104252511A (en) | 2013-11-05 | 2013-11-05 | SQL (Structural Query Language) command compiling method and SQL command compiling device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN104252511A true CN104252511A (en) | 2014-12-31 |
Family
ID=52187404
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310538677.6A Pending CN104252511A (en) | 2013-11-05 | 2013-11-05 | SQL (Structural Query Language) command compiling method and SQL command compiling device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104252511A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105912607A (en) * | 2016-04-06 | 2016-08-31 | 普强信息技术(北京)有限公司 | Grammar rule based classification method |
CN108536728A (en) * | 2018-02-24 | 2018-09-14 | 国家计算机网络与信息安全管理中心 | A kind of data query method and apparatus |
CN110413646A (en) * | 2019-06-28 | 2019-11-05 | 阿里巴巴集团控股有限公司 | Method and apparatus based on preset rules screening user |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20090094216A1 (en) * | 2006-06-23 | 2009-04-09 | International Business Machines Corporation | Database query language transformation method, transformation apparatus and database query system |
CN102073490A (en) * | 2009-11-25 | 2011-05-25 | 阿里巴巴集团控股有限公司 | Method and device for translating database language |
CN102185930A (en) * | 2011-06-09 | 2011-09-14 | 北京理工大学 | Method for detecting SQL (structured query language) injection vulnerability |
CN102521008A (en) * | 2011-12-28 | 2012-06-27 | 用友软件股份有限公司 | Program compiling device and method for compiling program |
CN102609451A (en) * | 2012-01-11 | 2012-07-25 | 华中科技大学 | SQL (structured query language) query plan generation method oriented to streaming data processing |
CN102768682A (en) * | 2012-06-28 | 2012-11-07 | 用友软件股份有限公司 | Business rule processing device and business rule processing method |
CN102867045A (en) * | 2012-09-05 | 2013-01-09 | 武汉达梦数据库有限公司 | Method and system for realizing compatibility of heterogeneous database reserved words based on driver layer |
CN103186541A (en) * | 2011-12-27 | 2013-07-03 | 阿里巴巴集团控股有限公司 | Generation method and device for mapping relationship |
-
2013
- 2013-11-05 CN CN201310538677.6A patent/CN104252511A/en active Pending
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20090094216A1 (en) * | 2006-06-23 | 2009-04-09 | International Business Machines Corporation | Database query language transformation method, transformation apparatus and database query system |
CN102073490A (en) * | 2009-11-25 | 2011-05-25 | 阿里巴巴集团控股有限公司 | Method and device for translating database language |
CN102185930A (en) * | 2011-06-09 | 2011-09-14 | 北京理工大学 | Method for detecting SQL (structured query language) injection vulnerability |
CN103186541A (en) * | 2011-12-27 | 2013-07-03 | 阿里巴巴集团控股有限公司 | Generation method and device for mapping relationship |
CN102521008A (en) * | 2011-12-28 | 2012-06-27 | 用友软件股份有限公司 | Program compiling device and method for compiling program |
CN102609451A (en) * | 2012-01-11 | 2012-07-25 | 华中科技大学 | SQL (structured query language) query plan generation method oriented to streaming data processing |
CN102768682A (en) * | 2012-06-28 | 2012-11-07 | 用友软件股份有限公司 | Business rule processing device and business rule processing method |
CN102867045A (en) * | 2012-09-05 | 2013-01-09 | 武汉达梦数据库有限公司 | Method and system for realizing compatibility of heterogeneous database reserved words based on driver layer |
Non-Patent Citations (2)
Title |
---|
周雅倩 等: "自底向上和自顶向下结合的句法分析", 《863计划智能计算机主题学术会议论文集》 * |
孙兆玉 等: "一种SQL语法分析的策略和实现", 《计算机应用》 * |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105912607A (en) * | 2016-04-06 | 2016-08-31 | 普强信息技术(北京)有限公司 | Grammar rule based classification method |
CN108536728A (en) * | 2018-02-24 | 2018-09-14 | 国家计算机网络与信息安全管理中心 | A kind of data query method and apparatus |
CN110413646A (en) * | 2019-06-28 | 2019-11-05 | 阿里巴巴集团控股有限公司 | Method and apparatus based on preset rules screening user |
CN110413646B (en) * | 2019-06-28 | 2023-05-12 | 创新先进技术有限公司 | Method and device for screening users based on preset rules |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105260403B (en) | General integration across database access method | |
CN103699638B (en) | Method for realizing cross-database type synchronous data based on configuration parameters | |
CN104965735A (en) | Apparatus for generating upgrade SQL script | |
CN104252510A (en) | SQL (Structural Query Language) language translation method and SQL language translation device | |
US20130138681A1 (en) | Method and system for metadata driven processing of federated data | |
CN103617176A (en) | Method for achieving automatic synchronization of multi-source heterogeneous data resources | |
CN112579626A (en) | Construction method and device of multi-source heterogeneous SQL query engine | |
CN108052635A (en) | A kind of heterogeneous data source unifies conjunctive query method | |
CN103678532A (en) | Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system | |
CN103234549B (en) | A kind of differential data generation method for upgrading map | |
CN105335479A (en) | Text data statistics realization method based on SQL | |
CN102750354B (en) | Method for analyzing and processing non-structured data query operating language | |
CN103246704A (en) | Mapping method for describing entity and relational data based on conventional data structure | |
US20210250218A1 (en) | Abstraction layer for streaming data sources | |
US9053207B2 (en) | Adaptive query expression builder for an on-demand data service | |
CN104462351A (en) | Data query model and method for MapReduce pattern | |
CN104252511A (en) | SQL (Structural Query Language) command compiling method and SQL command compiling device | |
CN116804994B (en) | Data synchronization method, system, device, electronic equipment and storage medium | |
CN105373621A (en) | Rapid database-system-across data increment migration method | |
CN108763323B (en) | Meteorological grid point file application method based on resource set and big data technology | |
CN104462361A (en) | Method and device for matching data in data table | |
CN113688148B (en) | Urban rail data query method and device, electronic equipment and readable storage medium | |
CN103927402A (en) | Control logic diagram modular design management system implementation method | |
CN105045912A (en) | Relational database data distribution method | |
CN103593182A (en) | Method for reconfiguring software by using clustering mode |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20141231 |
|
RJ01 | Rejection of invention patent application after publication |