Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Ken Williams <ken@ma...> - 2003-05-01 18:17:02
|
Hi, Is there a quick way to count the number of rows returned by a RowCursor? Currently I'm doing something like this: # assoc_links() follows a linking table my @rows = $object->assoc_links->all_rows; my $count = @rows; Two things aren't ideal here - first, all_rows() has to go through the work of creating objects for all the rows it returns, when all I need is a count. Second, I have to store those objects in an array, which I throw away (actually, '$count = $object->assoc_links->all_rows;' looks like it would work fine, but isn't documented). Any chance of adding a method like $row_cursor->count_rows(), or something, that counts rows which have *not* been fetched yet? -Ken |
From: Dave Rolsky <autarch@ur...> - 2003-05-01 18:25:19
|
On Thu, 1 May 2003, Ken Williams wrote: > Is there a quick way to count the number of rows returned by a > RowCursor? Currently I'm doing something like this: > > # assoc_links() follows a linking table > my @rows = $object->assoc_links->all_rows; > my $count = @rows; > > Two things aren't ideal here - first, all_rows() has to go through the > work of creating objects for all the rows it returns, when all I need > is a count. Second, I have to store those objects in an array, which I > throw away (actually, '$count = $object->assoc_links->all_rows;' looks > like it would work fine, but isn't documented). > > Any chance of adding a method like $row_cursor->count_rows(), or > something, that counts rows which have *not* been fetched yet? Sure, that could be done. It'd still have to fetch all the data from the database, though. -dave /*======================= House Absolute Consulting http://www.houseabsolute.com =======================*/ |
From: Fen Labalme <fen@co...> - 2003-05-02 03:00:09
|
Is post_insert known to work? Does it get the new, inserted object? I ask as after a Member table gets updated a post_insert gets called to update an Action table reflecting a new member. But $self->member_id_c inserts a zero (0) into the Action table, despite the fact that the new Member table row just inserted a row with member_id set to (say) 7. Or maybe I'm doing something wrong - I'm still getting used to Alzabo. Code is below. Thanks, Fen package CPV::Data::Table::Member; sub post_insert { my $self = shift; my $row = $Schema->ActionList_t->one_row ( where => [ $Schema->ActionList_t->action_c, '=', 'join' ] ); $Schema->Action_t->insert ( values => { member_id => $self->member_id_c, actionList_id => $row->actionList_id, points => $row->points } ); } -- Fen Labalme, Director of Technology, Coalition for Progressive Values Never doubt that a small group of thoughtful, committed citizens can change the world. Indeed, it's the only thing that ever has. -- Margaret Mead |
From: Dave Rolsky <autarch@ur...> - 2003-05-03 05:02:43
|
On Thu, 1 May 2003, Fen Labalme wrote: > Is post_insert known to work? Does it get the new, inserted object? Yes, but not as it's sole argument. > sub post_insert > { > my $self = shift; > > my $row = $Schema->ActionList_t->one_row ( > where => [ $Schema->ActionList_t->action_c, '=', 'join' ] ); > > $Schema->Action_t->insert ( > values => { member_id => $self->member_id_c, > actionList_id => $row->actionList_id, > points => $row->points } ); > } The problem is that a post_insert hook needs to work like this: sub post_insert { my $table = shift; my %p = @_; my $row = delete $p{row}; my %insert_values = %p; ... } This interface is a little off though, now that I like at it closely. Sticking the row in the same hash of values as was inserted is bad, just in case someone names a column "row". -dave /*======================= House Absolute Consulting http://www.houseabsolute.com =======================*/ |
From: Dave Rolsky <autarch@ur...> - 2003-05-03 04:20:30
|
On Fri, 2 May 2003, Dave Rolsky wrote: > The problem is that a post_insert hook needs to work like this: > > sub post_insert > { > my $table = shift; > my %p = @_; > > my $row = delete $p{row}; > my %insert_values = %p; > > ... > } Ooops, that should be sub post_insert { my $table = shift; my $p = shift; my $row = delete $p->{row}; my %insert_values = %$p; ... } -dave /*======================= House Absolute Consulting http://www.houseabsolute.com =======================*/ |
From: Fen Labalme <fen@co...> - 2003-05-02 05:55:30
|
When I use select in the code below, the first line returns undef (despite the fact that matching where clause lines exist with points values set) and the second returns the correct number. But if I follow the documentation http://www.alzabo.org/docs/Alzabo.mhtml#Using%20SQL%20functions and change the select to function, I get this error: The following parameter was passed in the call to Alzabo::Runtime::Table::_select_sql but was not listed in the validation options: function /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 9 /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 339 /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 339 /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 310 /x/web/cpv/demo/activist_points.mas: 29 ... What does this mean? I'm guessing my syntax is incorrect - can someone give me a pointer as to how to fix? Thanks, Fen --- $points = $Schema->Action_t->function ( select => SUM( $Schema->Action_t->points_c ), where => [ $Schema->Action_t->member_id_c, '=', $Member->member_id ] ) || 0; $total = $Schema->Action_t->function( select => SUM( $Schema->Action_t->points_c )); |
From: Dave Rolsky <autarch@ur...> - 2003-05-02 15:59:12
|
On Fri, 1 May 2003, Fen Labalme wrote: > The following parameter was passed in the call to Alzabo::Runtime::Table::_select_sql but was not listed in the validation options: function > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 9 > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 339 > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 339 > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 310 > /x/web/cpv/demo/activist_points.mas: 29 > ... > > What does this mean? I'm guessing my syntax is incorrect - can someone give > me a pointer as to how to fix? It means you passed a parameter named "function" to some Alzabo method. > $points = $Schema->Action_t->function ( > select => SUM( $Schema->Action_t->points_c ), > where => [ $Schema->Action_t->member_id_c, '=', $Member->member_id ] > ) || 0; > > $total = $Schema->Action_t->function( > select => SUM( $Schema->Action_t->points_c )); Both of these should work, but are you _sure_ this is the code you're executing? And what version of Alzabo are you using? -dave /*======================= House Absolute Consulting http://www.houseabsolute.com =======================*/ |
From: Fen Labalme <fen@co...> - 2003-05-02 17:57:15
|
Dave Rolsky <autarch@...> writes: > On Fri, 1 May 2003, Fen Labalme wrote: > > > The following parameter was passed in the call to Alzabo::Runtime::Table::_select_sql but was not listed in the validation options: function > > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 9 > > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 339 > > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 339 > > /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm: 310 > > /x/web/cpv/demo/activist_points.mas: 29 > > ... > > > > What does this mean? I'm guessing my syntax is incorrect - can someone give > > me a pointer as to how to fix? > > It means you passed a parameter named "function" to some Alzabo method. > > > $points = $Schema->Action_t->function ( > > select => SUM( $Schema->Action_t->points_c ), > > where => [ $Schema->Action_t->member_id_c, '=', $Member->member_id ] > > ); > > Both of these should work, but are you _sure_ this is the code you're > executing? Yes, but my note was confusing. $points is undef after the code above. But when I use 'function' instead of 'select' as in the snippet below, I get the error message referencing Alzabo/Runtime/Table.pm ############ from /x/web/cpv/demo/activist_points.mas $points = $Schema->Action_t->function ( ####### activist_points.mas, line 29 function => SUM( $Schema->Action_t->points_c ), where => [ $Schema->Action_t->member_id_c, '=', $Member->member_id ] ); ############ from /usr/local/share/perl/5.6.1/Alzabo/Runtime/Table.pm sub function { my $self = shift; my %p = @_; my $sql = $self->_select_sql(%p); ####### line 310 my $method = UNIVERSAL::isa( $p{select}, 'ARRAY' ) && @{ $p{select} } > 1 ? 'rows' : 'column'; $sql->debug(\*STDERR) if Alzabo::Debug::SQL; print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE; return $self->schema->driver->$method( sql => $sql->sql, bind => $sql->bind ); } sub _select_sql { my $self = shift; my %p = validate( @_, { select => { type => SCALAR | ARRAYREF | OBJECT }, where => { type => ARRAYREF | OBJECT, optional => 1 }, order_by => { type => ARRAYREF | HASHREF | OBJECT, optional => 1 }, group_by => { type => ARRAYREF | HASHREF | OBJECT, optional => 1 }, having => { type => ARRAYREF, optional => 1 }, limit => { type => SCALAR | ARRAYREF, optional => 1 }, } ); Not sure if I'm reading this corrctly, but there appears to be no validate option in _select_sql for function, which is what the error complains about. And the reason I'm trying to use 'function' is that's what the doc suggests: http://www.alzabo.org/docs/Alzabo.mhtml#Using%20SQL%20functions > And what version of Alzabo are you using? Alzabo 0.72, Perl 5.6.1, MySql 3.23.52, Debian Linux (testing) kernel 2.4.19 Thanks, Fen |
From: Fen Labalme <fen@co...> - 2003-05-02 18:06:03
|
Mea Culpa! My mistake! Please ignore previous message - I found the error in my table structure. Thanks again for your help and apologies for taking your time. (Though I *am* still confused by the documentation at http://www.alzabo.org/docs/Alzabo.mhtml#Using%20SQL%20functions that reads my $max = $table->function( function => MAX( $table->column('budget') ), where => [ $table->column('country'), '=', 'USA' ] ); Perhaps the second "function" ought to be a "select"?) I love Alzabo! Fen === Fen Labalme <fen@...> writes: ... <erroneously> |
From: Dave Rolsky <autarch@ur...> - 2003-05-02 21:32:22
|
On Fri, 2 May 2003, Fen Labalme wrote: > Yes, but my note was confusing. $points is undef after the code above. But > when I use 'function' instead of 'select' as in the snippet below, I get the > error message referencing Alzabo/Runtime/Table.pm > > ############ from /x/web/cpv/demo/activist_points.mas > $points = $Schema->Action_t->function ( ####### activist_points.mas, line 29 > function => SUM( $Schema->Action_t->points_c ), > where => [ $Schema->Action_t->member_id_c, '=', $Member->member_id ] > ); That's cause you're supposed to call the parameter "select" regardless of which method you call. > Not sure if I'm reading this corrctly, but there appears to be no validate > option in _select_sql for function, which is what the error complains about. > And the reason I'm trying to use 'function' is that's what the doc suggests: > http://www.alzabo.org/docs/Alzabo.mhtml#Using%20SQL%20functions That's cause the guy who wrote the docs wasn't paying enough attention ;) There is no "function" parameter. -dave /*======================= House Absolute Consulting http://www.houseabsolute.com =======================*/ |