I have been able to get save to work, but fetch still doesn't work. Hopefully someone can suggest an avenue for me to follow.

I am accessing a Postgres database, and the code

my $user = MyUserClass->new( {u_name=>"mrwong",u_password=>"jshdghjashjd"}); $user->save;
works fine .. a new user is created in the database. When I try to fetch a user, either using fetch or fetch_group I get what appears to be an internal error in SPOPS.

I am assuming that I have the configuration wrong, but after some time spent reading the man pages, I'm not sure what mistake I'm making.

test1.pl:

#!/usr/bin/perl -w use SPOPS; use MyUserClass; { SPOPS::set_global_debug( debug => 1 ); my $otherUser = MyUserClass->fetch(4); foreach my $key ( keys %$otherUser ) { print "Key $key: $otherUser->{$key}\n"; } }
MyUserClass.pm:
package MyUserClass; use strict; use SPOPS::Initialize; my $spops = { 'users' => { class => 'MyUserClass', field => [ 'u_name', 'u_password' ], isa => [qw/Datasource SPOPS::DBI::Pg SPOPS::DBI/], id_field => ['u_id'], base_table => 'users', field_discover => 'no', }, }; { SPOPS::Initialize->process( { config => $spops } ); } sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; my $vars = shift; foreach my $key ( keys %{$vars} ) { $self->{$key} = $vars->{$key}; } bless $self, $class; return $self; }
DataSource.pm:
package Datasource; use strict; use DBI; my ($dbh); sub global_datasource_handle { my ($class) = @_; return $dbh if ($dbh); $dbh = DBI->connect( 'DBI:Pg:dbname=xxx', 'xxx', 'xxx', { RaiseError => 1, PrintError => 0 } ); unless ($dbh) { die "Cannot create database handle! Error: $DBI::errstr\n"; } return $dbh; } 1;
The error that I get:
SPOPS::ruleset_process_action (323) >> Trying to process pre_fetch_act +ion for a MyUserClass type of object SPOPS::clear_all_loaded (399) >> Clearing all fields to unloaded for o +bject class MyUserClass Can't use an undefined value as a HASH reference at /usr/lib/perl5/sit +e_perl/5.8.0/SPOPS.pm line 400. Use of uninitialized value in concatenation (.) or string at /usr/lib/ +perl5/site_perl/5.8.0/SPOPS.pm line 173.
Any suggestions, comments would be appreciated. Thanks.

--t. alex
Life is short: get busy!

In reply to SPOPS fetch problems by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.