Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] SQLSource encoding

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Guillaume Rousse <address@concealed>
  • To: address@concealed
  • Subject: Re: [sympa-developpers] SQLSource encoding
  • Date: Thu, 25 Jul 2013 16:49:34 +0200

Le 25/07/2013 16:20, David Verdin a écrit :

Le 25/07/13 15:58, Guillaume Rousse a écrit :
Le 25/07/2013 15:48, David Verdin a écrit :
Hi,

I'm merging SQLSource to Sympa::Datasource::SQL (the problem will be the
same in Sympa::Database).

Problem: In the 6.2 branch, Soji added the enforcement of the UTF-8
encoding on the client side for all supported engines. It was done in
the "establish_connection" sub. Now, in SQL.pm, we only have a "connect"
sub with no part related to a given RDBMS.The sub modules for each RDBMS
don't have a "connect" sub. So where can we enforce UTF-8 usage? Can we
create an "enforce_utf8" sub in each module, which will be called in the
SQL::connect?
You probably didn't found thqem, but both
Sympa::Datasource::SQL::SQLite and Sympa::Datasource::SQL::Sybase
override the definition of connect() method for database-specific
processing.
Damn me; i didn't read all the subclasses; Sorry.

Here is Sybase case, for instance:

sub connect {
my ($self, %params) = @_;

my $result = $self->SUPER::connect(%params);
return unless $result;

$self->{dbh}->do("use $self->{db_name}");

return 1;
}
Good. however, in some cases, UTF-8 enforcment should be done before
connecting. It then would favorize an "enforce_utf8" sub.
Keep It Stupid Simple: no need for two different methods when one is enough.

Just export needed environment variables before calling the original method. The current Sympa::Database::Oracle::connect, for instance, should be modified as:

sub connect {
my ($self, %params) = @_;

$ENV{'NLS_LANG'} = 'UTF8';

my $result = $self->SUPER::connect(%params);
return $result;
}

[..]

Al ittle look at the modification made by Soji, so that he can also give
us advice about where to set up this code:
https://sourcesup.renater.fr/scm/viewvc.php/branches/sympa-6.2-branch/src/lib/SQLSource.pm?root=sympa&r1=7621&r2=9562
For everything related to database-specific initialisation:
- in Sympa::Database::Oracle::connect method for the oracle part
- in Sympa::Database::Sybase::connect method for the sybase part
- in Sympa::Database::MySQL::connect method for the mysql part

Everything related to parameter binding in do_query and do_prepared_query can be discarded, those methods don't exist anymore, and binding is now delegated to DBI internals.

The connection pooling (global %db_connections hash) doesn't exist anymore.

The call to send_notify_to_listmaster() in case of connection failure has been transfered into calling code, to kill dependency on the related package.

Once done, you have a bunch of tests available in t/database and t/datasource to check your code.
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31

Attachment: smime.p7s
Description: Signature cryptographique S/MIME




Archive powered by MHonArc 2.6.19+.

Top of Page