Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: SQL in perl/tk

by vsurend (Novice)
on Jan 16, 2012 at 06:33 UTC ( [id://948067]=note: print w/replies, xml ) Need Help??


in reply to Re: SQL in perl/tk
in thread SQL in perl/tk

Hi All, Thanks a lot for all the replies. I have tried to include the piece of SQL code by inserting into my code. But this too is not giving any results. I am using the correct Userid/pwd/schema etc. for this. Please find the piece of code I have written.

use strict; use Tk; use Tk::BrowseEntry; use Tk::LabFrame; use Tk::JPEG; use DBI; use DBD::Oracle; use Spreadsheet::WriteExcel; . . . . . . . sub generateDailyReport{ #Create Excel my $workbook = Spreadsheet::WriteExcel->new('Report.xls'); my $worksheet = $workbook->add_worksheet(); my $from_date = @_[0]; my $to_date = @_[1]; #Connect to DB my $dbh = DBI->connect("dbi:Oracle:cecdev9","asdm_dev","c1sc0pass" +) or die "cannot connect $DBI::errstr\n"; my $sth = $dbh->prepare("SELECT gamm.PROCESS_NAME, GAMM.APPLI +CATION_NAME, TO_CHAR (TRUNC (gmz.testtime - 7 / 24, 'DD'),'MM/DD/YYYY +') Fiscal_Day,ROUND (AVG(DECODE (total_response_time, 0, NULL, total_ +response_time) / DECODE (total_page_count,0, 1,total_page_count))/ 10 +00,2) Average_Response_time FROM portal_gomez_bb_load gmz, GOMEZ_AP +P_MAPPING_MASTER gamm WHERE gmz.monitor_id = 3805260 AND (gamm.PROC +ESS_NAME = 'SAM_Exact_Product_Search' OR gamm.APPLICATION_NAME = 'SAM +_Exact_Product_Search') AND trunc(gmz.testtime) BETWEEN to_date('09/1 +2/2011','MM/DD/YYYY') AND to_date('09/15/2011','MM/DD/YYYY') AND succ +ess_flag = 0 GROUP BY gamm.PROCESS_NAME,GAMM.APPLICATION_NAME,TO_CH +AR (TRUNC (gmz.testtime - 7 / 24, 'DD'),'MM/DD/YYYY')"); #execute the query $sth->execute(); my $i = "A1"; my $j = 1; while ( my @row = $sth->fetchrow_array( ) ) { print "@row\n"; $worksheet->write($i, \@row); $j=$j+1; $i="A$j"; open(FILE,'Report.xls'); } }
Please help. Thanks, Vidya Surendran

Replies are listed 'Best First'.
Re^3: SQL in perl/tk
by marto (Cardinal) on Jan 16, 2012 at 10:43 UTC

    Did you read the replies you already have? I advised that you look at tracing, which you've not done in this example.

      Hi Marto, Yes I checked. But I am afraid, I dont know how to check the trace for DBD. Can you please help. :( Thanks, Vidya Surendran

        After the connect do DBI->trace(3);, see Tracing for an explanation of trace levels.

        Update: See also RaiseError attribute in the DBI docs.

        :) You open your browser and point it at the documentation for DBI you hit Ctrl+F button and type "trace" and you find it

Re^3: SQL in perl/tk
by chacham (Prior) on Jan 16, 2012 at 11:45 UTC
    Check for an error: die $dbh->errstr if ! defined $msg;

    Not only after the DB connect, but after the statement is run.

      Hurray! got the issue... It was that wrong userid/pwd that eat up my days....Thanks a lot for all the valuable suggestions.....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://948067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found