[Bps-public-commit] dbix-searchbuilder branch, query-hinting, updated. 1.66-3-g4ad0bad

Shawn Moore shawn at bestpractical.com
Wed Jul 13 13:18:51 EDT 2016


The branch, query-hinting has been updated
       via  4ad0badd26a544022201365392cd4f51d221f128 (commit)
      from  f3e6fff5a3cfc4807f3b2216b7298fa9e3a69662 (commit)

Summary of changes:
 lib/DBIx/SearchBuilder.pm | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit 4ad0badd26a544022201365392cd4f51d221f128
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Jul 13 17:17:57 2016 +0000

    QueryHintFormatted and usage example

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 3a9abf2..1ba3efd 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -434,8 +434,7 @@ sub BuildSelectQuery {
     $QueryString .= $self->_WhereClause . " "
       if ( $self->_isLimited > 0 );
 
-    my $QueryHint = $self->QueryHint;
-    $QueryHint = $QueryHint ? " /* $QueryHint */ " : " ";
+    my $QueryHint = $self->QueryHintFormatted;
 
     # DISTINCT query only required for multi-table selects
     # when we have group by clause then the result set is distinct as
@@ -484,8 +483,7 @@ sub BuildSelectCountQuery {
     if ($self->_isJoined) {
         $QueryString = $self->_Handle->DistinctCount(\$QueryString, $self);
     } else {
-        my $QueryHint = $self->QueryHint;
-        $QueryHint = $QueryHint ? " /* $QueryHint */ " : " ";
+        my $QueryHint = $self->QueryHintFormatted;
 
         $QueryString = "SELECT" . $QueryHint . "count(main.id) FROM " . $QueryString;
     }
@@ -631,8 +629,7 @@ sub DistinctFieldValues {
     $query_string .= ' '. $self->_WhereClause
         if $self->_isLimited > 0;
 
-    my $query_hint = $self->QueryHint;
-    $query_hint = $query_hint ? " /* $query_hint */ " : " ";
+    my $query_hint = $self->QueryHintFormatted;
 
     my $column = 'main.'. $args{'Field'};
     $query_string = "SELECT" . $query_hint . "DISTINCT $column FROM $query_string";
@@ -1847,6 +1844,11 @@ If called with an argument, sets a query hint for this collection.
 
 Always returns the query hint.
 
+When the query hint is included in the SQL query, the C</* ... */> will be
+included for you. Here's an example query hint for Oracle:
+
+    $sb->QueryHint("+CURSOR_SHARING_EXACT");
+
 =cut
 
 sub QueryHint {
@@ -1855,6 +1857,18 @@ sub QueryHint {
     return $self->{query_hint};
 }
 
+=head2 QueryHintFormatted
+
+Returns the query hint formatted appropriately for inclusion in SQL queries.
+
+=cut
+
+sub QueryHintFormatted {
+    my $self = shift;
+    my $QueryHint = $self->QueryHint;
+    return $QueryHint ? " /* $QueryHint */ " : " ";
+}
+
 =head1 DEPRECATED METHODS
 
 =head2 GroupBy

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list