Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is JsqlParse?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about what is JsqlParse. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

JsqlParse is a basic tool that generates the syntax and morphology of sql through the program javaCC. There are two functions, 1 is to parse sql to java objects, and 2 is to generate sql after building java objects according to allowed rules and hierarchies.

JsqlParse is a basic tool because it only has parsing and generating functions, without any business or specific functions. For example, the sql of Select a From myTable where b = 1001 limit 1 java 10 is mechanically parsed into a query java object, and then the object contains the field name of the query, the table name of the query, the condition of the query, and the content of the limit, regardless of if this is oracle paging, sql is wrong. Similarly, if you build a paging query object, if you need paging, mysql will fill itself with the contents of limit, and oralce will wrap the query on its own, and the writing of mysql and oracle cannot be converted. Because JsqlParse doesn't know anything at all and can only translate literally.

This tool is very basic, it is a good tool for functions that require sql parsing, but the functionality is too basic. Need to do a lot of functional packaging in the outer layer, if there is time, I intend to do a layer of packaging according to the current project requirements. At present, it is not possible, the project time is tight, find another way.

Source code analysis, this tool uses the visitor design pattern throughout, all the functions are clustered with visitor pattern. For example, the first step, statement type (statement), defines statementVisitor, and all types add visit methods. And all visit are not implemented, the default is a string, there is no business processing. Another example is the query statement body (selectBody), which defines selectBodyVisitor.

Source code analysis, JsqlParse content is simple, from the package naming point of view, expression,parser,schema,statement,util plus an Exception class. Parser parser, schema simple object class, statement statement analysis, expression expression function.

Use only one sentence, Statement sqlStmt = CCJSqlParserUtil.parse (new StringReader (sql)); after parsing, you can take each part of the content corresponding to the specific type.

The above is the editor for you to share what is JsqlParse, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report