Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Clarification on Class::DBI wackiness

by spork (Monk)
on Aug 03, 2005 at 16:06 UTC ( [id://480535]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to set up an object with the aid of Class::DBI (actually Class::DBI::Sybase) All classes have been set up according to the documentation and I wrote a quick program to verify C::D behavior. The original test program ran retrieve_all() which was successful. However when I run a search() based on the PK an error is returned "sth_to_objects needs a statement handle".

Looking under the hood we find that indeed $sth is not valued, but oddly enough when sth_to_objects() is called (from within C::D itself) $sth is not even passed.

Obviously it must be something that I am doing wrong if there is plenty documentation on how to use the module, but nothing on the strange behavior experience by this humble monk.

Any advice?

Code and results...

The base class...

package user::user; use base 'Class::DBI::Sybase'; user::user->set_db('Main', 'DBI:Sybase:database=YYYYYY;server=127.0.0. +1;textsize=4550', 'xxxxxxxx', 'xxxxxxxx'); __PACKAGE__->table('users'); __PACKAGE__->columns(All => 'recnum', 'firstname', 'lastname', 'email' +); 1;
The test program
#!/usr/bin/perl -w use strict; use user::user; use Data::Dumper; my @cols = user::user->columns; print "COLUMNS:\n"; print "$_\n" foreach @cols; print "\n\nAnd now the table data...\n"; my @obj = user::user->search(recnum =>1); print "$_\n" foreach @obj;
The results
COLUMNS: lastname firstname email recnum And now the table data... sth_to_objects needs a statement handle at ./ line 38

Thanks in advance

Replies are listed 'Best First'.
Re: Clarification on Class::DBI wackiness
by Joost (Canon) on Aug 03, 2005 at 16:11 UTC
      Thanks for the advice. I made the change to using connection(), but still get the same results.
Re: Clarification on Class::DBI wackiness
by cees (Curate) on Aug 03, 2005 at 16:57 UTC

    Try and use set_up_table instead of table and columns to configure your CDBI class to see if that makes a difference.


    set_up_table will read all the table information (like column names and primary keys and more) directly from the DB and setup your CDBI class for you.

      Good tip. However set_up_table() returned all of the column names (original post represented a subset of the table columns) but still presented the "statement handle" error message when running search().

      I'm stumped as to why retrieve_all() is successful while search is not coming from the same base class.

        Are you sure it is not something else in your code that is causing this. The code you provide above looks like it should work fine. But your error message mentions the error occurs on line 35 of your test file. This tells me you have a bunch of other stuff in your test file. Strip your code down to bare minimum and test it again.

        Also, test your code out using SQLite instead of Sybase. This may give you a hint as to what is going wrong as well. If the same error happens again, then we know it isn't the Sybase module causing the problem, and most likely it is with your code.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://480535]
Approved by Joost
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-06-16 16:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.