QUESTION How do I handle stored procedures for the SQL Server in VisualAge? ANSWER Stored Procedure Support for SQL Server in VisualAge Version 2 There are two implementations that will support SQL Server Stored Procedures in VisualAge Version 2. The first involves changing the VisualAge code. This will enable the customer to still use the visuals (the database query part, not the stored procedure part) much like doing a database query as you currently can do. This implementation also requires that the customer package his application as a runtime image or (if using the merge method), dump the changes to the VisualAge code to merge with his application. Be aware that this change may be over-written with maintenance supplied the VisualAge support team. Also, further changes to the code with the next version of VisualAge will overwrite this code and possible support of this feature in the next version may require changes to the customer's application to take advantage of the new feature. The VisualAge development team does not guarantee the code below and will not add bug fixes to it. The second implementation is totally programmatical and code is provided below under "Implementation 2." Another words, this code must be written for every stored procedure you wish to call. Or the customer may design a non visual re-usable part along these lines. Implementation 1: Go to the System Transcript menu and click on Smalltalk Tools/System/Change User and change to Library Supervisor. Then, go to the System Transcript/Smalltalk Tools and click on Manage Applications. Find and click on AbtRunDatabaseQueryPartApp, and choose Applications/Create New Edition. Then, in the second pane, click on AbtDatabaseQuery and choose Classes/Create New Edition. Drop a database query part on the layout surface of any composition editor. Bring up the context menu (second mouse button) and click on "edit part." Then, go to the Public Interface Editor for that part, click on the actions page and add a new action name called "executeStoredProcedure". In the action selector box, type "executeStoredProcedure". Go to the script editor for that part, click on the AbtDbRun-Internal category and write a script called "executeStoredProcedure" that looks like the following: executeStoredProcedure "Execute my query spec; no commits or rollbacks are issued." | result | result := self executeQuerySetUp. (( result isAbtError ) or: [result == nil]) ifFalse: [ result := self executeSelect ]. ^result Under File, save the part. Then, go back to the Application Manager window, find AbtRunDatabaseQueryPartApp, and click on AbtDatabaseQuery in the second pane. Under Classes click on Version Release All and name the version something that you will recognize later. Under Applications, choose Version Applications/Name Each and name the version the same as you did for the class. Then, go to the System Transcript menu and click on Smalltalk Tools/System/Change User and change back to your userid. In order for others in your group to take advantage of these changes they will have to load this version of AbtRunDatabaseQueryPartApp in their image. With this implementation, you can use the visual query part to manually create a query spec to call the stored procedure. Then tear off a result table from the query part. In order to present your data in a table format, you will need to drop a table part on the window and add columns to the table for each column that the stored procedure returns. For each column, you will need to open the settings and set the attribute name to the exact column name of the table in the database. Then, make two connections from the table to the result table part. Connect the table (rows) to the result table (rows) and the table (selectedRowIndex) to the result table (currentRow Index). Then, connect your event to run the query to the executeStoredProcedure action of the database query part. If you package your application as a runtime image, then you will not have to perform the next step. If you use the merge (.app) file packaging method, you will need to dump these changes and include them in your runtime application. To do this, execute the code below in a workspace or transcript window. |result| (result := ApplicationDumper new) dump: (AbtRunDatabaseQueryPartApp) intoFileNamed: 'abtdbqry.app'. result hasErrorOccurred ifTrue: [ self error: 'An error occurred when dumping the application'. result currentErrorString]. This will create a file in the current directory. This file must then be moved to your merge directory during the packaging step (User's Guide pp. 146-147). The .CNF file needs to be modified and "abtdbqry.app" needs to be added directly after the database .app files (abtbdb10.app, abtmdb10.app, and absql10.app) in the list. *********************************************************************** Implementation 2: This code, when implemented in a script for a view, will run a stored procedure and place the results in a list box on the window called "List". executeStoredProc " This code executes a SQL Server system stored procedure and puts the result table in a list box on the window. " | dbmgr resultTable qSpec db| dbmgr := AbtDbmSystem activeDatabaseMgr. (dbmgr notNil) ifTrue: [ db := dbmgr openDatabaseNamed: 'pubs'. qSpec := AbtQuerySpec new statement: 'sp_helpdb pubs'. resultTable := dbmgr databaseInUse resultTableFromQuerySpec: qSpec. (self subpartNamed: 'List') items: (resultTable asStrings) ].