sqlformatter的简单介绍
本篇文章给大家谈谈sqlformatter,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、Toad forDB2工具有没有类似plsql developer工具中的美化器,美化SQL语句的功能
- 2、如何采用element-plus,基于codemirror6实现sql在线编辑器?
- 3、怎么用正则表达式解析sql语句
- 4、Poor Man's T-SQL Formatter如何在sublime中使用
Toad forDB2工具有没有类似plsql developer工具中的美化器,美化SQL语句的功能
toad中叫Formatter,
在tools--options...--Editor--Formatter 进行设置调整,自定义
在sql窗口中毁中,有一个 format sql 快捷按钮,执行sql格游昌式化纤磨山的操作
[img]如何采用element-plus,基于codemirror6实现sql在线编辑器?
js在线sql编辑器,下载后导入IDE工具中,在浏览器访问sql-editor-master/index.html ,效果如下(含括号高亮显示、显示折叠栏):
codeMirror官网, 官网羡歼咐js/css资源文件改历,也可自行去官网下载,但是官网比较慢,需引入的核心页面代码:
link rel="stylesheet" href="css/codemirror.css" /
link rel="stylesheet" href="test/addon/fold/foldgutter.css"
link rel="stylesheet" href="css/theme/dracula.css" /
link rel="stylesheet" href="css/show-hint.css" /
link rel="stylesheet" href="js/jquery-easyui/themes/default/easyui.css"
link rel="stylesheet" href="js/layui/css/layui.css"
link rel="stylesheet" href="css/index.css" /
script type="text/javascript"var baseUrl ="";/script
script type="text/javascript" src="js/jquery.min.js"/script
script type="text/javascript" src="js/jquery-easyui/jquery.easyui.min.js"/script
script type="text/javascript" src="js/兄纯jquery-easyui/locale/easyui-lang-zh_CN.js"/script
script type="text/javascript" src="js/editor/codemirror.js"/script
!-- 折叠栏显示 --
script type="text/javascript" src="test/addon/fold/foldcode.js"/script
script type="text/javascript" src="test/addon/fold/foldgutter.js"/script
script type="text/javascript" src="test/addon/fold/comment-fold.js"/script
!-- 括号高亮匹配 --
script type="text/javascript" src="test/addon/fold/matchbrackets.js"/script
script type="text/javascript" src="js/editor/sublime.js"/script
script type="text/javascript" src="js/editor/sql.js"/script
script type="text/javascript" src="js/editor/sql-hint.js"/script
script type="text/javascript" src="js/editor/show-hint.js"/script
!-- sql格式 --
script type="text/javascript" src="js/editor/formatting.js"/script
script type="text/javascript" src="js/editor/sql-formatter.min.js"/script
script type="text/javascript" src="js/layui/layui.js"/script
script type="text/javascript" src="js/index.js"/script
textarea id="code"/textarea
核心js代码:
//根据DOM元素的id构造出一个编辑器
var editor=CodeMirror.fromTextArea(document.getElementById("code"),{
mode:"text/c-mysql", //实现Java代码高亮
lineNumbers:true,
matchBrackets: true, //括号高亮匹配
theme:"default",
keyMap: "default",
extraKeys:{"Tab":"autocomplete"},
hint: CodeMirror.hint.sql,
lineWrapping: true, //是否换行
foldGutter: true, //是否折叠
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], //添加行号栏,折叠栏
hintOptions: {
tables: tablewords
}
});
输入关键词提示等信息的配置:allWords.json
动态设置表字段等信息:
let tableWords = {"dual": []};
let tableName = "tn_user";
tableWords[tableName].push("userId");
editor.setOption("hintOptions", {"tables": tableWords});
tableWords json格式如下:
"tableWords": {
"cp_sku": [
"skuid",
"cpbh",
"tcbh"
],
"user_info": [
"user_id",
"user_token",
"user_name",
"user_type",
"password"
]
}
怎么用正则表达式解析sql语句
先看要解析的样例SQL语句:
select * from dual
SELECT * frOm dual
Select C1,c2 From tb
select c1,c2 from tb
select count(*) from t1
select c1,c2,c3 from t1 where condi1=1
Select c1,c2,c3 From t1 Where condi1=1
select c1,c2,c3 from t1,t2 where condi3=3 or condi4=5 order by o1,o2
Select c1,c2,c3 from t1,t2 Where condi3=3 or condi4=5 Order by o1,o2
select c1,c2,c3 from t1,t2,t3 where condi1=5 and condi6=6 or condi7=7 group by g1,g2
Select c1,c2,c3 From t1,t2,t3 Where condi1=5 and condi6=6 or condi7=7 Group by g1,g2
Select c1,c2,c3 From t1,t2,t3 Where condi1=5 and condi6=6 or condi7=7 Group by g1,g2,g3 order by g2,g3
解析效果之一(isSingleLine=false):
原SQL为select * from dual
解析后的SQL为
select
*
from
dual
原SQL为SELECT * frOm dual
解析后的SQL为
select
*
from
dual
原SQL为Select C1,c2 From tb
解析后的SQL为
select
C1,c2
from
tb
原SQL为select c1,c2 from tb
解析后慎察的SQL为
select
c1,c2
from
tb
原SQL为select count(*) from t1
解析后的SQL为
select
count(*)
from
t1
原SQL为select c1,c2,c3 from t1 where condi1=1
解析后的SQL为
select
c1,c2,c3
from
t1
where
condi1=1
原SQL为Select c1,c2,c3 From t1 Where condi1=1
解析咐孝州后的SQL为
select
c1,c2,c3
from
t1
where
condi1=1
原SQL为select c1,c2,c3 from t1,t2 where condi3=3 or condi4=5 order by o1,o2
解析后的SQL为
select
c1,c2,c3
from
t1,t2
where
condi3=3 or condi4=5
order by
o1,o2
原SQL为Select c1,c2,c3 from t1,t2 Where condi3=3 or condi4=5 Order by o1,o2
解衡蔽析后的SQL为
select
c1,c2,c3
from
t1,t2
where
condi3=3 or condi4=5
order by
o1,o2
原SQL为select c1,c2,c3 from t1,t2,t3 where condi1=5 and condi6=6 or condi7=7 group by g1,g2
解析后的SQL为
select
c1,c2,c3
from
t1,t2,t3
where
condi1=5 and condi6=6 or condi7=7
group by
g1,g2
原SQL为Select c1,c2,c3 From t1,t2,t3 Where condi1=5 and condi6=6 or condi7=7 Group by g1,g2
解析后的SQL为
select
c1,c2,c3
from
t1,t2,t3
where
condi1=5 and condi6=6 or condi7=7
group by
g1,g2
原SQL为Select c1,c2,c3 From t1,t2,t3 Where condi1=5 and condi6=6 or condi7=7 Group by g1,g2,g3 order by g2,g3
解析后的SQL为
select
c1,c2,c3
from
t1,t2,t3
where
condi1=5 and condi6=6 or condi7=7
group by
g1,g2,g3
order by
g2,g3
解析效果之二(isSingleLine=true):
原SQL为select * from dual
解析后的SQL为
select
*
from
dual
原SQL为SELECT * frOm dual
解析后的SQL为
select
*
from
dual
原SQL为Select C1,c2 From tb
解析后的SQL为
select
C1,
c2
from
tb
原SQL为select c1,c2 from tb
解析后的SQL为
select
c1,
c2
from
tb
原SQL为select count(*) from t1
解析后的SQL为
select
count(*)
from
t1
原SQL为select c1,c2,c3 from t1 where condi1=1
解析后的SQL为
select
c1,
c2,
c3
from
t1
where
condi1=1
原SQL为Select c1,c2,c3 From t1 Where condi1=1
解析后的SQL为
select
c1,
c2,
c3
from
t1
where
condi1=1
原SQL为select c1,c2,c3 from t1,t2 where condi3=3 or condi4=5 order by o1,o2
解析后的SQL为
select
c1,
c2,
c3
from
t1,
t2
where
condi3=3 or
condi4=5
order by
o1,
o2
原SQL为Select c1,c2,c3 from t1,t2 Where condi3=3 or condi4=5 Order by o1,o2
解析后的SQL为
select
c1,
c2,
c3
from
t1,
t2
where
condi3=3 or
condi4=5
order by
o1,
o2
原SQL为select c1,c2,c3 from t1,t2,t3 wher e condi1=5 and condi6=6 or condi7=7 group by g1,g2
解析后的SQL为
select
c1,
c2,
c3
from
t1,
t2,
t3
where
condi1=5 and
condi6=6 or
condi7=7
group by
g1,
g2
原SQL为Select c1,c2,c3 From t1,t2,t3 Where condi1=5 and condi6=6 or condi7=7 Group by g1,g2
解析后的SQL为
select
c1,
c2,
c3
from
t1,
t2,
t3
where
condi1=5 and
condi6=6 or
condi7=7
group by
g1,
g2
原SQL为Select c1,c2,c3 From t1,t2,t3 Where condi1=5 and condi6=6 or condi7=7 Group by g1,g2,g3 order by g2,g3
解析后的SQL为
select
c1,
c2,
c3
from
t1,
t2,
t3
where
condi1=5 and
condi6=6 or
condi7=7
group by
g1,
g2,
g3
order by
g2,
g3
使用的类SqlParser,你可以拷贝下来使用之:
package com.sitinspring.common.sqlFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* SQL语句解析器类
* @author: sitinspring(junglesong@gmail.com)
* @date: 2008-3-12
*/
public class SqlParser{
/**
* 逗号
*/
private static final String Comma = ",";
/**
* 四个空格
*/
private static final String FourSpace = " ";
/**
* 是否单行显示字段,表,条件的标识量
*/
private static boolean isSingleLine=true;
/**
* 待解析的SQL语句
*/
private String sql;
/**
* SQL中选择的列
*/
private String cols;
/**
* SQL中查找的表
*/
private String tables;
/**
* 查找条件
*/
private String conditions;
/**
* Group By的字段
*/
private String groupCols;
/**
* Order by的字段
*/
private String orderCols;
/**
* 构造函数
* 功能:传入构造函数,解析成字段,表,条件等
* @param sql:传入的SQL语句
*/
public SqlParser(String sql){
this.sql=sql.trim();
Poor Man's T-SQL Formatter如何在sublime中使用
Poor Man's T-SQL Formatter。该工具用于格式凯腔化SQL语句盯穗衫,具有简单、强大、免费的特点,该工具一般是作为SSMS、Notepad++ 、VS Code 等SQL编辑器的插件安装使用。当SQL语句中含有中文的时,UTF8编码的SQL格式化时会报错或乱码,解决办法是:将编码 转为ANSI即可。修改配置项,修改内容为:
"php_path": "族悔Data\\CodeFormatter\\php\\php.exe",
php_path是php.exe文件路径,路径可以是相对路径当然也可以是绝对路径,用相对路径是为了在配置好sublime后将其整个文件夹打包带走在其他电脑直接使用无需再次配置。
关于sqlformatter和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。