janjan has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I'm trying to implement an Oracle-driven web application with Class::DBI. All is generally going well, except when I try to access the class that points to a view instead of a real table; I get errors like
Can't locate object method "search" via package "TestPkg::View" at /ho +me/janjan/test.pl line 33.
I get the same error no matter what method I call, which leads me to believe that the package just isn't working.

Now, I've taken a look at Class::DBI::View, and even tried it out -- but, alas, with the same error. It was then that I delved a little deeper into Class::DBI::View, and began to think that it's possible that it doesn't support Oracle.

I'm using perl 5.005_03, Class::DBI 0.90 (I know, I know -- but political reasons keep me from upgrading DBI.pm. Ugh.), and the latest version of Class::DBI::Oracle.

All of my other packages seem to work just fine. Is there anything else I can try, short of setting up a cron job to populate a real table from the view?

Many thanks!

Replies are listed 'Best First'.
Re: Class::DBI::Oracle and views
by perrin (Chancellor) on Sep 28, 2003 at 18:24 UTC
    Class::DBI::View is for simulating views, not for working with real ones. I can't tell quite what you're doing from your post. How about showing us the code for TestPkg::View and the script you called it from?
      Sure, and thank you. Here's test.pl:
      #!/usr/bin/perl -w use strict; require Modules.pl; my @students = TestPkg::View->retrieve_all; # returns the same error as search() would warn Dumper(\@students);
      And here's code from Modules.pl -- I'm not using Class::DBI::View in this version of the code, obviously. (Relevant info: this is a view containing enrollment data for a course.)
      package TestPkg::DBI; use base 'Class::DBI::Oracle'; TestPkg::DBI->set_db('Main', 'dbi:Oracle:devdv', 'username', 'password +'); package TestPkg::View; use base TestPkg::DBI; __PACKAGE__->table('course_enrollment'); __PACKAGE__->columns( All => qw/id username year term name_first name_ +last/ ); # and just for kicks, here's another package that's working just fine # it points to a table, not a view package TestPkg::Permissions; use base TestPkg::DBI; __PACKAGE__->table('permissions'); __PACKAGE__->columns( All => qw/id student_id access_level/);
      The view is just generated from a command like
      CREATE OR REPLACE VIEW course_enrollment AS SELECT [...]
      (it's of course much longer and nastier -- but I can select things from it on the command line just fine.)
        Well, I don't see anything wrong here. It's probably a bad idea to keep all of your packages in Modules.pl (as opposed to separate files) and there is no reason to use Class::DBI::Oracle if you're not using the set_up_table call, but neither of those should break it.

        Can you access this view from DBI when you don't go through Class::DBI?