[Bps-public-commit] dbix-searchbuilder branch, master, updated. 39129fa966516b891b7bba660365f75777e97c47
Ruslan Zakirov
ruz at bestpractical.com
Mon Mar 22 15:41:18 EDT 2010
The branch, master has been updated
via 39129fa966516b891b7bba660365f75777e97c47 (commit)
via 7a025715e85f9cc32e2c3da1246339f54658fe6c (commit)
via eb88a87b204e6ea85d4c33fa0162997762b76e69 (commit)
from d77dd287821520704bf5a99b2b60b8879e81eb8d (commit)
Summary of changes:
SearchBuilder.pm | 195 +++++++++++++++++++++--------------------------
SearchBuilder/Record.pm | 2 +-
t/01records.t | 2 +-
3 files changed, 88 insertions(+), 111 deletions(-)
- Log -----------------------------------------------------------------
commit eb88a87b204e6ea85d4c33fa0162997762b76e69
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Mar 22 19:57:40 2010 +0300
make debugging problems easier by passing errors back
https://rt.cpan.org/Ticket/Display.html?id=55203
Thanks to Dan Drown
diff --git a/SearchBuilder/Record.pm b/SearchBuilder/Record.pm
index 447780d..1b7254b 100755
--- a/SearchBuilder/Record.pm
+++ b/SearchBuilder/Record.pm
@@ -1208,7 +1208,7 @@ sub _LoadFromSQL {
#TODO this only gets the first row. we should check if there are more.
- return ( 0, "Couldn't execute query" ) unless $sth;
+ return ( 0, "Couldn't execute query: ".$self->_Handle->dbh->errstr ) unless $sth;
$self->{'values'} = $sth->fetchrow_hashref;
$self->{'fetched'} = {};
diff --git a/t/01records.t b/t/01records.t
index 507e8e0..1730645 100644
--- a/t/01records.t
+++ b/t/01records.t
@@ -144,7 +144,7 @@ SKIP: {
($val, $msg) = $newrec->_LoadFromSQL('SELECT ...');
}
is($val, 0, "didn't find object");
- is($msg, "Couldn't execute query", "reason is bad SQL");
+ like($msg, qr/^Couldn't execute query/, "reason is bad SQL");
# test Load* methods
$newrec = TestApp::Address->new($handle);
commit 7a025715e85f9cc32e2c3da1246339f54658fe6c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Mar 22 21:02:35 2010 +0300
update deprecated methods
* move to the bottom
* update docs
* make some just do nothing
diff --git a/SearchBuilder.pm b/SearchBuilder.pm
index 2714bd8..56aa98d 100755
--- a/SearchBuilder.pm
+++ b/SearchBuilder.pm
@@ -128,7 +128,6 @@ sub CleanSlate {
my $self = shift;
$self->RedoSearch();
$self->{'itemscount'} = 0;
- $self->{'where_clause'} = "";
$self->{'limit_clause'} = "";
$self->{'order'} = "";
$self->{'alias_count'} = 0;
@@ -816,40 +815,6 @@ sub Limit {
-=head2 ShowRestrictions
-
-Returns the current object's proposed WHERE clause.
-
-Deprecated.
-
-=cut
-
-sub ShowRestrictions {
- my $self = shift;
- $self->_CompileGenericRestrictions();
- $self->_CompileSubClauses();
- return ( $self->{'where_clause'} );
-
-}
-
-
-
-=head2 ImportRestrictions
-
-Replaces the current object's WHERE clause with the string passed as its argument.
-
-Deprecated
-
-=cut
-
-#import a restrictions clause
-sub ImportRestrictions {
- my $self = shift;
- $self->{'where_clause'} = shift;
-}
-
-
-
sub _GenericRestriction {
my $self = shift;
my %args = ( TABLE => $self->Table,
@@ -1002,7 +967,6 @@ sub _WhereClause {
}
-
#Compile the restrictions to a WHERE Clause
sub _CompileGenericRestrictions {
@@ -1027,9 +991,6 @@ sub _CompileGenericRestrictions {
}
-
-
-
=head2 OrderBy PARAMHASH
Orders the returned results by ALIAS.FIELD ORDER.
@@ -1111,20 +1072,6 @@ sub _OrderClause {
return $clause;
}
-
-
-
-
-=head2 GroupBy (DEPRECATED)
-
-Alias for the GroupByCols method.
-
-=cut
-
-sub GroupBy { (shift)->GroupByCols( @_ ) }
-
-
-
=head2 GroupByCols ARRAY_OF_HASHES
Each hash contains the keys ALIAS and FIELD. ALIAS defaults to 'main' if ignored.
@@ -1139,7 +1086,6 @@ sub GroupByCols {
$self->RedoSearch();
}
-
=head2 _GroupClause
Private function to return the "GROUP BY" clause for this query.
@@ -1180,10 +1126,6 @@ sub _GroupClause {
}
}
-
-
-
-
=head2 NewAlias
Takes the name of a table.
@@ -1268,9 +1210,6 @@ sub Join {
}
-
-
-
sub NextPage {
my $self = shift;
$self->FirstRow( $self->FirstRow + $self->RowsPerPage );
@@ -1283,9 +1222,6 @@ sub FirstPage {
}
-
-
-
sub PrevPage {
my $self = shift;
if ( ( $self->FirstRow - $self->RowsPerPage ) > 1 ) {
@@ -1297,7 +1233,6 @@ sub PrevPage {
}
-
sub GotoPage {
my $self = shift;
my $page = shift;
@@ -1355,9 +1290,6 @@ sub FirstRow {
}
-
-
-
=head2 _ItemsCounter
Returns the current position in the record set.
@@ -1370,15 +1302,12 @@ sub _ItemsCounter {
}
-
=head2 Count
Returns the number of records in the set.
=cut
-
-
sub Count {
my $self = shift;
@@ -1409,7 +1338,7 @@ sub Count {
=head2 CountAll
Returns the total number of potential records in the set, ignoring any
-LimitClause.
+L</RowsPerPage> settings.
=cut
@@ -1464,8 +1393,6 @@ sub CountAll {
}
-
-
=head2 IsLast
Returns true if the current row is the last record in the set.
@@ -1486,10 +1413,6 @@ sub IsLast {
}
-
-sub DEBUG { warn "DEBUG is deprecated" }
-
-
=head2 Column { FIELD => undef }
Specify that we want to load the column FIELD.
@@ -1557,7 +1480,6 @@ sub Columns {
}
-
=head2 Fields TABLE
Return a list of fields in TABLE, lowercased.
@@ -1571,8 +1493,6 @@ sub Fields {
}
-
-
=head2 HasField { TABLE => undef, FIELD => undef }
Returns true if TABLE has field FIELD.
@@ -1592,7 +1512,6 @@ sub HasField {
}
-
=head2 Table [TABLE]
If called with an argument, sets this collection's table.
@@ -1601,17 +1520,52 @@ Always returns this collection's table.
=cut
-sub SetTable {
- my $self = shift;
- return $self->Table(@_);
-}
-
sub Table {
my $self = shift;
$self->{table} = shift if (@_);
return $self->{table};
}
+=head1 DEPRECATED METHODS
+
+=head2 GroupBy
+
+DEPRECATED. Alias for the L</GroupByCols> method.
+
+=cut
+
+sub GroupBy { (shift)->GroupByCols( @_ ) }
+
+=head2 SetTable
+
+DEPRECATED. Alias for the L</Table> method.
+
+=cut
+
+sub SetTable {
+ my $self = shift;
+ return $self->Table(@_);
+}
+
+=head2 ShowRestrictions
+
+DEPRECATED AND DOES NOTHING.
+
+=cut
+
+sub ShowRestrictions { }
+
+=head2 ImportRestrictions
+
+DEPRECATED AND DOES NOTHING.
+
+=cut
+
+sub ImportRestrictions { }
+
+# not even documented
+sub DEBUG { warn "DEBUG is deprecated" }
+
if( eval { require capitalization } ) {
capitalization->unimport( __PACKAGE__ );
commit 39129fa966516b891b7bba660365f75777e97c47
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Mar 22 22:40:57 2010 +0300
shuffle paging functions and document them
diff --git a/SearchBuilder.pm b/SearchBuilder.pm
index 56aa98d..d13a796 100755
--- a/SearchBuilder.pm
+++ b/SearchBuilder.pm
@@ -1209,18 +1209,47 @@ sub Join {
}
+=head2 Pages: size and changing
-sub NextPage {
+Use L</RowsPerPage> to set size of pages. L</NextPage>,
+L</PrevPage>, L</FirstPage> or L</GotoPage> to change
+pages. L</FirstRow> to do tricky stuff.
+
+=head3 RowsPerPage
+
+Get or set the number of rows returned by the database.
+
+Takes an optional integer which restricts the # of rows returned
+in a result. Zero or undef argument flush back to "return all
+records matching current conditions".
+
+Returns the current page size.
+
+=cut
+
+sub RowsPerPage {
my $self = shift;
- $self->FirstRow( $self->FirstRow + $self->RowsPerPage );
+ $self->{'show_rows'} = shift if (@_);
+
+ return ( $self->{'show_rows'} );
}
+=head3 NextPage
-sub FirstPage {
+Turns one page forward.
+
+=cut
+
+sub NextPage {
my $self = shift;
- $self->FirstRow(1);
+ $self->FirstRow( $self->FirstRow + $self->RowsPerPage );
}
+=head3 PrevPage
+
+Turns one page backwards.
+
+=cut
sub PrevPage {
my $self = shift;
@@ -1232,49 +1261,43 @@ sub PrevPage {
}
}
+=head3 FirstPage
-sub GotoPage {
- my $self = shift;
- my $page = shift;
-
- if ( $self->RowsPerPage ) {
- $self->FirstRow( 1 + ( $self->RowsPerPage * $page ) );
- } else {
- $self->FirstRow(1);
- }
-}
-
+Jumps to the first page.
+=cut
-=head2 RowsPerPage
+sub FirstPage {
+ my $self = shift;
+ $self->FirstRow(1);
+}
-Limits the number of rows returned by the database. Optionally, takes
-an integer which restricts the # of rows returned in a result. Zero
-or undef argument flush back to "return all records matching conditions".
+=head3 GotoPage
-Returns the number of rows the database should display.
+Takes an integer number and jumps to that page or first page if
+number ommitted. Numbering starts from zero.
=cut
-sub RowsPerPage {
+sub GotoPage {
my $self = shift;
- $self->{'show_rows'} = shift if (@_);
+ my $page = shift || 0;
- return ( $self->{'show_rows'} );
+ $self->FirstRow( 1 + $self->RowsPerPage * $page );
}
-
-
-=head2 FirstRow
+=head3 FirstRow
Get or set the first row of the result set the database should return.
Takes an optional single integer argrument. Returns the currently set integer
-first row that the database should return.
+minus one (this is historical issue).
+Usually you don't need this method. Use L</RowsPerPage>, L</NextPage> and other
+methods to walk pages. It only may be helpful to get 10 records starting from
+5th.
=cut
-# returns the first row
sub FirstRow {
my $self = shift;
if (@_) {
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list