[Bps-public-commit] dbix-searchbuilder branch, query-hinting, updated. 1.66-2-gf3e6fff
Shawn Moore
shawn at bestpractical.com
Thu Mar 10 13:20:27 EST 2016
The branch, query-hinting has been updated
via f3e6fff5a3cfc4807f3b2216b7298fa9e3a69662 (commit)
from cb80dfe54fbd95d2f441439443239244d0138cc8 (commit)
Summary of changes:
lib/DBIx/SearchBuilder.pm | 2 +-
lib/DBIx/SearchBuilder/Handle.pm | 11 +++++++++--
lib/DBIx/SearchBuilder/Handle/SQLite.pm | 1 +
3 files changed, 11 insertions(+), 3 deletions(-)
- Log -----------------------------------------------------------------
commit f3e6fff5a3cfc4807f3b2216b7298fa9e3a69662
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Mar 10 18:19:49 2016 +0000
Add query hint to DistinctQuery and DistinctCount
diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index f755e14..3a9abf2 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -482,7 +482,7 @@ sub BuildSelectCountQuery {
# DISTINCT query only required for multi-table selects
if ($self->_isJoined) {
- $QueryString = $self->_Handle->DistinctCount(\$QueryString);
+ $QueryString = $self->_Handle->DistinctCount(\$QueryString, $self);
} else {
my $QueryHint = $self->QueryHint;
$QueryHint = $QueryHint ? " /* $QueryHint */ " : " ";
diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index 6ed2cc8..f4e3d6c 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -1398,8 +1398,11 @@ sub DistinctQuery {
my $statementref = shift;
my $sb = shift;
+ my $QueryHint = $sb->QueryHint;
+ $QueryHint = $QueryHint ? " /* $QueryHint */ " : " ";
+
# Prepend select query for DBs which allow DISTINCT on all column types.
- $$statementref = "SELECT DISTINCT main.* FROM $$statementref";
+ $$statementref = "SELECT" . $QueryHint . "DISTINCT main.* FROM $$statementref";
$$statementref .= $sb->_GroupClause;
$$statementref .= $sb->_OrderClause;
}
@@ -1417,9 +1420,13 @@ takes an incomplete SQL SELECT statement and massages it to return a DISTINCT re
sub DistinctCount {
my $self = shift;
my $statementref = shift;
+ my $sb = shift;
+
+ my $QueryHint = $sb->QueryHint;
+ $QueryHint = $QueryHint ? " /* $QueryHint */ " : " ";
# Prepend select query for DBs which allow DISTINCT on all column types.
- $$statementref = "SELECT COUNT(DISTINCT main.id) FROM $$statementref";
+ $$statementref = "SELECT" . $QueryHint . "COUNT(DISTINCT main.id) FROM $$statementref";
}
diff --git a/lib/DBIx/SearchBuilder/Handle/SQLite.pm b/lib/DBIx/SearchBuilder/Handle/SQLite.pm
index a9376fd..c172974 100644
--- a/lib/DBIx/SearchBuilder/Handle/SQLite.pm
+++ b/lib/DBIx/SearchBuilder/Handle/SQLite.pm
@@ -128,6 +128,7 @@ takes an incomplete SQL SELECT statement and massages it to return a DISTINCT re
sub DistinctCount {
my $self = shift;
my $statementref = shift;
+ my $sb = shift;
$$statementref = "SELECT count(*) FROM (SELECT DISTINCT main.id FROM $$statementref )";
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list