输出:

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. 基于.NetCore3.1系列 —— 日志记录之日志核心要素揭秘

    一.前言 在上一篇中,我们已经了解了内置系统的默认配置和自定义配置的方式,在学习了配置的基础上,我们进一步的对日志在程序中是如何使用的深入了解学习.所以在这一篇中,主要是对日志记录的核心机制进行学习说 ...

  2. 10、Java 数组的定义和使用

    1.数组的定义 首先举一个小例自:如果你现在需要定义100个int类型的变量,那么按照前俩节的做法为: int a = 1, b=2 , c=3.......; 可以发现我们的代码特别的冗余,而且不美 ...

  3. Faiss流程与原理分析

    1.Faiss简介 Faiss是Facebook AI团队开源的针对聚类和相似性搜索库,为稠密向量提供高效相似度搜索和聚类,支持十亿级别向量的搜索,是目前最为成熟的近似近邻搜索库.它包含多种搜索任意大 ...

  4. Vuex mapState的基本使用

    mapState把Store中的state映射到组件中的计算属性 Store文件 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) ...

  5. 攻防世界-web(进阶)-upload1

    打开链接是一个上传文件的窗口,随便上传一个PDF文件提示必须上传图片,查看源代码,要求必须输入png或jpg格式文件才会上传成功,想到通过修改源代码删除上传限制条件,上传一句话木马,通过中国菜刀进入后 ...

  6. noip复习——线性筛(欧拉筛)

    整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...

  7. 图论算法(五)最小生成树Prim算法

    最小生成树\(Prim\)算法 我们通常求最小生成树有两种常见的算法--\(Prim\)和\(Kruskal\)算法,今天先总结最小生成树概念和比较简单的\(Prim\)算法 Part 1:最小生成树 ...

  8. python3中文输出乱码的问题

    最近使用you-get这个工具下载视频,发现命令行窗口里显示的媒体标题是乱码(但文件管理器里显示正常).我的命令行窗口的code page是936,sys.stdout.encoding是utf-8, ...

  9. 【Flutter 实战】一文学会20多个动画组件

    老孟导读:此篇文章是 Flutter 动画系列文章第三篇,后续还有动画序列.过度动画.转场动画.自定义动画等. Flutter 系统提供了20多个动画组件,只要你把前面[动画核心](文末有链接)的文章 ...

  10. java容器源码分析及常见面试题笔记

      概览 容器主要包括 Collection 和 Map 两种,Collection 存储着对象的集合,而 Map 存储着键值对(两个对象)的映射表. List Arraylist: Object数组 ...