输出:

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. 8、Builder 建造者模式 组装复杂的实例 创造型模式

    1.什么是Builder模式 定义: 将一个复杂对象的构建与表示相分离,使得同样的构建过程可以创建不同的表示.大白话就是,你不需要知道这个类的内部是什么样的,只用把想使用的参数传进去就可以了,达到了解 ...

  2. 2020-07-26:如何用 socket 编程实现 ftp 协议?

    福哥答案2020-07-26: 功能用户输入user username.pass password注册,注册后输入dir查看服务器文件列表,输入get filename path下载文件到指定路径. ...

  3. NodeJs nrm 和 nvm

    nrm 和 nvm nrm (npm registry manager)是npm的镜像源管理工具 nvm (node version manager)是nodejs的版本管理工具 nrm # nrm ...

  4. 《T-GCN: A Temporal Graph Convolutional Network for Traffic Prediction》 代码解读

    论文链接:https://arxiv.org/abs/1811.05320 博客原作者Missouter,博客链接https://www.cnblogs.com/missouter/,欢迎交流. 解读 ...

  5. java如何实现发送邮箱

    package cn.buy.util; import java.security.GeneralSecurityException; import java.util.Properties; imp ...

  6. 金题大战Vol.0 C、树上的等差数列

    金题大战Vol.0 C.树上的等差数列 题目描述 给定一棵包含\(N\)个节点的无根树,节点编号\(1-N\).其中每个节点都具有一个权值,第\(i\)个节点的权值是\(A_i\). 小\(Hi\)希 ...

  7. 使用Spring Boot开发者工具进行自动重启和页面自动刷新

    简介 大家可能都听说过开发Node.js应用时可以使用多种工具对开发者提供便利,如WebPack提供了开发者服务器来支持js应用动态更替,并在保存文件时自动刷新浏览器.Spring Boot也提供了相 ...

  8. Webpack开发指南

    前言 成为一个全栈工程师,前端是必不可少的,这位前端构建工具webpack是一门必修的技术. 在学习webpack之前,先熟悉一下npm工具:https://www.runoob.com/nodejs ...

  9. JDK1.8源码学习-Object

    JDK1.8源码学习-Object 目录 一.方法简介 1.一个本地方法,主要作用是将本地方法注册到虚拟机中. private static native void registerNatives() ...

  10. 作弊揭发者 C++

    鉴于我市拥堵的交通状况,市政交管部门经过听证决定在道路两侧安置自动停车收费系统.当车辆驶入车位,系统会通过配有的摄像头拍摄车辆画面,通过识别车牌上的数字.字母序列识别车牌,通过连接车管所车辆信息数据库 ...