在Eclipse上安装SQL插件的初衷是为了SQL代码格式化(尤其是代码缩进),尽管DTP可以用Shift+Ctrl+F自动格式化代码,然并卵,用了没什么变化。不过,还是简单记录下吧。
1. 关于DTP
Data tools platform (DTP)按官网的描述,功能很强大,除了代码编辑器(语法高亮、自动填充、格式化),还可以调试SQL语句。摘录部分内容如下:
Users – both developers and administrators – typically will create, edit, and test SQL for these commands. Assistance in editing SQL through code completion, formatting, and dialect specialization, greatly enhances productivity.
Further, the ability to execute or debug commands, both SQL and stored procedures, rounds out the rapid development process that Eclipse supports so well.
Finally, bridging chasms, whether between relational, object, or other structures, presents challenges that data management tooling should address.
目前只是作为SQL编辑器使用,更多功能等以后用到再去了解。
2. 安装DTP插件
Help –> Eclipse Marketplace… –> 在搜索框输入Data tools platform –> 安装DTP,其他的按提示操作即可。
其实我安装这个插件的初衷是为了代码格式化(尤其是代码缩进),尽管DTP可以用Shift+Ctrl+F格式化代码,然而用了并没什么变化。不过可以选中代码块,按Tab对整块代码进行缩进。以下是用DTP和TAB键格式化的一段代码:
SELECT T1.trip_id, T1.stop_sequence, T1.stop_id, T2.stop_sequence, T2.stop_id FROM -- create a new table T1: trip_id, stop_sequence=0, stop_id (first stop) (SELECT st_first1.trip_id, st_first1.stop_sequence, st_first1.stop_id FROM stop_times st_first1 INNER JOIN -- filter out the first stop: trip_id, stop_sequence=0 (SELECT stop_times.trip_id, MIN(CAST(stop_times.stop_sequence AS UNSIGNED)) AS first_stop FROM stop_times GROUP BY stop_times.trip_id ) st_first2 ON st_first1.trip_id=st_first2.trip_id AND st_first1.stop_sequence=st_first2.first_stop ) T1 LEFT JOIN -- combine T1 and T2 -- create a new table T2: trip_id, stop_sequence=MAX, stop_id (last stop) (SELECT st_last1.trip_id, st_last1.stop_sequence, st_last1.stop_id FROM stop_times st_last1 INNER JOIN -- filter out the last stop: trip_id, stop_sequence=MAX (SELECT stop_times.trip_id, MAX(CAST(stop_times.stop_sequence AS UNSIGNED)) AS last_stop FROM stop_times GROUP BY stop_times.trip_id ) st_last2 ON st_last1.trip_id=st_last2.trip_id AND st_last1.stop_sequence=st_last2.last_stop ) T2 ON T1.trip_id=T2.trip_id LIMIT 10;
参考资料:
[1]StackOverflow: Lightweight SQL editor for Eclipse [closed]
微信赞赏
支付宝赞赏
Pingback: MySQL使用笔记:目录 | Spark and Shine