| 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.
|
|
|
| 6) jshirley [Catalyst] Model--best practice help |
|
|
| Without seeing a tremendous amount of your code it is hard to answer, but it sounds like you are... |
|
|
|
|
|
|
|
On Sun, Oct 5, 2008 at 10:03 AM, Dr. Jennifer Nussbaum <bg271828@yahoo.com> wrote: > Im going through my code, and trying to really think about how i can make it work well. Its a mess, i am realising, and i need advice on the best way > to clean it up. > > Its clear that there are things in my Model that should be in a Controller; that i dont need help with. > > My problem is that i have two different Models, and dont know how they should be combined. > > In particular, im using DBIC, so i have a setup where i have MyApp::Schema::Main, which only looks like: > > package MyApp::Schema::Main; > use base qw/DBIx::Class::Schema/; > > __PACKAGE__->load_classes(qw/Book Author/); > > 1; > > (the config stuff is in a separate config file:) > > <Model::MyAppDB> > schema_class MyApp::Schema::Main > connect_info ####### > </Model::MyAppDB> > > Then i'll have MyApp::Schema::Main::Book of whatever that looks like > > package MyApp::Schema::Main::Book; > > use base qw/DBIx::Class/; > > __PACKAGE__->load_components(qw/PK::Auto Core/); > (etc., other DBIC stuff) > > The problem is i also have a MyApp::Model::Book, and ive usually put non-DBIC things in there, like if i have a "get_results" method thats > specific to my Cat app and not appropriate for the schema, ill put it there. That starts like > > package MyApp::Model::Book; > use strict; > use warnings; > use base 'Catalyst::Model'; > > So ive got these two model classes, one i call with $c->model('MyAppDB::Book') and the other with $c->model('Book'). The problem > is, i have some things that are Cat specific and i dont want them in my schema class (becaues i use this in non-Cat apps), but i dont want to > have to have two separate models that i call by different names at > different times. > > Whats the way im supposed to be setting these up? > > Thanks! > > Jen > > >
Without seeing a tremendous amount of your code it is hard to answer, but it sounds like you are either at a point where it would be advantageous to learn Moose, or start doing some multiple inheritance hacks to get things working.
The simple approach, which is much less "great" than using Moose, is to put your App specific (the Catalyst specific, as you phrased it) methods in a class, and then in your model class:
package MyApp::Model::Everything;
use base qw/Catalyst::Model::DBIC::Schema MyApp::Model::Book/;
__PACKAGE__->config( ... );
1;
Then you can do $c->model('Everything')->foo_method( ... ); (foo_method defined in Model::Book), and still have $c->model('Everything::SchemaClass')->search(...);
In foo_method, $self will be Catalyst::Model::DBIC::Schema, so you can do $self->schema->resultset('SchemaClass')->search(...); etc.
But really... I'd just learn Moose, it'll make things easier and cleaner in the long run.
-J
|
|
|
| 7) jshirley [Catalyst] FASTCGI - configuring timeout |
|
|
| Something tells me you didn't use Google:... |
|
|
|
|
|
|
|
On Thu, Oct 2, 2008 at 7:03 AM, Dermot <paikkos@googlemail.com> wrote: > Hi, > > I am stretching the boundaries of the topic here I know but I thought > someone might know this off the top of their head. I am getting > timeout's. I am 99% sure this is because the Cat App is copying a > 500MB file on it filesystem. > > FastCGI: comm with server "/var/www/MyApp/script/myapp_fastcgi.pl" > aborted: idle timeout (30 sec) > FastCGI: incomplete headers (0 bytes) received from server > "/var/www/MyApp/script/myapp_fastcgi.pl" > > > I can't find any way to configure fastcgi.pl to increase the timeout > via the _fastcgi.pl and changes to the httpd.conf seem to make no > difference (at least the error always report a 30sec timeout). > > Can anyone offer any suggestions please? > Dp.
Something tells me you didn't use Google: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer-J
|
|
|
| 8) jshirley [Catalyst] Passing UTF-8 arg in URL to DBIC search |
|
|
| I haven't dug into the Catalyst source to see of any handling for the arguments, but just for... |
|
|
|
|
|
|
|
On Sat, Sep 27, 2008 at 6:51 AM, Hugh Hunter <hhunter@gmail.com> wrote: > Hello all, > > I've been struggling with this for some time and know there must be an > answer out there. > > I'm using URL arguments to pass parameters to my controller. It's a site > about names, so take the url http://domain.com/name/Jes?s (note the accented > u). The Name.pm controller has an :Args(1) decorator so Jes?s is stored in > $name and then passed to my DBIC model in a ->search({name => $name}) call. > This doesn't manage to find the row that exists in mysql. When I dump > $name I get: > > 'name' => 'Jes\xc3\xbas' > > which I think I understand as being perl's internal escaping of utf-8 > characters. > > I've done everything recommended on > http://dev.catalystframework.org/wiki/gettingstarted/tutorialsandhowtos/using_unicode and > the name column in my mysql database uses the utf-8 charset. > > Where am I going wrong? > > Best regards, > > --Hugh
I haven't dug into the Catalyst source to see of any handling for the arguments, but just for testing you may want to try doing a utf8::decode($name) and see if that does the trick for you. (Wild guessing on my part, sorry) -J
|
|
|
| 9) jshirley [Catalyst] tips for troubleshooting/QAing Unicode (was Re: Passing UTF-8 arg in URL to DBIC search) |
|
|
| Hey Darren, great post! Can you post it on the wiki, perhaps at:... |
|
|
|
|
|
|
|
On Sat, Sep 27, 2008 at 3:39 PM, Darren Duncan <darren@darrenduncan.net> wrote: > Maybe you're already aware of this, but I've found from experience that > troubleshooting encoding/Unicode problems in a web/db app can be difficult, > especially with multiple conversions at different stages, but I've come up > with a short generic algorithm to help test/ensure that things are working > and where things need fixing. Note that these details assuming we're using > Perl 5.8+. > [ snip ]
Hey Darren, great post! Can you post it on the wiki, perhaps at: http://dev.catalystframework.org/wiki/faq link to "Unicode Troubleshooting" in the Unicode section there? It would be much appreciated. Thanks, -J
|
|
|
| 10) jshirley [Catalyst] Conditional GET with Catalyst::Controller::REST |
|
|
| What is the full output from something like GET -e -d -s {path}? I added a simple test to... |
|
|
|
|
|
|
|
On Thu, Sep 25, 2008 at 4:02 AM, Gavin Carr <gavin@openfusion.com.au> wrote: > I'm seeing a weird problem trying to get conditional GETs > working under Catalyst::Controller::REST (0.66). > > Short version is that everything works beautifully when > doing a HEAD, and my 304 is happily returned, but the same > code on a GET causes a 500, with nothing helpful logged. > > Code snippet is: > > sub index_GET { > my ($self, $c) = @_; > > my $sset = $c->stash->{sset} or return; > > my $ifmod_ts = $c->request->headers->if_modified_since; > my $sset_ts = $sset->modify_ts->epoch; > if ($ifmod_ts && $ifmod_ts == $sset_ts) { > $c->log->debug("not modified: ifmod_ts == sset_ts ($sset_ts)"); > $c->response->status(304); > $c->log->debug('Status: ' . $c->response->status); > return 1; > } > > # Rest of GET > # ... > } > > In the logs I see the two debug lines, and then nothing else: > > [debug] not modified: ifmod_ts == sset_ts (1222241031) > [debug] Status: 304 > > Any cluesticks as to what might be going on here? If I change the > status to almost anything else but 304 it all works fine. And it > doesn't seem to be the serialisation code either, as that explicitly > checks for 3xx status codes and exits. > > Baffled. Anyone have conditional GETs working with C::C::REST? > > Cheers, > Gavin > >
What is the full output from something like GET -e -d -s {path}? I added a simple test to t/catalyst-action-rest.t that returns a 304 status and it passed as expected. I'm guessing something somewhere else is breaking things. Do you have a begin/end and can you post a simplified controller exhibiting the behaviors and a complete request cycle? Patch below, if you want to test: === t/catalyst-action-rest.t ================================================================== --- t/catalyst-action-rest.t (revision 5986) +++ t/catalyst-action-rest.t (local) @@ -81,6 +81,15 @@ $c->forward('ok'); } +sub not_modified : Local : ActionClass('REST') { } + +sub not_modified_GET { + my ( $self, $c ) = @_; + $c->res->status(304); + return 1; +} + + sub ok : Private { my ( $self, $c ) = @_; @@ -135,6 +144,9 @@ is( $options_res->header('allow'), "GET", "OPTIONS request allow header properly set." ); +my $modified_res = request( $t->get( url => '/not_modified' ) ); +is( $modified_res->code, 304, "Not Modified request handler succeeded" ); + my $ni_res = request( $t->delete( url => '/not_implemented' ) ); is( $ni_res->code, 200, "Custom not_implemented handler succeeded" ); is(
|
|
|
| 11) jshirley [Catalyst] How to send raw HTTP response |
|
|
| You can use IO::Scalar, then pass that to $c->res->body... that's what I do for XLS reports and it... |
|
|
|
|
|
|
|
On Thu, Sep 25, 2008 at 11:35 AM, Christian Lackas <christian@lackas.net> wrote: > Hi Everybody, > > is it possible for a controller method to directly produce the raw HTTP response? > My application generates a (potentially large)) ZIP file on the fly, > which I don't want to store (on disk or in memory) but rather send it > directly to the client while producing it. > > In a CGI script I use Archive::Zip such as > > print CGI::header(...); > $ZIP->writeToFileHandle(*STDOUT); > for my $f | | | |