User Information
| 1) jshirley [Catalyst] DBI Exception: DBD::SQLite::db prepare_cached failed |
|
|
| A couple things wrong: 1) This is a DBIx::Class problem, of which there is a separate list. This is... |
|
|
|
|
|
|
|
On Thu, Oct 9, 2008 at 9:00 PM, Proud Dzambukira <proudd@gmail.com> wrote: > Hi, > > I am very new to Catalyst and have found it pretty exciting so far. I have a > very basic "People" database table and whenever I try to run the following > script: > > > #!/usr/bin/perl > > use strict; > use warnings; > > use lib qw( lib ../lib ); > > > use Markets::Schema::MarketDB; > use Markets::Model::MarketDB; > > # demonstrate picking up database connection info > my $connect_info = Markets::Model::MarketDB->config->{connect_info}; > print "connecting schema to ".$connect_info->[0]."\n"; > > # connect to the Catalyst schema > my $schema = Markets::Schema::MarketDB->connect( @$connect_info ); > > > # list all People > print "listing all People\n"; > my $rs = $schema->resultset('People')->search({}); > for my $row ( $rs->all ){ > print "\nPerson ". $row->id ."\t - Name " . $row->first_name . "\n"; > } > > 1; > > from .../markets/script/test.pl I get the following error: > > connecting schema to dbi:SQLite:database > listing all People > DBIx::Class::ResultSet::all(): DBI Exception: DBD::SQLite::db prepare_cached > failed: no such table: people(1) at dbdimp.c line 271 [for Statement "SELECT > me.id, me.first_name, me.last_name FROM people me"] at test.pl line 26 > > It seems I am successfully connecting but failing to read from my database? > Any ideas what I may be doing wrong? Please help!
A couple things wrong: 1) This is a DBIx::Class problem, of which there is a separate list. This is for Catalyst, the MVC framework. You can subscribe to that list at http://lists.scsys.co.uk/mailman/listinfo/dbix-class/2) You haven't deployed your database. The table doesn't exist. When you get an error that says "no such table: people" the problem is quite clearly defined. There is no such table. You can read about deploying here: http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Schema.pm#deployThanks, -J
|
|
|
| 2) jshirley Fwd: [Catalyst] Model--best practice help |
|
|
| I'm an idiot and don't know how to use my mail client. Somehow this got offlist, but it really is a... |
|
|
|
|
|
|
|
I'm an idiot and don't know how to use my mail client. Somehow this got offlist, but it really is a good discussion...
---------- Forwarded message ---------- From: J. Shirley <jshirley@gmail.com> Date: Mon, Oct 6, 2008 at 9:35 AM Subject: Re: [Catalyst] Model--best practice help To: [email protected: bg2...@yahoo.com]
On Mon, Oct 6, 2008 at 9:08 AM, Dr. Jennifer Nussbaum <bg271828@yahoo.com> wrote: > (things trimmed, and also you replied to me personally but not the list, dont know if that was intentional) > > > > --- On Mon, 10/6/08, J. Shirley <jshirley@gmail.com> wrote: > >> >> > Jen >> >> My example -was- simple multiple inheritance. That is what >> the >> multiple packages in "use base" does. >> >> >> use base qw/Catalyst::Model::DBIC::Schema >> MyApp::Model::Book/; > > i understand that this was MI, but my point was that if i still have to call the "Cat" model class one way, and the schema model class the other > way, it doesnt really help. What is need is to call a single model, regardless of what im doing. > > Putting it another way, it shouldnt matter to the *Cat* programmer whether a function is in the DBIC schema (like "search" or "find", or even something > else thats customized in the schema class), or is in the Cat model class. The programmer should just be able to call $c->model('Book') (or anything > else that's regular). >
[Full Stop]
If you want this, you can't use Catalyst::Model::DBIC::Schema at all. It generates a model class for every schema class.
When you call $c->model('Book') what do you want to get back? What is MyApp::Model::Book? What do you want it to be? Do you want it to be a MyApp::Model::DBIC::Book class (or whatever your Model::DBIC::Schema generates as the name)?
>> >> Eden posted a very simple Moose example to get you going >> down that >> path. If you modified your lib/MyApp/Model/MyApp.pm to >> inherit from >> other classes (cat specific or not) then the methods from >> those would >> be accessible via >> $c->model('MyApp')->whatever. That's the >> method I >> showed. > > i understand that Edens example was simple and clear, and i do appreciate > it. But it does still involve learning something about Moose, or in > some cases convincing one's bosses that a project needs an entirely new OO layer to make it work. > >> Basically at this point, without knowing your exact >> codeframework >> you're only going to get these vague Multiple >> Inheritance 101 answers. >> Just with or without Moose :) > > I appreciate the time youve spent on this, but i dont think its necessary to show my whole codebase. Let me try once more explain what i want to > do, with a more specific example, then: > > Suppose i have a library application with the setup as described before, that is a DBIC schema group of classes set up and a MyApp::Model area. > > I want to write a method called get_books_by_purchase_date($foo), where > $foo is some parameters taken from a Cat search form. In other words > this function is clearly related to Cat, and not to the database layer, > because it needs to do something related to my Cat app, and i wouldnt > call it from an app thats not running on Cat. >
If $foo is processed, I don't see why that isn't a resultset method, tbh.
$schema->resultset('Book')->get_books_by_purchase_date($criteria); $c->model('Schema::Book')->get_books_by_purchase_date($criteria);
What is Catalyst specific is generating the search criteria, right? Could you explain -why- you wouldn't call it from an application that isn't Catalyst-based? It seems that is would be a useful method on the resultset later, and just an artificial restriction that it is Catalyst-based (but again, don't know the role)
> Where do i put this function? If i put it in MyApp::Model::Books, then i > have to remember that it's $c->model('Books')->get_books_by_purchase_date($foo), but it's > $c->model('MyAppDB::Books')->find($id). That's a pain, especially if my real > example is actually more complicated, and i want to (for instance) have the > base of a chain that sets the model in the stash, and then in later parts of the chain > do something based on the model, but i cant do these because for a given > table i have two different models depending on whether im using a > DBIC method or my own method. > > That is about the clearest i can be. If ive been misunderstanding you all along, i apologize. >
Well, aside from not understand -why- you want to do it, the answer is probably "Programming". Right now you are using Catalyst::Model::DBIC::Schema which simply creates a map of your schema classes to a model class. What you want is to decorate the model class that is generated and add additional methods to it. Not to harp on Moose, but... Moose would make this -much- easier.
To start with, you'll want to read the source for Catalyst::Model::DBIC::Schema, specifically just "sub new { }" -- there you will see how the model classes are instantiated.
The meat of it is just: foreach my $moniker ($self->schema->sources) { my $classname = "${class}::$moniker"; *{"${classname}::ACCEPT_CONTEXT"} = sub { shift; shift->model($model_name)->resultset($moniker); } }
What this does is creates a Model::$Name that is simply a ResultSet. At this point, what you -could- do, is set the resultset class to something Catalyst specific. That would give you methods on $c->model("Schema::$Name").
So, something like: sub { shift; my $schema = shift->model($model_name)->schema; my $source = $schema->source( $moniker ); $source->resultset_class("MyApp::Custom::ResultSet"); $source->resultset; }
Now, every MyApp::Model::DBIC::* class would have the resultset methods. You could only apply this on certain monikers (moniker would be 'Book', etc).
(I'm sure Eden or Matt can hop in here and do something better while I go put on my pointy hair)
|
|
|
| 3) jshirley See my comment at the end (was: Re: [Catalyst] Troubleshooting Help Please) |
|
|
| Sounds like you need a better mail reader? :) Show/hide quotes, configure to bottom post. I... |
|
|
|
|
|
|
|
On Mon, Oct 6, 2008 at 7:43 AM, Chisel Wright <chisel@herlpacker.co.uk> wrote: > On Mon, Oct 06, 2008 at 09:30:42AM -0500, James R. Leu wrote: >> See my comment at the end. > > I'm sorry if I start a flame-war, but is there any reason why long posts > don't get trimmed in this (and other) posts? > > It happens quite a bit, and I seem to spend half my time scrolling past > the un-trimmed posts I've already read earlier in the thread. > > Maybe we should switch to top-posting *G* >
Sounds like you need a better mail reader? :) Show/hide quotes, configure to bottom post. I actually like the gmail web reader for mailing lists purely because of the way it handles hiding quotes.
|
|
|
| 4) jshirley [Catalyst] Troubleshooting Help Please |
|
|
| Please also send your applications configuration so we can see your auth store. I do just have to... |
|
|
|
|
|
|
|
On Mon, Oct 6, 2008 at 6:47 AM, Paul Cory <pcory@wcpss.net> wrote: > All, > > I've Googled repeatedly, and RTFMed, and I've reached a point where I have > to ask for help. > > I have a Catalyst Web App that requires users to log in before they can do > anything (it's a front end for managing mailing list subscriptions). > > This runs on Apache 1.3/mod_perl 1/perl 5.8.8/MySQL 5.0 on SLES 10. Apache, > perl and mod_perl are compiled from source, not the distribution versions. > > The problem is that as the day progresses, and the application sees more and > more use, login behavior becomes inconsistent. > > It starts out working flawlessly. Then, after a while, valid logins start to > occasionally fail. Trying again gets you in - at the start. As time passes, > the problem gets progressively worse and it eventually gets to the point > where people quit trying because the success rate for logging in drops to > 10% or less. > > By fail, I mean you go to the log in screen, put in a valid username and > password combination, and then get seamlessly redirected to the log in > screen, as if you had just arrived fresh to the app. > > Restarting Apache solves the problem, at least for a while. And then things > begin to degrade again... > > I've verified that the problem is not end user error. Once you get it to > recognize your login, the system work fine. > > Other Web Apps I've written, using HTML::Mason and running on this exact > same server under mod_perl do not exhibit this behavior. > > I've checked the Apache error log, and I can't find any related errors. > > I'm using the following plug-in for authentication: > > Authentication > Session > Session::Store::FastMmap > Session::State::Cookie > > > The problem did not appear in testing, only in production. > > Any ideas on where to look, or what to try? > > FWIW, here's the login controller code (no promises on it being great - > programming is something I've learned in self-defense). The controller > handles log ins for both the regular and admin side of the application. > First it checks the regular users realm, and, if that fails, then the admin > users realm (two separate databases) . > > > > package esubscription::Controller::Login; > > use strict; > use warnings; > use base 'Catalyst::Controller'; > > > > sub index : Private { > my ( $self, $c ) = @_; > > # Get the username and password from form > my $login = $c->request->params->{login} || ""; > my $password = $c->request->params->{password} || ""; > > # If the username and password values were found in form > if ($login && $password) { > # Attempt to log the user in > if ( $c->authenticate({login => $login, password => $password}) ) > { > # If successful, then let them use the application > $c->response->redirect($c->uri_for('/')); > return; > } else { > > if ( $c->authenticate({login => $login, password => > $password}, 'admin') ) { > > $c->response->redirect($c->uri_for('/admin/')); > return; > > } > > else { # Set an error message > > $c->stash->{message} = "Bad username or password."; > $c->stash->{login} = "$login"; > } > } > } > > # If either of above don't work out, send to the login page > $c->stash->{template} = 'templates/forms/login_form.mas'; > } > > > > 1; > > > > Also, there's this snippet in the root controller that handles checking for > valid user: > > # If a user doesn't exist, force login > > if (!$c->user_exists) { > > $c->response->redirect($c->uri_for('login')); > # Return 0 to cancel 'post-auto' processing and prevent use > of application > return 0; > } > > > > Thanks for the help! > > > Paul Cory > WCPSS Webmaster > [email protected: p...@wcpss.net] > > >
Please also send your applications configuration so we can see your auth store. I do just have to ask though... why such ancient software? Apache 1 and MP1? Ouch. Off the top of my head, you are running out of space on your cache dir (how big is your tmp dir?). If you change your Session::Store or setup for a larger cache it'd probably alleviate the problem. -J
|
|
|
| 5) jshirley [Catalyst] Success stories please |
|
|
| Andy apparently just wanted to start a flamewar. This "article" is idiotic, the reasons more so.... |
|
|
|
|
|
|
|
On Sun, Oct 5, 2008 at 2:04 PM, Matt S Trout <dbix-class@trout.me.uk> wrote: > http://perlbuzz.com/2008/10/whats-the-state-of-perl-web-frameworks.html > > Shout out your support please, let's show the wider world that we're -the- > real MVC option right now. And be honest - I don't think anybody thinks the > docs are perfect or the learning curve's as shallow as it could be, but that > doesn't mean Catalyst isn't still awesome. >
Andy apparently just wanted to start a flamewar. This "article" is idiotic, the reasons more so. I'm disappointed in perlbuzz in general as it now holds the same amount of respect as getting my news from The National Inquirer. I'd encourage people to rather blog about finding the article to be in poor taste, then post their success stories. Commenting here or on that blog entry is going to be buried.
|
|
|
|
 | |