8 FS::DBI - Freeside wrapper for DBI
14 $dbh = FS::DBI->connect( @args );
16 'UPDATE table SET foo = ? WHERE bar = ?',
19 ) or die $dbh->errstr;
25 Allow Freeside to manage how DBI is used when necessary
27 =head2 Legacy databases and DBD::Pg v3.0+
29 Breaking behavior was introduced in DBD::Pg version 3.0.0
30 in regards to L<DBD::Pg/pg_enable_utf8>.
32 Some freedside databases are legacy databases with older encodings
33 and locales. pg_enable_utf8 no longer sets client_encoding to utf8
34 on non-utf8 databases, causing crashes and data corruption.
36 FS::DBI->connect() enforces utf8 client_encoding on all DBD::Pg connections
40 =head2 connect @connect_args
42 For usage, see L<DBI/connect>
44 Force utf8 client_encoding on DBD::Pg connections
50 my $dbh = $class->SUPER::connect( @_ );
52 if ( $_[0] =~ /^DBI:Pg/ ) {
53 $dbh->do('SET client_encoding TO UTF8;')
54 or die sprintf 'Error setting client_encoding to UTF8: %s', $dbh->errstr;
56 # DBD::Pg requires touching this attribute when changing the client_encoding
57 # on an already established connection, to get expected behavior.
58 $dbh->{pg_enable_utf8} = -1;
64 # Stub required to subclass DBI
66 use base qw( DBI::st );
68 # Stub required to subclass DBI
70 use base qw( DBI::db );