[Bps-public-commit] dbix-searchbuilder branch disable-combine-search-on-old-mysql created. 1.71-15-g875f3d3
BPS Git Server
git at git.bestpractical.com
Mon Oct 24 17:57:12 UTC 2022
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, disable-combine-search-on-old-mysql has been created
at 875f3d3ffbda1796d565a96307a03938759eaad2 (commit)
- Log -----------------------------------------------------------------
commit 875f3d3ffbda1796d565a96307a03938759eaad2
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 25 01:35:25 2022 +0800
Do not enable CombineSearchAndCount for old MariaDB/MySQL versions
This feature requires MariaDB 10.2+ and MySQL 8+. On old versions
enabling this feature will cause SQL syntax error like:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '() AS search_builder_count_all FROM ...'
diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 30dc090..094c5b6 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -808,7 +808,13 @@ in a single query.
sub CombineSearchAndCount {
my $self = shift;
if ( @_ ) {
- $self->{'_combine_search_and_count'} = shift;
+ if ( $self->_Handle->HasSupportForCombineSearchAndCount ) {
+ $self->{'_combine_search_and_count'} = shift;
+ }
+ else {
+ warn "No support for CombineSearchAndCount";
+ return undef;
+ }
}
return $self->{'_combine_search_and_count'};
}
diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index 079bcda..33a4f60 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -1802,6 +1802,16 @@ sub HasSupportForNullsOrder {
return 0;
}
+=head2 HasSupportForCombineSearchAndCount
+
+Returns true value if DB supports to combine search and count in single
+query.
+
+=cut
+
+sub HasSupportForCombineSearchAndCount {
+ return 1;
+}
=head2 QuoteName
diff --git a/lib/DBIx/SearchBuilder/Handle/mysql.pm b/lib/DBIx/SearchBuilder/Handle/mysql.pm
index 7e2ae77..09720ce 100755
--- a/lib/DBIx/SearchBuilder/Handle/mysql.pm
+++ b/lib/DBIx/SearchBuilder/Handle/mysql.pm
@@ -355,6 +355,24 @@ sub _RequireQuotedTables {
return 0;
}
+=head2 HasSupportForCombineSearchAndCount
+
+MariaDB 10.2+ and MySQL 8+ support this.
+
+=cut
+
+sub HasSupportForCombineSearchAndCount {
+ my $self = shift;
+ my ($version) = $self->DatabaseVersion =~ /^(\d+\.\d+)/;
+
+ if ( $self->_IsMariaDB ) {
+ return $version >= 10.2 ? 1 : 0;
+ }
+ else {
+ return $version >= 8 ? 1 : 0;
+ }
+}
+
1;
__END__
diff --git a/t/03searches_combine.t b/t/03searches_combine.t
index 25c06e6..39f5cdd 100644
--- a/t/03searches_combine.t
+++ b/t/03searches_combine.t
@@ -24,6 +24,11 @@ SKIP: {
my $handle = get_handle($d);
connect_handle($handle);
+
+ if ( !$handle->HasSupportForCombineSearchAndCount ) {
+ skip "Database version doesn't support CombineSearchAndCount", TESTS_PER_DRIVER;
+ }
+
isa_ok( $handle->dbh, 'DBI::db' );
my $ret = init_schema( 'TestApp', $handle );
-----------------------------------------------------------------------
hooks/post-receive
--
dbix-searchbuilder
More information about the Bps-public-commit
mailing list