Can't call method "Sql"... need help

Discussion in 'Perl Misc' started by sudhih@gmail.com, Feb 28, 2007.

  1. Guest

    hello,

    I have a problem CGI script. I am really sorry, this looks quite
    big...

    I created a package pkg::fetch_history.pm and placed it in c:\Perl
    \lib. Then I created a perl file to run from the commad promt. the
    program executed well without fail. The code is as follows,

    #!C:\Perl\bin\perl.exe
    use pkg::fetch_history;

    @dates = pkg::fetch_history::get_Dates();
    foreach $d (@dates)
    { print "\n",$d; }

    the data base exists locally.

    Then I created cgi script to populate the values into combo box, it
    says

    Can't call method "Sql" on an undefined value at C:/Perl/lib/pkg/
    fetch_history.pm line 20.

    I am not sure why is this. Below is the fetch_history.pm and
    combobox.cgi script.

    -----------------------------------------------------------------------------------------------
    #!C:\Perl\bin\perl.exe

    # this is fetch_history.pm

    package pkg::fetch_history;
    use strict;
    use Win32::ODBC;

    my $db = new Win32::ODBC('ServerStatistics'); #ODBC driver object
    #if (!$db)
    #{
    # print "Database could not be found\n";
    #}

    sub get_Dates
    {
    my $q = "select distinct(build_date) from wdf_history order by
    build_date";
    $db->Sql($q);
    my @dates;
    push(@dates, $db->Data()) while($db->FetchRow);

    return @dates;
    }
    ---------------------------------------------------------------------
    #!C:\Perl\bin\perl.exe

    use CGI::Carp qw(fatalsToBrowser);
    use CGI;
    use pkg::fetch_history;

    $cgi = new CGI;
    print $cgi->header;

    @dates = pkg::fetch_history::get_Dates();
    print "here is the dates value",@dates;
    print <<ENDHTML;
    <html>
    <head><title> Server statistics </title></head>
    <body>
    <select name="menu">
    ENDHTML


    foreach my $d(@datest)
    {
    print <<ENDHTML;
    <option value="$d" selected>(please select:)</option>
    <option value="$d">$d</option>
    ENDHTML

    }
    ------------------------------------------------------------------



    Am I wrong some where?


    Thank you,
    Regards,
    kath.
    , Feb 28, 2007
    #1
    1. Advertising

  2. perlguru Guest

    On Feb 28, 4:13 pm, wrote:
    > hello,
    >
    > I have a problem CGI script. I am really sorry, this looks quite
    > big...
    >
    > I created a package pkg::fetch_history.pm and placed it in c:\Perl
    > \lib. Then I created a perl file to run from the commad promt. the
    > program executed well without fail. The code is as follows,
    >
    > #!C:\Perl\bin\perl.exe
    > use pkg::fetch_history;
    >
    > @dates = pkg::fetch_history::get_Dates();
    > foreach $d (@dates)
    > { print "\n",$d; }
    >
    > the data base exists locally.
    >
    > Then I created cgi script to populate the values into combo box, it
    > says
    >
    > Can't call method "Sql" on an undefined value at C:/Perl/lib/pkg/
    > fetch_history.pm line 20.
    >
    > I am not sure why is this. Below is the fetch_history.pm and
    > combobox.cgi script.
    >
    > -----------------------------------------------------------------------------------------------
    > #!C:\Perl\bin\perl.exe
    >
    > # this is fetch_history.pm
    >
    > package pkg::fetch_history;
    > use strict;
    > use Win32::ODBC;
    >
    > my $db = new Win32::ODBC('ServerStatistics'); #ODBC driver object
    > #if (!$db)
    > #{
    > # print "Database could not be found\n";
    > #}
    >
    > sub get_Dates
    > {
    > my $q = "select distinct(build_date) from wdf_history order by
    > build_date";
    > $db->Sql($q);
    > my @dates;
    > push(@dates, $db->Data()) while($db->FetchRow);
    >
    > return @dates;}
    >
    > ---------------------------------------------------------------------
    > #!C:\Perl\bin\perl.exe
    >
    > use CGI::Carp qw(fatalsToBrowser);
    > use CGI;
    > use pkg::fetch_history;
    >
    > $cgi = new CGI;
    > print $cgi->header;
    >
    > @dates = pkg::fetch_history::get_Dates();
    > print "here is the dates value",@dates;
    > print <<ENDHTML;
    > <html>
    > <head><title> Server statistics </title></head>
    > <body>
    > <select name="menu">
    > ENDHTML
    >
    > foreach my $d(@datest)
    > {
    > print <<ENDHTML;
    > <option value="$d" selected>(please select:)</option>
    > <option value="$d">$d</option>
    > ENDHTML
    >
    > }
    > ------------------------------------------------------------------
    >
    > Am I wrong some where?
    >
    > Thank you,
    > Regards,
    > kath.



    If this script runs fine from command prompt, ..... then I think you
    should check with permission.
    I see that you are not catching error at the time of opening
    connection to database.
    While executing script from web, it executes with lower permission,
    and it may not be allowed to connect to database.

    Try catching error at the time of opening connection to database...
    perlguru, Feb 28, 2007
    #2
    1. Advertising

  3. kath Guest

    On Feb 28, 4:53 pm, "perlguru" <> wrote:
    > On Feb 28, 4:13 pm, wrote:
    >
    >
    >
    >
    >
    >
    >
    > > hello,

    >
    > > I have a problem CGI script. I am really sorry, this looks quite
    > > big...

    >
    > > I created a package pkg::fetch_history.pm and placed it in c:\Perl
    > > \lib. Then I created a perl file to run from the commad promt. the
    > > program executed well without fail. The code is as follows,

    >
    > > #!C:\Perl\bin\perl.exe
    > > use pkg::fetch_history;

    >
    > > @dates = pkg::fetch_history::get_Dates();
    > > foreach $d (@dates)
    > > { print "\n",$d; }

    >
    > > the data base exists locally.

    >
    > > Then I created cgi script to populate the values into combo box, it
    > > says

    >
    > > Can't call method "Sql" on an undefined value at C:/Perl/lib/pkg/
    > > fetch_history.pm line 20.

    >
    > > I am not sure why is this. Below is the fetch_history.pm and
    > > combobox.cgi script.

    >
    > > -----------------------------------------------------------------------------------------------
    > > #!C:\Perl\bin\perl.exe

    >
    > > # this is fetch_history.pm

    >
    > > package pkg::fetch_history;
    > > use strict;
    > > use Win32::ODBC;

    >
    > > my $db = new Win32::ODBC('ServerStatistics'); #ODBC driver object
    > > #if (!$db)
    > > #{
    > > # print "Database could not be found\n";
    > > #}

    >
    > > sub get_Dates
    > > {
    > > my $q = "select distinct(build_date) from wdf_history order by
    > > build_date";
    > > $db->Sql($q);
    > > my @dates;
    > > push(@dates, $db->Data()) while($db->FetchRow);

    >
    > > return @dates;}

    >
    > > ---------------------------------------------------------------------
    > > #!C:\Perl\bin\perl.exe

    >
    > > use CGI::Carp qw(fatalsToBrowser);
    > > use CGI;
    > > use pkg::fetch_history;

    >
    > > $cgi = new CGI;
    > > print $cgi->header;

    >
    > > @dates = pkg::fetch_history::get_Dates();
    > > print "here is the dates value",@dates;
    > > print <<ENDHTML;
    > > <html>
    > > <head><title> Server statistics </title></head>
    > > <body>
    > > <select name="menu">
    > > ENDHTML

    >
    > > foreach my $d(@datest)
    > > {
    > > print <<ENDHTML;
    > > <option value="$d" selected>(please select:)</option>
    > > <option value="$d">$d</option>
    > > ENDHTML

    >
    > > }
    > > ------------------------------------------------------------------

    >
    > > Am I wrong some where?

    >
    > > Thank you,
    > > Regards,
    > > kath.

    >
    > If this script runs fine from command prompt, ..... then I think you
    > should check with permission.
    > I see that you are not catching error at the time of opening
    > connection to database.
    > While executing script from web, it executes with lower permission,
    > and it may not be allowed to connect to database.
    >
    > Try catching error at the time of opening connection to database...


    Hi, thanks for the reply. you are right. The connection to database
    was not happening when run I from browser. But the same was working
    fine when I run in command prompt. Me and my friend figured it out
    that there wasn't establishing of connection to database was
    happening.

    Why only in the browser?

    Then later one thing flashed, that I was using local DSN(user DSN) to
    connect to database. Then I tried creating the System DSN tried to
    run, it was working.

    Any way, thanks a lot.


    Regards,
    kath.
    kath, Mar 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian
    Replies:
    2
    Views:
    341
    Ulrich Petri
    Sep 6, 2003
  2. Replies:
    3
    Views:
    301
  3. ecoolone
    Replies:
    0
    Views:
    755
    ecoolone
    Jan 3, 2008
  4. David
    Replies:
    4
    Views:
    151
    Bob Barrows [MVP]
    Sep 28, 2006
  5. aidy
    Replies:
    5
    Views:
    236
    Marcin Mielżyński
    Jun 4, 2006
Loading...

Share This Page