Monday, September 24, 2012

Re: Vim for Oracle

On 24/09/2012 1:19 PM, vicky b wrote:
Thanks for the replies guys but in the present world where we leave with so much of ide and code completion and so many features what is that makes you guys stick to vim .. does it make your job simpler or features are great or your use to it.


I am the maintainer of dbext and a host of other related SQL support in Vim.

IDE features provided by other software are great and a number of them have been added to Vim via plugins.


SrchRplcHiGrp.vim : Search and/or replace based on a syntax highlight group

http://www.vim.org/scripts/script.php?script_id=848

Since I work with SQL all day, I primarily created it to UPPER CASE
keywords (SELECT, UPDATE, FROM, WHERE, ...) in SQL. But, it has nothing to do with SQL.

Basically, if Vim can colour highlight text in a file, then you can
choose to search and replace on those colour highlights. I justchoose sqlKeyword highlighting keywords and then to do a search and replace to transform those words into UPPER CASE strings.


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

The main purpose of this plugin is it will reformat SQL queries into a
nice readable format. But it has another option which will allow you
to UPPER CASE your keywords as well.


Tim, I noticed you mentioned you format SQL, have a look at the web page for this plugin it shows a few formatting examples.


dbext.vim : Provides database access to many dbms (Oracle, Sybase,
Microsoft, MySQL, DBI,..)
http://www.vim.org/scripts/script.php?script_id=356


This one was mentioned by Paul.  It can do far more than simply execute SQL.
One of the most useful features I find is the ability to execute SQL and prompt you for input parameters.  It can also do this for many different fileformats.  For example  assume you had the following Java code:

    String mySQL =
        "SELECT s.script, ts.event, t.name                  " +
        "     , s.script_language, sv.name                  " +
        "  FROM ml_script s, ml_table_script ts, ml_table t " +
            "     , ml_script_version sv                        " +
        " WHERE s.script_id   = " + script_version +
        "   AND ts.version    = "+obj.method() +
        "   AND ts.table_id   = t.table_id                  ";

 If you visually select from the "SELECT ... to the "; and ran
 :'<,'>DBExecSQL

 The Java filetype support would concatenate each individual string into
 one single string.  In this case it removed the " + " and concatenated
 the lines to result in the following (assuming this is on one line):
          SELECT s.script, ts.event, t.name , s.script_language, sv.name
           FROM ml_script s, ml_table_script ts, ml_table t
                  , ml_script_version sv
          WHERE s.script_id   = " + script_version + "
            AND ts.version    = "+obj.method() +"
            AND ts.table_id   = t.table_id

It will then prompt you for values for "script_version" and "obj.method()".
This allows you to execute the query and test it without having you to modify your code at all.

A number of different filetypes are supported, Java, Perl, PHP, VB, Vim, SQL.  More can be added.


Included with Vim 7.3 is the SQL Complete plugin.  It uses the OMNI completion built into Vim (CTRL-X CTRL-O) and will complete using SQL syntax keywords.

If you have the dbext plugin installed, it will also complete, tables, columns, stored procedures and other items.  It will dynamically pull these from whatever database you have it connect.  See the help file :h omni-sql-completion or :h ft_sql.txt



Tim, you also showed an example of how create a select column list by grabbing the headers (from a different program) and running a search and replace on it.

SQLComplete.vim has provisions for doing just that.  When on a table name, a key stroke will replace the table name with a comma separated list of columns from that table.


Anyway, there is a bunch more to the SQL support I have added in Vim, but that should give people a fairly good overview.

David.


No comments: