Skip to content

Commit

Permalink
Exploit DBI callbacks to make MySQL behave.
Browse files Browse the repository at this point in the history
Fixed compatibility issues on MySQL. Bricolage now sets `sql_mode` when it
connects to the database, so that MySQL itself does not have to globally set
that option, as it could cause conflicts with other apps running on MySQL.
Also removed the attempt to set C<sql_mode> globally at installation time; it
was bad manners, really.

I used the DBI's callback support to make this work, so bumped up the minimum
required DBI to 1.49. That's five years old already, so everyone should be
fine.
  • Loading branch information
theory committed Oct 30, 2009
1 parent 69364ef commit 6857181
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Bric/Admin.pod
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ START MODULE LIST

=item Devel::Symdump

=item DBI 1.18
=item DBI 1.49

=item Error

Expand Down
8 changes: 8 additions & 0 deletions lib/Bric/Changes.pod
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,14 @@ documents with spaces or other URI-escapeable characters in their file names.
Thanks to Scott Lanning for the spot, and Aaron Fuleki for the kick to get it
fixed (Bug #82 / #1456). [David]

=item *

Fixed compatibility issues on MySQL. Bricolage now sets C<sql_mode> when it
connects to the database, so that MySQL itself does not have to globally set
that option, as it could cause conflicts with other apps running on MySQL.
Also removed the attempt to set C<sql_mode> globally at installation time; it
was bad manners, really. Thanks to Waldo Jaquith for the report. [David]

=back

=head1 Version 1.11.1 (2008-10-03)
Expand Down
13 changes: 12 additions & 1 deletion lib/Bric/Util/DBD/mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ use constant DSN_STRING => 'database=' . DB_NAME
. (DB_PORT ? eval "';port=' . DB_PORT" : '');

# This is to set up driver-specific database handle attributes.
use constant DBH_ATTR => ( );
use constant DBH_ATTR => (
Callbacks => {
connected => sub {
my $dbh = shift;
$dbh->do(q{
SET SESSION sql_mode='ansi,strict_trans_tables,no_auto_value_on_zero';
}) unless exists $dbh->{private_bric_sql_mode};
$dbh->{private_bric_sql_mode} = 1;
return;
},
},
);

# This is the maximum for LIMIT rowcount in MySQL
use constant LIMIT_DEFAULT => '18446744073709551615';
Expand Down
1 change: 0 additions & 1 deletion sql/mysql/Bric.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,4 @@ CREATE CAST (integer AS boolean)
WITH FUNCTION int_to_boolean(integer) AS IMPLICIT;
*/

SET GLOBAL sql_mode='ansi,strict_trans_tables';
SET SESSION sql_mode='ansi,strict_trans_tables,no_auto_value_on_zero';

0 comments on commit 6857181

Please sign in to comment.