输出:

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. Mixed Precision Training —— caffe-float16

    简介 最近有了突如其来的想法,如何把caffe的变得更小更快.后来翻到Nvidia开发caffe-float16,同时也看到它的论文.看完大致了解一番后,就做一下记录. 该工作的目标是,减少网络的所需 ...

  2. Spring的第一个程序

    目录 一.Spring概述 1. Spring是什么? 2. IOC控制反转 二.Spring的第一个程序 1. 创建Maven项目 2. 加入maven依赖pom.xml 3. 定义接口和实体类 4 ...

  3. 2020-06-15:Redis分布式锁怎么解锁?

    福哥答案2020-06-15: 答案来自群成员:1.setnx:del2.set:lua+del3.redisson:@Overridepublic void unlock(String lockKe ...

  4. Vue Vuex中的严格模式/实例解析/dispatch/commit /state/getters

    严格模式 import getters from './getters' import mutations from './mutations' import actions from './acti ...

  5. 利用Unity3D制作简易2D计算器

    利用Unity3D制作简易2D计算器 标签(空格分隔): uiniy3D 1. 操作流程 在unity3DD中创建一个新项目 注意选择是2D的(因为默认3D) 在Assets框右键新建C#脚本 在新建 ...

  6. 封装react antd的form表单组件

    form表单在我们日常的开发过程中被使用到的概率还是很大的,比如包含了登录.注册.修改个人信息.新增修改业务数据等的公司内部管理系统.而在使用时这些表单的样式如高度.上下边距.边框.圆角.阴影.高亮等 ...

  7. Spark从入门到放弃---RDD

    什么是Spark? 关于Spark具体的定义,大家可以去阅读官网或者百度关于Spark的词条,在此不再赘述.从一个野生程序猿的角度去理解,作为大数据时代的一个准王者,Spark是一款主流的高性能分布式 ...

  8. graphics.h源代码下载

    graphics.h源代码下载 /*graphics.h DefinitionsforGraphicsPackage. Copyright(c)BorlandInternational1987,198 ...

  9. 解决SpringBoot页面跳转无法访问静态资源的问题

    初学SpringBoot,写项目的时候遇到了问题,原本的页面是这样的 但启动项目后是这样的 这是因为thymeleaf中引入静态资源及模板需要使用到 th:xxx 属性,否则无法在动态资源中访问静态资 ...

  10. J20航模遥控器开源项目系列教程(三)开发说明 | 想要自己改造程序,扩充功能,怎么实现?

    我们的开源宗旨:自由 协调 开放 合作 共享 拥抱开源,丰富国内开源生态,开展多人运动,欢迎加入我们哈~ 和一群志同道合的人,做自己所热爱的事! 项目开源地址:https://github.com/C ...