RE: Calling DB2 Stored Procedures through DBD::ODBC
From: Jeff Urlwin (jurlwin_at_esoftmatic.com)
Date: 08/07/04
- Next message: Shanmugam Papuswamy: "PERL: DBD issue: (DBD-Oracle-1.15) Installation Problem in Solaris [SunOS 5.8]"
- Previous message: Samarth Kumar: "Calling DB2 Stored Procedures through DBD::ODBC"
- In reply to: Samarth Kumar: "Calling DB2 Stored Procedures through DBD::ODBC"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: <samarth_kumar@vanguard.com>, <dbi-users@perl.org> Date: Fri, 6 Aug 2004 18:21:36 -0400
>
> Folks,
>
> I am not sure if this has been answered before or not but on
> searching the
> list archives I haven't been able to get an answer. I am
> connecting to DB2
> using DBD::ODBC and am also able to run select statements.
> Now I have to
> run a stored procedure through the connection and was
> wondering if this is
> possible through the ODBC driver or do I have to install the
> native DB2
> driver.
Please see the DBD-ODBC distribution tarballs for examples in the t\*.t and
mytest\*.pl directories. t\20SqlServer.t and t\30Oracle.t have examples for
those systems. Testproc*.pl in the mytest should have some samples, too,
but the "mytest" directory is to handle specific things above and beyond
normal and a play area. Since some of the items have use as examples, I
publish them there.
Also, if you would like to contribute syntax for creating simple stored
procs for DB2, I am *happy* to include them in the tests in the same manner
that the SQLServer and Oracle tests are conducted. The more RDBMSs the
better, IMHO.
The short answer is you need the ODBC syntax wrapped around it.
{? = call func_with_no_params() } # note your system may not like
the extra ()
# see
bind_param_inout
{ call proc() } # procedure, not function,
no expected return
{ ? = call func_with_params(?, ?, ?) }
Etc
>
> The second thing is if I can run the stored procedure through
> ODBC then
> can anyone please forward me sample code that shows how to do
> this as I
> have written snippets of code which are able to connect to
> DB2 but do not
> run the stored procedure. They are attached with this email.
The {} are important, I think. Try those in your code below.
Jeff
>
> Any help in this matter would be greatly welcome!!
>
> Thanks in advance,
>
> Samarth
>
>
> #!j:\perl\bin\perl
>
> use DBI;
> use CGI qw( :standard );
> use CGI::Carp qw( warningsToBrowser fatalsToBrowser );
>
> my $subsystem = "DQ0G";
> my $collectionID = "AVGI00";
> my $username = "";
> my $password = "";
>
> print( "Content-type: text/html\n\n" );
> print( "<html>\n" );
> print( "\t<head>\n" );
> print( "\t\t<title>DBI Connection Test</title>\n" );
> print( "\t</head>\n" );
> print( "<body>\n" );
>
> my $dbh = DBI -> connect( "DBI:ODBC:$subsystem", "$username",
> "$password"
> );
>
> if( !$dbh ) {
> print( "Unable to connect to database!!" . DBI -> errstr );
> exit;
> }
> else {
> print( "Connected to DB2!!\n" );
> }
> my $rv = $dbh -> prepare( 'call
> dq0gwcat.eposp522(\'AVGI00\',\'CIA\',\'WECIACAT\',\'IIOW\',\'2
> 004-08-05-12.10.23.798322\',\'N\',0,0,0,\'
> \',\' \',\'Y\',\' \',115436746,364285835)' );
>
> if( !rv ) {
> print( "Unable to prepare select statement: " . $dbh -> errstr );
> $dbh -> disconnect;
> exit;
> }
>
> $rv -> execute();
>
> print( "Executed stored procedure" );
>
> $rv -> finish;
> $dbh -> disconnect;
>
> print( "</body>" );
> print( "</html>\n" );
>
- Next message: Shanmugam Papuswamy: "PERL: DBD issue: (DBD-Oracle-1.15) Installation Problem in Solaris [SunOS 5.8]"
- Previous message: Samarth Kumar: "Calling DB2 Stored Procedures through DBD::ODBC"
- In reply to: Samarth Kumar: "Calling DB2 Stored Procedures through DBD::ODBC"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|