[Bps-public-commit] dbix-searchbuilder branch produce-correct-oracle-query-hints created. 1.78-3-g9748103

BPS Git Server git at git.bestpractical.com
Mon Nov 27 19:48:27 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "dbix-searchbuilder".

The branch, produce-correct-oracle-query-hints has been created
        at  97481033362e3bb368c090820abfdf93494ef767 (commit)

- Log -----------------------------------------------------------------
commit 97481033362e3bb368c090820abfdf93494ef767
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Mon Nov 27 14:47:54 2023 -0500

    Add some basic testing for query hints

diff --git a/t/30query_hints.t b/t/30query_hints.t
new file mode 100644
index 0000000..89a3b95
--- /dev/null
+++ b/t/30query_hints.t
@@ -0,0 +1,162 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More;
+BEGIN { require "./t/utils.pl" }
+our (@AvailableDrivers);
+
+use constant TESTS_PER_DRIVER => 4;
+
+my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
+plan tests => $total;
+
+foreach my $d (@AvailableDrivers) {
+    SKIP: {
+        unless ( has_schema( 'TestApp', $d ) ) {
+            skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+        }
+        unless ( should_test($d) ) {
+            skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+        }
+
+        my $handle = get_handle($d);
+        connect_handle($handle);
+        isa_ok( $handle->dbh, 'DBI::db' );
+
+        my $ret = init_schema( 'TestApp', $handle );
+        isa_ok( $ret, 'DBI::st',
+            "Inserted the schema. got a statement handle back" );
+
+        my $rec = TestApp::Users->new($handle);
+
+        $rec->UnLimit;
+        my $hintless_sql = $rec->BuildSelectQuery( PreferBind => 0 );
+        unlike( $hintless_sql, qr/\/\*/, "Query hint markers aren't present when QueryHint() isn't called" );
+
+        $rec->UnLimit;
+        $rec->QueryHint( '+FooBar' );
+        my $hinted_sql = $rec->BuildSelectQuery( PreferBind => 0 );
+        like( $hinted_sql, qr|/\*\+FooBar \*/|, "..but are when QueryHint() IS called" );
+
+        cleanup_schema( 'TestApp', $handle );
+    }
+}
+
+1;
+
+package TestApp;
+
+sub schema_mysql {[
+	"DROP TABLE IF EXISTS Users",
+<<EOF
+CREATE TABLE Users (
+        id integer AUTO_INCREMENT,
+        Login varchar(18) NOT NULL,
+        Name varchar(36),
+	Phone varchar(18),
+  	PRIMARY KEY (id))
+EOF
+]}
+sub cleanup_schema_mysql { [
+    "DROP TABLE Users",
+] }
+
+sub schema_pg {
+<<EOF;
+CREATE TEMPORARY TABLE Users (
+        id serial PRIMARY KEY,
+        Login varchar(18) NOT NULL,
+        Name varchar(36),
+        Phone varchar(18)
+)
+EOF
+
+}
+
+sub schema_sqlite {
+
+<<EOF;
+CREATE TABLE Users (
+	id integer primary key,
+	Login varchar(18) NOT NULL,
+	Name varchar(36),
+	Phone varchar(18))
+EOF
+
+}
+
+sub schema_oracle { [
+    "CREATE SEQUENCE Users_seq",
+    "CREATE TABLE Users (
+        id integer CONSTRAINT Users_Key PRIMARY KEY,
+        Login varchar(18) NOT NULL,
+        Name varchar(36),
+        Phone varchar(18)
+    )",
+] }
+
+sub cleanup_schema_oracle { [
+    "DROP SEQUENCE Users_seq",
+    "DROP TABLE Users",
+] }
+
+
+1;
+
+package TestApp::User;
+
+use base $ENV{SB_TEST_CACHABLE}?
+    qw/DBIx::SearchBuilder::Record::Cachable/:
+    qw/DBIx::SearchBuilder::Record/;
+
+sub _Init {
+    my $self = shift;
+    my $handle = shift;
+    $self->Table('Users');
+    $self->_Handle($handle);
+}
+
+sub _ClassAccessible {
+    {
+        id =>
+        {read => 1, type => 'int(11)' },
+        Login =>
+        {read => 1, write => 1, type => 'varchar(18)' },
+        Name =>
+        {read => 1, write => 1, type => 'varchar(36)' },
+        Phone =>
+        {read => 1, write => 1, type => 'varchar(18)', default => ''},
+    }
+}
+
+sub init_data {
+    return (
+	[ 'Login',	'Name',			'Phone' ],
+	[ 'cubic',	'Ruslan U. Zakirov',	'+7-903-264-XX-XX' ],
+	[ 'obra',	'Jesse Vincent',	undef ],
+	[ 'glasser',	'David Glasser',	undef ],
+	[ 'autrijus',	'Autrijus Tang',	'+X-XXX-XXX-XX-XX' ],
+    );
+}
+
+1;
+
+package TestApp::Users;
+
+# use TestApp::User;
+use base qw/DBIx::SearchBuilder/;
+
+sub _Init {
+    my $self = shift;
+    $self->SUPER::_Init( Handle => shift );
+    $self->Table('Users');
+}
+
+sub NewItem
+{
+	my $self = shift;
+	return TestApp::User->new( $self->_Handle );
+}
+
+1;

commit e220a2e3774aba948d556725131583f53fe59653
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Mon Nov 27 14:47:01 2023 -0500

    Add some guidance for using query hints

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 3ed5bb4..7cbc514 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -1957,7 +1957,9 @@ sub Table {
 
 =head2 QueryHint [Hint]
 
-If called with an argument, sets a query hint for this collection.
+If called with an argument, sets a query hint for this collection. Call
+this method before performing additional operations on a collection,
+such as C<Count()>, C<Next()>, etc.
 
 Always returns the query hint.
 

commit ec23588133354cc67183af18eda5bc80ad82b2bf
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Mon Nov 27 14:45:25 2023 -0500

    Produce correct query hints on Oracle
    
    Originally, query hints were written as /* +FooBar */, which Oracle
    treats as comments. By removing the first space, Oracle treats them as
    hints instead.

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 636c9d5..3ed5bb4 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -1983,7 +1983,10 @@ Returns the query hint formatted appropriately for inclusion in SQL queries.
 sub QueryHintFormatted {
     my $self = shift;
     my $QueryHint = $self->QueryHint;
-    return $QueryHint ? " /* $QueryHint */ " : " ";
+
+    # As it turns out, we can't have a space between the opening /*
+    # and the query hint, otherwise Oracle treats this as a comment.
+    return $QueryHint ? " /*$QueryHint */ " : " ";
 }
 
 

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


hooks/post-receive
-- 
dbix-searchbuilder


More information about the Bps-public-commit mailing list