Tuesday, October 9, 2012

ANN: SQLUtilities 6.0

SQLUtilities : SQL utilities - Formatting SQL, generate - columns
lists, procedures for databases
http://www.vim.org/scripts/script.php?script_id=492

SQLUtilities can do many things, generating column lists for pasting in code
and others, but it is most used for formatting SQL statements into a nice
readable format.

Simple example:

SELECT m.MSG_ID, m.PRIORITY_ID, CUST.CUST_NBR, CUST.CUST_NM,
CUST.CUST_LEGAL_NM, CUST.STORE_ADDR_1, CUST.STORE_ADDR_2,
CUST.CROSS_STREET, XMLELEMENT( 'Alerts', XMLELEMENT( 'Alert_alert_id',
alert_id ), XMLELEMENT( 'Alert_agent_id', agent_id ), XMLELEMENT(
'Alert_alert_type_id', alert_type_desc), XMLELEMENT(
'Alert_alert_date', alert_date), XMLELEMENT(
'Alert_url_reference', url_reference), XMLELEMENT(
'Alert_read_status', read_status )) CUST.STORE_CITY,
CUST.STORE_ST, CUST.POST_CODE, CUST.STORE_MGR_NM, FROM MESSAGES m JOIN
PRIORITY_CD P WHERE m.to_person_id = ? AND p.NAME = 'PRI_EMERGENCY' AND
p.JOB = 'Plumber' AND m.status_id < ( SELECT s.STATUS_ID FROM
MSG_STATUS_CD s WHERE s.NAME = 'MSG_READ') ORDER BY m.msg_id desc

Becomes (assuming email doesn't mess it up):

SELECT m.MSG_ID, m.PRIORITY_ID, CUST.CUST_NBR, CUST.CUST_NM,
CUST.CUST_LEGAL_NM, CUST.STORE_ADDR_1, CUST.STORE_ADDR_2,
CUST.CROSS_STREET,
XMLELEMENT(
'Alerts', XMLELEMENT( 'Alert_alert_id', alert_id ),
XMLELEMENT( 'Alert_agent_id', agent_id ),
XMLELEMENT( 'Alert_alert_type_id', alert_type_desc),
XMLELEMENT( 'Alert_alert_date', alert_date),
XMLELEMENT(
'Alert_url_reference', url_reference
), XMLELEMENT( 'Alert_read_status', read_status )
) CUST.STORE_CITY, CUST.STORE_ST, CUST.POST_CODE,
CUST.STORE_MGR_NM
FROM MESSAGES m
JOIN PRIORITY_CD P
WHERE m.to_person_id = ?
AND p.NAME = 'PRI_EMERGENCY'
AND p.JOB = 'Plumber'
AND m.status_id < (
SELECT s.STATUS_ID
FROM MSG_STATUS_CD s
WHERE s.NAME = 'MSG_READ'
)
ORDER BY m.msg_id desc

It will also format other statements, see web page for additional examples.


I have uploaded a new version (6.00).

NF: When formatting INSERT statements, the sqlutil_align_comma is also
respected to place each column on a newline.

NF: When formatting UPDATE statements and sqlutil_align_comma is set
comments at the end of the line were removed (Rodrigo Laporte).



Enjoy.

Dave
Feedback always welcome.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: