Login
     
  Latest Entries  
  Blog  
23

Using UltraEdit's powerful external tool integration, this article will show you how to submit an SQL query directly from UltraEdit and have the results returned directly to the editor.

This example uses Microsoft SQL Server 2000, but the basic technique can be applied to most any database tool.

Using the Tool Configuration option (in the Advanced menu), you can define external tools to be used within your UltraEdit (UE) session. Mostly this is used to drive language compilers so you can code and compile directly within UE, but we'll use it to drive a command line query tool. SQL Server comes with a couple of command line query tools (iSQL and oSQL), which both operate in a similar manner. Although, I believe that iSQL is legacy and being phased out, so we'll use oSQL.

From UE's Advanced menu, select Tool Configuration. On the Command tab of the dialog, pick a name for the Menu Item Name box (this will be displayed as a menu item under the Advanced menu).

Next, fill in the Command Line box (substitute text in italics with specifics for your database):
osql -S ServerName,Port -d DatabaseName -w 500 -U UserName -P Passwrod -q"%sel%"
where —
ServerName,Port is the name and port number of the server where your database resides (the default port number is 1433 and can be omitted if you've never changed it).
DatabaseName is the name of the database within SQL Server (example: NorthWind)
UserName is the name of the user account within the database that will run the query
Password is the password of the above user account

Next, fill in the Working Directory box with the location of the osql.exe file (the default install path for SQL Server 2000 is: C:\Program Files\Microsoft SQL Server\80\Tools\Binn ).

On the Options tab, make sure that Dos Program is selected (since osql.exe is a DOS application). You can also select options to save your files before running the query (probably a good idea).

On the Output tab select the options: Output to List Box, Capture Output and No Replace. You can experiment with the other options depending on how you wish to utilize this tool for your situation.

Be sure to click Apply, to save your settings. You will now see a menu item under the Advanced menu... Time to test it out!

Create a new document within UE, and type a simple query. For example:

SELECT count(*) FROM TableName

Highlight the query, and select your new menu item from the Advanced menu (or hit the shortcut keys — the first Tool entry is Ctrl+Shift+0). Your query will execute and the results will be displayed in a new document within UE. Easy as that!

There are many ways to use this tool configuration. Let's say that you are constantly typing up a weekly status report on sales figures, you could use this tool (with the option Replace selected text with: set to Captured Output) and type something like this:

The total sales for the month of July is select sum(sales) from SalesDB where month='07'

Then simply highlight the embedded select at the end of that sentence, run your query, and let UE replace the selected text with the results from the database.

That's just a really simple idea, but you can now see the possibilities. You can experiment with any DOS or Windows program that returns some form of output, just define it as a Tool and easily run it from within UE (I've used it to capture ipconfig and ping information directly into the editor). Leave a comment if you have any questions or discover any novel uses for the tool feature in UE.

Posted in: Development

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

  Archives