mtrasp has asked for the wisdom of the Perl Monks concerning the following question:
Hi any one can explain below Subroutine. original subroutine has only one argument but i need to pass two argument to below stored procedure. original way of calling Sub is ExecStoredProcedureArg1("pr_CustomForPV", $AutoNumber, "IsCustom") I have changed the sub to like ExecStoredProcedureArg1("pr_CustomForPV", "$VersionID,$AutoNumber", "IsCustom"). it is still working fine. my question is how the sub is working with two parameters and please explain subroutine what is qq.what is fetch row? what i need to learn to understand this subroutine.
stored procedure: In the below procedure i have added @number parameter.original stored procedure has only one parameterif (0 != ExecStoredProcedureArg1("pr_CustomForPV", "$VersionID,$AutoN +umber", "IsCustom")) { # Do some thing } sub ExecStoredProcedureArg1($$$) { writelog(info,"Entering ExecStoredProcedureArg1() : ===="); my ($strStoredProc,$strArg, $strResultField) = @_; my $strResultValue = ""; my $mydb = Win32::ODBC->new($DSN); if (!$mydb) { Win32::ODBC::DumpError(); writelog(logdie,"Failed to connect to $DB_SERVER!"); } my $sql = qq|$strStoredProc $strArg|; if ($mydb->Sql($sql)) { Win32::ODBC::DumpError(); } if ($mydb->FetchRow()) { %DataSet = $mydb->DataHash(); $strResultValue = $DataSet{$strResultField}; } else { writelog(info,"No row found for $strResultField"); $mydb->Close(); } $mydb->Close(); writelog(info,"$strStoredProc $strArg for $strResultField: value += $strResultValue"); writelog(info,"Exiting ExecStoredProcedureArg1() : ===="); return $strResultValue; }
CREATE PROCEDURE dbo.pr_CustomForPV ( @VersionID int, @Number int ) AS SELECT CASE WHEN U.SourceFileName IS NOT NULL Then 1 ELSE 0 END AS IsCustom # some joins
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling Stored procedure from perl
by desemondo (Hermit) on Mar 02, 2010 at 01:36 UTC | |
by mtrasp (Acolyte) on Mar 02, 2010 at 05:44 UTC | |
by Utilitarian (Vicar) on Mar 02, 2010 at 08:54 UTC |