输出:

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. ECMAScript6新增数据类型symbol数据类型

    25.Symbol目的:为了解决对象之间属性名冲突的问题,Symbol它是引用数据类型. Symbol( ),它代表着一个独一无二的值 [name]: '小红',//加中括号代表默认创建了一个Symb ...

  2. Tutte 定理与 Tutte–Berge 公式

    Tutte theorem 图 \(G=(V,E)\) 有完美匹配当且仅当满足 \(\forall U\subseteq V,o(G-U)\le|U|,o(X)\) 表示 X 子图的奇连通块数. Tu ...

  3. Docker容器网络-实现篇

    通常,Linux容器的网络是被隔离在它自己的Network Namespace中,其中就包括:网卡(Network Interface).回环设备(Loopback Device).路由表(Routi ...

  4. find the lowest number location

    before #设定路径列表Path def find_path2(heightmap, x, y, water_level=557,path=[]): #global path #设定坐标 右0 左 ...

  5. 2020-06-20:一句话总结ZK?

    福哥答案2020-06-20: 这道题价值不大,但是面试题里有这道题. 分布式协调服务,注册服务和发现,树形结构,监听机制,过半机制. ZooKeeper是源代码开放的分布式协调服务,由雅虎公司创建, ...

  6. 【USACO13DEC】 最优挤奶 - 线段树

    题目描述 FJ最近买了1个新仓库, 内含N 个挤奶机,1 到N 编号并排成一行. 挤奶机i 每天能产出M(i) 单位的奶.不幸的是, 机器装得太近以至于如果一台机器i 在某天被使用, 那与它相邻的两台 ...

  7. Eclipse怎么切换工作空间

    1.进行点击Eclipse编辑代码的窗口界面中,进行点击菜单中file的选项. 2.弹出了下拉菜单中进行选择为“switch workspace”的选项. 3.弹出了下一级菜单中进行选择为other的 ...

  8. 启动tomcat出现闪退的原因

    出现闪退的可能有几点: 1.没有安装jdk或者配置jdk是否配置成功 2.找不到jdk安装的路径 3.tomcat环境配置失败 如果是第二点原因(确保第一第三点配置都正确无误)找不到jdk路径的话,可 ...

  9. k8s 辨析 port、NodePort、targetPort、containerPort 区别

    刚接触 k8s 涉及到端口到内容较多,容易混淆,这里整理如下: 目录 nodePort port targetPort containerPort 参考文章 nodePort nodePort 提供了 ...

  10. Linux系统添加应用服务进程的守护进程

    以前曾在Linux上维护应用服务,但是只是简单的迭代版本等工作,没有什么技术含量.最近部署在Linux服务器上的一个平台的总线进程broker(下面总线用broker指代)经常挂掉,由于总线负责服务之 ...