[Rt-commit] [svn] r754 - in DBIx-SearchBuilder/trunk: .
SearchBuilder SearchBuilder/Handle
jesse at pallas.eruditorum.org
jesse at pallas.eruditorum.org
Tue Apr 27 02:45:49 EDT 2004
Author: jesse
Date: Tue Apr 27 02:45:48 2004
New Revision: 754
Modified:
DBIx-SearchBuilder/trunk/SearchBuilder.pm
DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm
DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm
Log:
Updated SearchBuilder support for SQLite's COUNT (DISTINCT)
Modified: DBIx-SearchBuilder/trunk/SearchBuilder.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder.pm (original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder.pm Tue Apr 27 02:45:48 2004
@@ -195,20 +195,20 @@
#TODO refactor DoSearch and DoCount such that we only have
# one place where we build most of the querystring
-
- # DISTINCT query only required for multi-table selects
- if ($self->_isJoined) {
- $QueryString = "SELECT count(DISTINCT main.id) FROM ";
- } else {
- $QueryString = "SELECT count(main.id) FROM ";
- }
-
$QueryString .= $self->_BuildJoins . " ";
$QueryString .= $self->_WhereClause . " "
if ( $self->_isLimited > 0 );
+
+ # DISTINCT query only required for multi-table selects
+ if ($self->_isJoined) {
+ $QueryString = $self->_Handle->DistinctCount(\$QueryString);
+ } else {
+ $QueryString = "SELECT count(main.id) FROM " . $QueryString;
+ }
+
print STDERR "DBIx::SearchBuilder->DoSearch Query: $QueryString\n"
if ( $self->DEBUG );
Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm (original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm Tue Apr 27 02:45:48 2004
@@ -783,6 +783,25 @@
# }}}
+# {{{ DistinctCount
+
+=head2 DistinctCount STATEMENTREF
+
+takes an incomplete SQL SELECT statement and massages it to return a DISTINCT result set.
+
+
+=cut
+
+sub DistinctCount {
+ my $self = shift;
+ my $statementref = shift;
+
+ # Prepend select query for DBs which allow DISTINCT on all column types.
+ $$statementref = "SELECT COUNT(DISTINCT main.id) FROM $$statementref";
+
+}
+
+# }}}
=head2 Log MESSAGE
Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm (original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm Tue Apr 27 02:45:48 2004
@@ -76,4 +76,25 @@
# }}}
+=head2 DistinctCount STATEMENTREF
+
+takes an incomplete SQL SELECT statement and massages it to return a DISTINCT result count
+
+
+=cut
+
+sub DistinctCount {
+ my $self = shift;
+ my $statementref = shift;
+
+ # Wrapper select query in a subselect as Oracle doesn't allow
+ # DISTINCT against CLOB/BLOB column types.
+ $$statementref = "SELECT count(*) FROM (SELECT DISTINCT main.id FROM $$statementref )";
+
+}
+
+# }}}
+
+
+
1;
More information about the Rt-commit
mailing list