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
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.my $user = MyUserClass->new( {u_name=>"mrwong",u_password=>"jshdghjashjd"}); $user->save;
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:
MyUserClass.pm:#!/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"; } }
DataSource.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; }
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;
Any suggestions, comments would be appreciated. Thanks. --t. alexSPOPS::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.
In reply to SPOPS fetch problems by talexb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |