fhg
Volume 8, Number 4 -- January 30, 2008

Saving and Restoring External SQL Routine Definitions

Published: January 30, 2008

Hey, Mike:

A vendor whose software we use separates objects into two main libraries--a data library and an object library. I had to restore all the data, so I deleted the data library and restored it. After that, the application stopped working. The problem turned out to be that some stored procedures that they created in their data library got wiped out, and the Restore Library (RSTLIB) command didn't put them back. The story ends happily because the vendor had a program in place for just such emergencies, but (and I'm sure IBM disagrees), I consider this a big old bug in the SAVE/RESTORE command. If I restore a library, I want everything in the library restored.

--Joe


Well this is indeed a thorny problem. First let's review what's happening here:

  • The software has logic existing in program and/or service programs, presumably written in some high-level language such as RPG, C, or COBOL.
  • To make these programs available to the SQL world, the vendor executed the external version of the CREATE PROCEDURE SQL statement, which allows SQL to run these programs.
  • These external SQL routine definitions, whether they be stored procedures or user-defined functions, are stored in the SQL system catalogs in library QSYS2. Essentially these definitions are merely "pointers" telling DB2 for i5/OS how it can make use of high-level language (HLL) programs.

And now a problem arises. Since these definitions are more or less pointers, not i5/OS objects themselves, how should IBM handle saving and restoring them? The answer IBM came up with is to associate the external SQL routine definition with the corresponding HLL program or service program object. When the program object is backed up, the SQL routine definition is captured as well. Subsequently when the program object is restored, the SQL routine definition is restored. Therefore, restoring the library will not restore the SQL routine definition unless the program object is in that library.

In this case, the vendor chose to assign the SQL routine definitions' schema with the data library rather than the program library. Hence when the data library was deleted, all of the SQL routine definitions were deleted. When the data library was restored, only the data objects were put back on the system. Since the program objects were never restored, the SQL routine definitions were never re-created. As mentioned, IBM chose to associate the routine definition at the program and service program level rather than at the library level. I agree with this because you can control what is being restored at the object level--if you only restore one program then only that program's definition are restored. You wouldn't want to have to restore an entire library to restore the SQL routine definition for one program. Unfortunately, this creates a problem in this situation where the user wanted the routine definitions restored with the library.

To avoid this problem, generally I like to create the external SQL routine definitions in the same schema (i.e., library) as the HLL program objects. I don't know why the vendor opted to use this cross library approach. Perhaps there is a good reason, such as the application builds SQL statements that use the SQL naming convention and use qualified schema names--I'm only guessing.

Incidentally, there is one other thing to note when allowing for the saving and restoring of external SQL routine definitions. Because the definition is saved with the program object, the program object should exist when the external CREATE statement is issued because this is when the program object is supplied the extra SQL information needed to backup the routine definition. If the program does not exist when the CREATE statement is issued, the routine will still exist but you'll receive the following warning: SQL7909--Routine XYZ was created, but cannot be saved and restored.

This message simply signals that the SQL routine definition has been created but since no program object exists yet there is no way to associate the definition with the program for the save operation.

This also has implications for re-compilation of programs and service programs. A service program may have several associated SQL routines defined. Say a service program has 10 external routines defined against it. You fix a bug in the service program and then re-compile it. What then? The routine definitions are no longer associated with the service program object and hence will not be backed up.

The lesson here is that whenever you re-create a program that has one or more external SQL routines defined, you should drop and re-create the associated routine definitions so they continue to be associated with the program object and backed up as expected. To do this effectively, you may need to run SQL scripts for each of your program objects (similar to what this vendor did) so that this process is painless as possible.




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
PRODATA COMPUTER SERVICES

Push-Pull-Synchronize Data TODAY!

Finally, a product that provides easy and full SQL access to remote databases
from all System i high-level languages. Remote Database Connect gives you
easy access to remote databases from your System i programs.

Share real time data across platforms NOW!

Use RDB Connect today.....download a free trial NOW.

Order today and SAVE $$$!

800.228.6318

sales@prodatacomputer.com

www.prodatacomputer.com


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

COMMON:  Join us at the annual 2008 conference, March 30 - April 3, in Nashville, Tennessee
BCD:  WebSmart offers you more Web Application Development choices
Vision Solutions:  Enter to win an iPod Touch. Just download any of our DR planning resources


 

IT Jungle Store Top Book Picks

Getting Started with PHP for i5/OS: List Price, $59.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
IBM to Buy AMD? Seems Unlikely, But an Interesting Idea

i5/OS V6R1: It Must Be Getting Close, Since People Are Talking

Microsoft Rains on IBM's Lotusphere Parade

As I See It: Avatar Nation

Readers Pipe Up On the STG Reorg and System i Wish List

The Linux Beacon
openSUSE Build Service Pumps Out Red Hat, CentOS Packages

IBM to Buy AMD? Seems Unlikely, But an Interesting Idea

Lenovo Licenses X64 Server Designs from IBM to Build Boxes

As I See It: Avatar Nation

SOA Remains Hard to Define, but Projects on the Rise

Four Hundred Stuff
i5/OS V6R1 Announced Today, Ships in March

System i VoIP from Nortel Expected Soon

Who Needs a Web Application Firewall?

Reigning In IT Chaos is the Goal of Innotas

Oracle Updates Tools for JD Edwards EnterpriseOne

Big Iron
CA Offers Mainframe Software Bundles and Freebie Services

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
January 26, 2008: Volume 10, Number 4

January 19, 2008: Volume 10, Number 3

January 12, 2008: Volume 10, Number 2

January 5, 2008: Volume 10, Number 1

December 29, 2007: Volume 9, Number 52

December 22, 2007: Volume 9, Number 51

The Windows Observer
Microsoft Moves to Solidify Virtualization Offerings

Microsoft to IBM: Tolerate PSI Mainframes or Quit Europe

Dell Launches New, Power-Efficient Blade Servers

E-Government Program Unveiled by Microsoft

Microsoft Rains on IBM's Lotusphere Parade

The Unix Guardian
Sun Asks ISVs Why They Love Solaris

Weak Dollar, Services, and Power6 Give IBM a Solid Fourth Quarter

IBM Aims for Server Expansion in 2008

SOA Remains Hard to Define, but Projects on the Rise

The Rumor Mill on IBM's Impending Platform Announcements

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

ProData Computer Services
Guild Companies
WorksRight Software


Printer Friendly Version


TABLE OF CONTENTS
Saving and Restoring External SQL Routine Definitions

Create Multiple Directory Levels in One Swell Foop

User Storage Limits and Application Processing

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
FTP in arrival sequence

S36 environment problem

QSH won't write in batch!

SQL Trigger

usine switches in RPGIII???





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement