[CDBI] Something is wrong when use Class::DBI to search

[prev] [thread] [next] [Date index for 2005/08/15]

From: Ye Wenbin
Subject: [CDBI] Something is wrong when use Class::DBI to search
Date: 01:40 on 15 Aug 2005
I had a problem when I use the Class::DBI module. I had a simple table  
that store a reference id and
a author id. But when i use reference id to search all author id, the  
output is weird.

this is my scripts:

use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('dbi:mysql:ref');
my $sth;
$sth = $dbh->prepare("describe refau");
$sth->execute;
print "Table Scheme:\n";
print $sth->dump_results, "\n";

$sth = $dbh->prepare("select * from refau");
$sth->execute;
print "Data:\n";;
print $sth->dump_results, "\n";

package Refer::DBI;
use base 'Class::DBI';
Refer::DBI->connection('dbi:mysql:ref');

package Refer::Ref;
use base 'Refer::DBI';

Refer::Ref->table('refau');
Refer::Ref->columns(All => qw/auto_ref auto_au/);


package main;
my @all = Refer::Ref->retrieve_all;
print "Data:\n";;
p(\@all);

print "Authors:\n";
my @a = Refer::Ref->search(auto_ref => 1);
p(\@a);

sub p {
   my @a = @{shift @_};

   foreach (@a) {
     print $_->auto_ref, "\t";
     print $_->auto_au, "\n";
   }
}

__DATA__

The output like this:
Table Scheme:
'auto_ref', 'int(11)', 'YES', 'MUL', undef, ''
'auto_au', 'int(11)', 'YES', '', undef, ''
2 rows
2
Data:
'1', '1'
'1', '2'
'1', '3'
'2', '4'
'2', '5'
'2', '6'
6 rows
6
Data:
11
11
11
24
24
24
Authors:
11
11
11

Waiting for you answers. Thank your very much.
With best wishes!

        -- 
        Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] Something is wrong when use Class::DBI to search
Ye Wenbin 01:40 on 15 Aug 2005

Generated at 13:17 on 19 Aug 2005 by mariachi v0.52