[jifty-devel] Jifty::DBI manpage buglet and a candidate for a FAQ

Kevin Falcone falcone at bestpractical.com
Tue May 22 14:48:07 EDT 2007


On May 21, 2007, at 8:43 PM, Andreas J. Koenig wrote:

> I have completed the Jifty::Manual::Tutorial and after that I had the
> desire to see the content of the database with Jifty's own means, not
> in the browser but in perl. So I took the Synopsis of the
> Jifty::DBI::Collection manpage and adjusted the filename and tried to
> guess the rest. Apparently the manpage has the capitalization wrong? I
> then did adjust the driver and database parameters to lowercase but I
> could not figure out how to use Jifty::DBI directly. I won't bother
> you with all the wrong solutions I tried:-/

The Collection manpage definitely needs a Synopsis update.
I'm working on that.

You probably want to read David's response since you're using JIfty::DBI
in the context of Jifty and you need a Jifty->new to properly  
instantiate
the ClassLoader and all the associated classes.

This is code that will make it into the Synopsis in a little bit

#!perl
use Jifty::DBI::Collection;
use lib 'lib';

package MyWeblog::PostCollection;
use base qw/Jifty::DBI::Collection/;

package MyWeblog::Post;
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema { };

package main;

use Jifty::DBI::Handle;
my $handle = Jifty::DBI::Handle->new();
$handle->connect( driver => "SQLite", database => "myweblog" );

my $sb = MyWeblog::PostCollection->new( handle => $handle );

$sb->limit( column => "title", value => "post1" );

while ( my $record = $sb->next ) {
     print $record->id;
}


If you're going to use it in the context of jifty, you can do this

!perl
use lib 'lib';
use Jifty;
Jifty->new;

my $sb = MyWeblog::Model::PostCollection->new;

$sb->limit( column => "title", value => "post1" );

while ( my $record = $sb->next ) {
     print $record->id;
}

-kevin

>
> Can somebody post a solution?
>
> % /home/src/perl/repoperls/installed-perls/*/p*/perl-5.*@31162/bin/ 
> perl -le '
>
>   use Jifty::DBI::Collection;
>
>   package MyWeblog::Record;
>   use base qw/Jifty::DBI::Collection/;
>
>   package main;
>
>   use Jifty::DBI::Handle;
>   my $handle = Jifty::DBI::Handle->new();
>   $handle->connect( Driver => "SQLite", Database => "myweblog" );
>
>   my $sb = MyWeblog::Record->new( handle => $handle );
>
>   $sb->limit( column => "column_1", value => "matchstring" );
>
>   while ( my $record = $sb->next ) {
>       print $record->my_column_name();
>   }
> '
> Can't connect to data source 'Database=myweblog;Driver=SQLite'  
> because I can't work out what driver to use (it doesn't seem to  
> contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not  
> set) at /home/src/perl/repoperls/installed-perls/maint-5.8/pyVlEUy/ 
> perl-5.8.0 at 31162/lib/site_perl/5.8.8/Jifty/DBI/Handle.pm line 108
>
>
>
> -- 
> andreas
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel



More information about the jifty-devel mailing list