Skip to content

Commit 0006371

Browse files
bagyi0vim-scripts
authored andcommitted
Version 2.00
dbext.vim has been greatly enhanced for version 2.00. Additional features include: Connection Profiles You can create as many profiles as you like in your vimrc. Each profile specifies various connection information. When you are prompted for connection information, for ease of use, you can choose from a numbered list. Modeline Support Similar to Vim modelines, you can specify connection information as comments within your buffers. To prevent sensitive information (ie passwords) from being visible, you can specify a connection profile as part of your modeline. Object Completion dbext ties into Vim dictionary feature. You can complete table names, procedure names and view names. Viewing Lists of Objects You can browse through the various objects in the database you are connected to and specify wildcard information. For example you can say, "Show me all tables beginning with 'ml_' ". These objects are currently supported: Tables, Procedures, Views, Columns (for a table). FileType Support Added dbext has support for various filetypes. For example, assume you dynamically build a SQL statement by joining strings together, using calls to functions, host parameters. By visually selecting the code and executing it dbext will parse the statement, strip out the various string joining commands (+, ||, .) and prompt you for host values before sending the string to be executed against the database. This way it is very easy to test your SQL statements without having to cut and paste the commands into a SQL tool. Currently supported filetypes are: PHP, Java, JSP, JavaScript, Perl, SQL, Vim. Intellisense Addin Support The Intellisense plugin now has SQL supported. To enable greater functionality (table, procedure, view lists), it uses dbext.vim to retrieve this information.
0 parents  commit 0006371

File tree

3 files changed

+4223
-0
lines changed

3 files changed

+4223
-0
lines changed

README

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
This is a mirror of http://www.vim.org/scripts/script.php?script_id=356
2+
3+
This plugin contains functions/mappings/commands to enable Vim to access several databases. Current databases supported are: Mysql, PostgreSQL, Ingres, Oracle, Oracle Rdb (VMS), Sybase Adaptive Server Anywhere, Sybase Adaptive Server Enterprise, Microsoft SQL Server, DB2, Interbase and SQLite and ODBC are supported. New to version 5.x of dbext introduces the support for Perl's DBI layer. If the database you are using is not *natively* supported by dbext, but has a DBI interface, dbext's standard feature set is available. For those already using dbext, the DBI interface should provide a performance boost when running statements against your database. DBI also provides an ODBC bridge, therefore any ODBC compliant database is also accessible.
4+
5+
NOTE: As of version 4.0 this plugin requires Vim 7.
6+
Version 5.0 supports Vim 7's autoload feature.
7+
8+
dbext provides a common interface between your editor and a database. If your company/project moves onto a new database platform, there is no need to learn the new databases tools. While editing your SQL (and without leaving Vim) you can execute database commands, run queries, display results, and view database objects. dbext understands various programming languages, and can parse and prompt the user for [host] variables and execute the resulting statement. See below for more details.
9+
10+
Adds a menu for the common commands for gvim users.
11+
12+
Some of the features that are supported:
13+
14+
Tutorial
15+
-----------
16+
A tutorial has been added to help you become familiar with the features of the plugin, :h dbext-tutorial.
17+
If you dislike reading docs, then at a minimum follow the tutorial. It will give you the basics of the features and introduce some "best" practices, like creating connection profiles.
18+
19+
Connection Profiles
20+
-----------------------------
21+
You can create as many profiles as you like in your vimrc. Each profile specifies various connection information. Each buffer can be connected to a different database. The plugin will automatically prompt the user for connection information. If you have defined profiles in your vimrc, for ease of use, you can choose from a numbered list.
22+
23+
SQL History
24+
-----------
25+
As of version 3.0, dbext maintains a history file which is shared between multiple instances of Vim. A statement added in one instance of Vim will be immediately available in a different instance of Vim on the same computer. To re-run a statement you can either press <enter> on the line, or if you prefer the mouse you can double click on the statement.
26+
27+
Modeline Support
28+
---------------------------
29+
Similar to Vim modelines, you can specify connection information as comments within your buffers. To prevent sensitive information (i.e. passwords) from being visible, you can specify a connection profile as part of your modeline.
30+
31+
Object Completion
32+
----------------------------
33+
dbext ties into Vim dictionary feature. You can complete table names, procedure names and view names using the i_CTRL-X_CTRL-K feature.
34+
35+
Viewing Lists of Objects
36+
------------------------------------
37+
You can browse through the various objects in the database you are connected to and specify wildcard information. For example you can say, "Show me all tables beginning with 'ml_' ". These objects are currently supported: Tables, Procedures, Views, Columns (for a table).
38+
39+
Result Buffer
40+
-------------------
41+
The output from any of the commands is placed into a new buffer called Result. In the event of an error, both the error and the command line is included for inspection.
42+
43+
Mappings
44+
----------------
45+
There are many maps created for convenience. They exist for most modes (command, visual and insert).
46+
47+
Place the cursor on a word, and invoke the default mapping (or menu) and a Result buffer will open with the contents of the table displayed (i.e. select * from <word>. Optionally you can be prompted for the table name, and a WHERE clause.
48+
49+
Describe a table (see column names and datatypes).
50+
51+
Describe a stored procedure (see input and output datatypes).
52+
53+
Visually highlight statements and execute them against the database.
54+
55+
Parsing Statements
56+
-----------------------------
57+
By default any statement will be parsed looking for input parameters (host variables), if any are found you are prompted to enter a suitable value for the parameter. This option can be turned off either globally or on a per
58+
buffer basis.
59+
SELECT first_name, city
60+
FROM customer
61+
WHERE last_name = @name
62+
In the case you will be asked for a value for @name. The rules for defining input parameters are customizable either globally or on a per buffer basis. See help file for more details.
63+
64+
FileType Support
65+
--------------------------
66+
SQL can be used from a variety of languages. Each development language (PHP, Perl, Java, ...) language has different syntax for creating SQL statements that are sent to the database. dbext has support for several
67+
different filetypes, so that it can understand and correctly parse a SQL statement.
68+
69+
The current supported languages are:
70+
PHP, Java, JSP, JavaScript, JProperties, Perl, SQL, Vim
71+
72+
For example assume you had the following Java code:
73+
String mySQL =
74+
"SELECT s.script, ts.event, t.name " +
75+
" , s.script_language, sv.name " +
76+
" FROM ml_script s, ml_table_script ts, ml_table t " +
77+
" , ml_script_version sv " +
78+
" WHERE s.script_id = " + script_version +
79+
" AND ts.version_id = "+obj.method() +
80+
" AND ts.table_id = t.table_id ";
81+
82+
If you visually select from the "SELECT ... to the "; and ran
83+
:'<,'>DBExecSQL (or used the default map <Leader>se)
84+
85+
The Java filetype support would concatenate each individual string into one
86+
single string. In this case it removed the " + " and concatenated the
87+
lines to result in the following (assuming this is on one line):
88+
SELECT s.script, ts.event, t.name , s.script_language, sv.name
89+
FROM ml_script s, ml_table_script ts, ml_table t
90+
, ml_script_version sv
91+
WHERE s.script_id = " + script_version + "
92+
AND ts.version_id = "+obj.method() +"
93+
AND ts.table_id = t.table_id
94+
95+
Next, it will prompt you for replacement values for the various variables or objects you used in the string.
96+
Assuming you had the default behaviour turned on, you would be prompted to supply a value for:
97+
" + script_version + "
98+
"+obj.method() +"
99+
100+
So assuming you entered:
101+
100
102+
'Project_Yahoo'
103+
104+
Then the resulting string sent to your database would be (again, this would technically be on one line):
105+
SELECT s.script, ts.event, t.name , s.script_language, sv.name
106+
FROM ml_script s, ml_table_script ts, ml_table t
107+
, ml_script_version sv
108+
WHERE s.script_id = 100
109+
AND ts.version_id = 'Project_Yahoo'
110+
AND ts.table_id = t.table_id
111+
112+
Benefit:
113+
You did not have to test your SQL by cutting and pasting it into a separate tool and replacing all the object and host variables yourself. Just by visually selecting the string and running the command DBExecSQL (or the default mapping <Leader>se) the SQL statement was executed against the database and allowed to you enter host variables.
114+
115+
Additional Commands
116+
---------------------------------
117+
DBExecSQL - Enter any command you want sent to the database
118+
DBExecRangeSQL - Enter any range of statements you want executed
119+
Select - Enter the remainder of a select (ie :Select * from customer)
120+
Call - Call a stored procedure
121+
Update - Enter the remainder of an update
122+
Insert - Enter the remainder of an insert
123+
Delete - Enter the remainder of an delete
124+
Drop - Enter the remainder of a drop
125+
Alter - Enter the remainder of an alter
126+
Create - Enter the remainder of a create

0 commit comments

Comments
 (0)