输出:

select
a.f1,
b.f2
from
table01 a,
(
select
a
from
tb
)
b
where
a.f1=1 and
b.f2=2 or
b.f3=3
order by
a.f1,
b.f2 Text Depth Parent Prev Next Child Cnt
------------------------------------------------------------------------------------
NULL 0 NULL NULL NULL 4
select 0 null NULL from 3
a.f1 1 select NULL , 0
, 1 select a.f1 b.f2 0
b.f2 1 select , NULL 0
from 0 null select where 3
table01 a 1 from NULL , 0
, 1 from table01 a null 0
NULL 1 from , NULL 4
( 1 null NULL null 0
NULL 1 null ( ) 2
select 2 null NULL from 1
a 3 select NULL NULL 0
from 2 null select NULL 1
tb 3 from NULL NULL 0
) 1 null null b 0
b 1 null ) NULL 0
where 0 null from order by 5
a.f1=1 1 where NULL and 0
and 1 where a.f1=1 b.f2=2 0
b.f2=2 1 where and or 0
or 1 where b.f2=2 b.f3=3 0
b.f3=3 1 where or NULL 0
order by 0 null where NULL 3
a.f1 1 order by NULL , 0
, 1 order by a.f1 b.f2 0
b.f2 1 order by , NULL 0

程序:

package com.heyang.easysql.nod05;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List; /**
* Sql Node v1.05
* @author Heyang
*
*/
public class Node {
private static final String FOUR_SPACE = " ";
private static final String ONE_SPACE = " ";
private String text=null;
private int depth=0;
private Node parent=null;
private Node prev=null;
private Node next=null;
private List<Node> children=null;
public static final int TYPE_NORMAL=1;
public static final int TYPE_JOINT=2;
public static final int TYPE_TRANSPARENT=3;
private int type=TYPE_NORMAL; public Node() { } public Node(int type) {
this.type=type;
} public Node(String text) {
this.text=text;
} public Node(String text,int type) {
this.text=text;
this.type=type;
} public boolean isLeaf() {
return children==null || children.size()==0;
} private List<Node> addChild(Node child) {
if(children==null) {
children=new ArrayList<Node>();
} if(children.size()>0) {
Node last=children.get(children.size()-1);
last.next=child;
child.prev=last;
} child.parent=this;
child.depth=this.depth+(this.type==TYPE_TRANSPARENT?0:1); children.add(child);
adjustDepth(); return children;
} private String getIndentSpace() {
return String.join("", Collections.nCopies(this.depth, FOUR_SPACE));
} private void adjustDepth() {
if(children!=null) {
for(Node child:children) {
child.depth=this.depth+(this.type==TYPE_TRANSPARENT?0:1);
child.adjustDepth();
}
}
} public void printHeaders() {
final String continuousStar = createRepeatedStr("-", 84);
final String layout = "%-12s %-12s %-12s %-12s %-12s %-12s %s";
StringBuilder sb = new StringBuilder(); sb.append(String.format(layout, "Text", "Depth","Parent","Prev","Next","Child Cnt","\n"));
sb.append(continuousStar + "\n");
System.out.print(sb.toString());
} public void printTree() {
final String layout = "%-12s %-12s %-12s %-12s %-12s %-12s %s";
StringBuilder sb = new StringBuilder(); String text=(this.text==null?"NULL":this.text);
int count=(this.children==null?0:this.children.size());
String parentText=(this.parent==null?"NULL":this.parent.text);
String prevText=(this.prev==null?"NULL":this.prev.text);
String nextText=(this.next==null?"NULL":this.next.text); sb.append(String.format(layout, text,String.valueOf(this.depth), parentText,prevText,nextText,String.valueOf(count),"\n"));
System.out.print(sb.toString()); if(count>0) {
for(Node child:children) {
child.printTree();
}
}
} private static String createRepeatedStr(String seed, int n) {
return String.join("", Collections.nCopies(n, seed));
} public String toString() {
StringBuilder sb=new StringBuilder(); final String tabs=getIndentSpace(); if(this.text!=null) {
if(this.type!=TYPE_JOINT) {
sb.append(tabs+this.text);
}else {
if(",".equalsIgnoreCase(this.text)) {
sb.append(this.text);
}else {
sb.append(ONE_SPACE+this.text);
}
} if(this.next!=null) {
if(this.next.type!=TYPE_JOINT) {
sb.append("\n");
}
}else {
sb.append("\n");
}
} if(children!=null) {
for(Node child:children) {
sb.append(child.toString());
}
} return sb.toString();
} public static void main(String[] args) {
Node f1=new Node("a.f1");
Node comma=new Node(",",Node.TYPE_JOINT);
Node f2=new Node("b.f2"); Node select=new Node("select");
select.addChild(f1);
select.addChild(comma);
select.addChild(f2); Node t1=new Node("table01 a");
Node tComma=new Node(",",Node.TYPE_JOINT); Node childSelect=new Node("select");
childSelect.addChild(new Node("a")); Node childFrom=new Node("from");
childFrom.addChild(new Node("tb")); Node subSelect=new Node();
subSelect.addChild(childSelect);
subSelect.addChild(childFrom); Node t2=new Node(Node.TYPE_TRANSPARENT);
t2.addChild(new Node("("));
t2.addChild(subSelect);
t2.addChild(new Node(")"));
t2.addChild(new Node("b")); Node from=new Node("from");
from.addChild(t1);
from.addChild(tComma);
from.addChild(t2); Node w1=new Node("a.f1=1");
Node wAnd=new Node("and",Node.TYPE_JOINT);
Node w2=new Node("b.f2=2");
Node wor=new Node("or",Node.TYPE_JOINT);
Node w3=new Node("b.f3=3"); Node where=new Node("where");
where.addChild(w1);
where.addChild(wAnd);
where.addChild(w2);
where.addChild(wor);
where.addChild(w3); Node orderby=new Node("order by");
orderby.addChild(new Node("a.f1"));
orderby.addChild(new Node(",",Node.TYPE_JOINT));
orderby.addChild(new Node("b.f2")); Node query=new Node(Node.TYPE_TRANSPARENT);
query.addChild(select);
query.addChild(from);
query.addChild(where);
query.addChild(orderby); System.out.println(query);
query.printHeaders();
query.printTree();
}
}

--2020年5月15日--

SQL Node 1.05版的更多相关文章

  1. SQL Server 2016正式版安装(超多图)

    微软数据库SQL Server 2016正式版在2016年6月就发布,由于近期工作忙,一直拖到现在才有时间把安装过程写到博客上,分享给大家.本人一直习惯使用英文版,所以版本和截图都是英文版的.废话少说 ...

  2. win7 安装SQL Server 2005 开发版 图文教程

    转自win7 安装SQL Server 2005 开发版 图文教程 ----------------------------写在安装前------------------------------ 一. ...

  3. Windows XP系统安装SQL Server 2005(开发版)图解

    转自Windows XP系统安装SQL Server 2005(开发版)图解 安装前提:由于有些从网上的下载的项目需要导入SQL Server 2005的数据文件,因此,今天便安装了这个数据库,我的系 ...

  4. Sql Server 2005 开发版亲測可用下载地址

    sqlserver2005开发版下载地址:http://222.132.81.146/rj/cs_sql_2005_dev_all_dvd.rar建议使用迅雷下载. sql server 2005 开 ...

  5. Sql Server 2008开发版(Developer Edition)过期升级企业版(Enterprise Edition)失败后安装学习版(Express Edition)

    最近一个多月,甚是悠哉,无事可做.上线的网站系统也没接到客户的反馈,反而觉得无聊之极了.上周五早上,一上QQ,就收到客户发来消息,管理平台无法登陆了.心里一惊,立马开始查找故障原因.翻看了系统日志,提 ...

  6. SQL Server 2012 官方版 / SQL Server 2012下载

    SQL Server是微软的一款专业免费的关系数据库管理工具, 是一个全面的数据库平台,使用集成的商业智能 (BI)工具提供了企业级的数据管理服务,SQL Server 数据库引擎为关系型数据和结构化 ...

  7. Node.js meitulu图片批量下载爬虫 1.05版(Final最终版)

    //====================================================== // https://www.meitulu.com图片批量下载Node.js爬虫1. ...

  8. Practical Node.js (2018版) 第5章:数据库 使用MongoDB和Mongoose,或者node.js的native驱动。

    Persistence with MongoDB and Mongoose https://github.com/azat-co/practicalnode/blob/master/chapter5/ ...

  9. 【pyhon】理想论坛爬虫1.05版,将读取和写DB分离成两个文件

    下午再接再厉仿照Nodejs版的理想帖子爬虫把Python版的也改造了下,但美中不足的是完成任务的线程数量似乎停滞在100个左右,让人郁闷.原因还待查. 先把代码贴出来吧,也算个阶段性成果. 爬虫代码 ...

随机推荐

  1. CSS 定位总结

    目录 元素显示模式 元素模式 元素显示模式转换 CSS定位机制 静态定位static 相对定位relative 绝对定位absolute 固定定位fixed 粘性定位sticky 定位小结一图流 CS ...

  2. HTML实例-01-轮播图

     body部分 <div class="outer"> <ul class="img-list"> <li><a hr ...

  3. MySQL字符集操作

    一.查看编码 show variables like 'character%'; 二.临时设置编码 1.set names xxx set names ${编码}; "set names x ...

  4. 记一次mysql数据库被勒索(上)

    家里搞了台旧电脑做NAS,安装了nextcloud,选择了mysql做为数据库. 当时也没有想太多,mysql数据库密码随便设置了个123456,用的一切正常. 然后,听说可以找电信申请换个公网IP的 ...

  5. 搭建vue开发环境的步骤,六步完成

    搭建vue开发环境的步骤,其实也挺简单的,之前这环境的配置也困扰着我一:在搭建vue的开发环境之前,一定一定要先下载node.js,vue的运行是要依赖于node的npm的管理工具来实现,下载地址:h ...

  6. IntelliJ IDEA安装Activiti插件并使用

    一.安装Activiti插件 1.搜索插件 点击菜单[File]-->[Settings...]打开[Settings]窗口. 点击左侧[Plugins]按钮,在右侧输出"actiBPM",点击 ...

  7. I帧B帧P帧

    转载自:http://blog.csdn.net/abcjennifer/article/details/6577934 视频压缩中,每帧代表一幅静止的图像.而在实际压缩时,会采取各种算法减少数据的容 ...

  8. HDFS概述和Shell操作

    大数据技术之Hadoop(HDFS) 第一章 HDFS概述 HDFS组成架构 HDFS文件块大小 第二章 HDFS的Shell操作(开发重点) 1.基本语法 bin/hadoop fs 具体命令    ...

  9. HTTP基础--请求

    请求,由客户端向服务器端发出,可以分为4部分:请求方法(Request Method),请求的网址(Request URL),请求头(Request Headers),请求体(Request Body ...

  10. 为wordpress的分类以及子分类指定固定模版

    在wordpress主题开发有多个不同分类页面时,通常使用category-{slug}.php的方式分别为每个分类开发不同的页面模版,slug为该分类的别名,并且无需其他设置仅仅以此命名即可. 但是 ...