If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Executing statically bound SQL directly

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-10, 14:20
jkschneider jkschneider is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
Executing statically bound SQL directly

This may seem a bit paradoxical, but is there a special SQL command to target and execute an existing statically bound SQL package through the Command Editor or any other SQL client?

I noticed that when using the static profiling tool in match mode, if you create your JDBC connection with an auth id that does not have permission to execute the statically bound SQL, you get an error messsage saying something like:

"USER" does not have the privilege to perform operation "EXECUTE PACKAGE" on object "MYSCHEMA.MYPACKAGE1"

where '1' is the section number.

This led me to believe that perhaps EXECUTE PACKAGE was a valid DB2 SQL command, which does not appear to be the case.
Reply With Quote
  #2 (permalink)  
Old 10-11-10, 14:36
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
i think you are forgetting that static sql,
which when bound creates a package, which is a db2 object.
db2 objects have attributes, one of which is the privilege(authority) to execute/access......
user requires privilege to execute the package,
same as user requires the privilege (authority) to access any other db2 object, like a table.
__________________
Dick Brenholtz, Ami in Deutschland
Reply With Quote
  #3 (permalink)  
Old 10-11-10, 15:29
jkschneider jkschneider is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
dbzTHEdinosaur,

Thank you for the reply, and I can see where my original post was a little misleading. The error about the lack of privileges was corrected by changing which user I authenticated with and it did run statically thereafter. I only mentioned the error because it clued me in to the possibility that I could invoke statically bound SQL through some command (with the right auth id).

More specifically, I am using the JDBC type 2 driver and:

StaticMode = MATCH

I can see how the driver is matching the dynamic sql statement with the statically bound schema, package, and section number, but what is unclear to me is how it is using these three pieces of information to actually INVOKE the bound query.

To be completely honest, I am after a poor man's pureQuery here for type 4 drivers.

1. I know I can easily recreate the capture file and use the db2cap executable to perform the bind operation.
2. I know I can easily match up the dynamic sql with the schema, package, and section number.
3. How do I execute the static SQL?
Reply With Quote
  #4 (permalink)  
Old 10-11-10, 16:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You can GRANT EXECUTE ON PACKAGE, but it won't do you any good since the package must match up with the program that it was original created from (as embedded SQL).

I suspect that you would be satisfied with a UDF (more powerful than many realize in newer releases of DB2 LUW) or a stored procedure.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 10-12-10, 08:34
jkschneider jkschneider is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
Marcus,

Thank you for this tidbit: "You can GRANT EXECUTE ON PACKAGE"

Now we are at the heart of the issue: "the package must match up with the program that it was original created from".

What does it mean for the package to match up with the program that it was originally created from? Is the type 2 driver in MATCH StaticMode sending the CONTOKEN or some other piece of data in a hidden and proprietary way to DB2 prior to executing the package? Is there no equivalent in the type 4 driver? Can I somehow employ a UDF to do this program-to-package handshaking before attempting to execute the package?
Reply With Quote
  #6 (permalink)  
Old 10-12-10, 09:31
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You cannot directly execute a package. You can execute a program that executes the package. In your case I am assuming a UDF or Stored Procedure is the best choice.

When an application program is written with embedded static SQL (including static SQL in a UDF or SP), the SQL is replaced in the DB2 pre-compiler with calls to DB2 using a package created for that program. The consistency token of the package must match to make sure the right version of the package matches the right version of the program (the program is modified by the DB2 pre-compiler to store the consistency token in the program, and of course it also exists in the package).

I don't understand what you trying to do that you can't use a UDF or SP?
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On