Version Control from Query Analyzer

for RuBoard

Even though Query Analyzer itself has no built-in support for version control, you can use command-line utilities in conjunction with Query Analyzer's ability to run custom tools to add version control facilities to the environment. If your source code management system includes a command-line utility for performing code management tasks (most do), you can hook that utility into Query Analyzer's Tools menu. Moreover, because Query Analyzer provides special runtime tokens that allow you to pass the name of the current file (and many other key elements) to an outside tool, you can wire your version control tool almost seamlessly into the development environment.

As I've said, I use VSS, so the steps that follow show how to use the VSS command-line utility, SS.EXE, from within Query Analyzer. This is not to say that you couldn't use a different version control system with Query Analyzer. On the contrary, because most version control systems work similarly, the steps necessary to access a version control utility from Query Analyzer are likely to be comparable regardless of the actual package used.

To add an external tool to the Query Analyzer Tools menu, click the ToolsCustomize menu option and select the Tools tab in the Customize dialog. The Menu contents: entry box in the center of the page is the list of currently installed tools. Double-click a blank entry to add a new one. Table 4-2 shows the VSS- related entries in my list:

Table 4-2. VSS-Related Tool Menu Entries
Name Command Arguments Initial directory
Set Project Path ss.exe cp $/ggspxml/ch04/code  
Set Working folder ss.exe workfold $(FileDir)  
Add Current File ss.exe add $(FilePath) $(FileDir)
Check Out Current File ss.exe checkout $(FileName)$ (FileExt) -C- $(FileDir)
Check In Current File ss.exe checkin $(FileName) $(FileExt) $(FileDir)
Undo Check Out of Current File ss.exe undocheckout $(FileName) $(FileExt) $(FileDir)
Diff Current File Diff.bat $(FileName)$(FileExt) $(FileDir)

If you set up Query Analyzer to call VSS using the information in Table 4-2, there are a few caveats of which you should be aware. First, be sure to assign your own project path and working folder using the Set Project Path and Set Working Folder options, respectively. Those listed in Table 4-2 are the ones I happen to be using at the moment. Second, keep in mind that most VSS commands prompt you for comments when invoked. I've disabled comment prompting on the Check Out Current File option, but not on the others. Add -C- to any command for which you want to disable comment prompting. Third, set the SSDIR environmental variable to point to the folder containing the SRCSAFE.INI file you wish to use if this differs from the default VSS search path.

Notice my use of the DIFF.BAT FILE for checking a file for version differences. Diff.bat contains just two lines:

 ss diff %1 pause 

The first line lists the differences between the local version of the current file and the one stored in the VSS database. The pause command allows you to view the difference output before returning to Query Analyzer. We call DIFF.BAT instead of ss diff directly because we want to see the output of the command before returning.

Special Tokens

As you can see, Query Analyzer supports several special tokens (denoted with a $ symbol) that you can use to send runtime information to outside tools. Click the arrow buttons to the right of the Arguments: and Initial directory: entry boxes to list those available to you. Table 4-3 lists the ones that I use.

Table 4-3. Query Analyzer Runtime Environment Tokens
Token Meaning
$(FilePath) The full path to the current file
$(FileName) The filename portion (without extension) of the current file
$(FileExt) The file extension (including the leading period) of the current file
$(FileDir) The directory path (no filename or extension) of the current file

CAUTION

You may have noticed that Query Analyzer appends an asterisk to the current file's window caption when you modify the file. Because it apparently retrieves the name of the current file from the window caption, it makes the mistake of including the asterisk indicator when it passes the $(FileExt) or $(FilePath) tokens to an external tool. So, if you've modified the file, an invalid filename will be passed to your external tool. To get around this, simply save the file before invoking the tool. This is likely what you'd want to do anyway to ensure that the tool operates on the latest version of the file.


You can find a .REG file containing the registry entries necessary to add these tokens to your Query Analyzer setup on the CD accompanying this book. Run the file to add the settings in Table 4-3 to your Query Analyzer setup.

for RuBoard


The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML
The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML
ISBN: 201700468
EAN: N/A
Year: 2005
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net