免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1985 | 回复: 0
打印 上一主题 下一主题

Zql: a Java SQL parser [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-25 15:42 |只看该作者 |倒序浏览

Zql: a Java SQL parser
What is Zql ?
Zql is a SQL parser written in Java.
Zql parses SQL and fills in java structures representing SQL statements and
expressions.
Zql can parse all the queries given as examples in the following
SQL tutorial
(downloaded from
geocities.com
).
See the Zql
API documentation
for more info about
the Zql structures.
A SQL expression evaluator comes with Zql, so you can easily evaluate
SQL expressions out of the parser.
Warning: No warranty !
Zql is no commercial product: feel free to use it, but we provide
no warranty.
Zql APIs may be subject to changes, to enrich functionalities or fix bugs.
[email=pierreyves.gibello@experlog.com?subject=Zql]Click here[/email]
for any bug report or suggestion.
How to use Zql ?
First of all,
download Zql!
Then:


  • Unpack Zql.tar: tar xvf Zql.tar (or use WinZip if you are a Windows user).

  • Make your CLASSPATH variable point on the Zql/classes directory.

  • Type java Zql.ZqlParser, then some SQL statements (like
    select * from customer;) to make sure Zql is properly installed.

  • Go in the Zql/demo directory, see the README file and the ZDemo.java program
    to discover how you can use Zql to write your own SQL application!

Some SQL queries for heavy testing...
Note that java sources are NOT provided in the package, but you can
contact me concerning the availability, licensing terms and conditions.
More details
The parser itself is written with
JavaCC
, a Java parser generator (like
Unix's popular yacc generator).
It takes as input SQL statements (select, insert, update, delete, commit,
rollback, set transaction), and fills in Java structures that represent the
statements it parsed.
Example:
SELECT ANTIQUEOWNERS.OWNERLASTNAME, ANTIQUEOWNERS.OWNERFIRSTNAME
FROM ANTIQUEOWNERS, ANTIQUES
WHERE ANTIQUES.BUYERID = ANTIQUEOWNERS.OWNERID AND ANTIQUES.ITEM = 'Chair';
Will result in a ZqlQuery structure.
ZqlQuery's getSelect(), getFrom() and getWhere() methods will extract the
SELECT, FROM and WHERE parts of the query.


  • getSelect() will return a Vector of ZSelectItem, data structures that give
    information about the columns and/or operations requested (including
    SQL expression support, like in SELECT a+b FROM num;).

  • getFrom() will return a Vector of ZFromItem, data structures that give
    information about the tables involved in the query.

  • getWhere() will return a SQL expression, a data structure that represents
    ANTIQUES.BUYERID = ANTIQUEOWNERS.OWNERID AND ANTIQUES.ITEM = 'Chair'
    in the example above (the expression evaluator that comes with
    Zql can evaluate such expressions, for a given data tuple).

               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/79955/showart_1879005.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP