diff -ur SpamAssassin.dist/BayesStore/MySQL.pm SpamAssassin/BayesStore/MySQL.pm --- SpamAssassin.dist/BayesStore/MySQL.pm 2006-09-29 13:06:38.000000000 +0000 +++ SpamAssassin/BayesStore/MySQL.pm 2006-10-31 15:36:26.676255534 +0000 @@ -641,20 +641,24 @@ =cut sub _connect_db { - my ($self) = @_; + my ($self, $write) = @_; + $self->{_dbh}->disconnect if ($self->{_dbh}); $self->{_dbh} = undef; + my $dsn = $write ? $self->{_dsnw} : $self->{_dsn}; + # Turn off PrintError and explicitly set AutoCommit to off - my $dbh = DBI->connect($self->{_dsn}, $self->{_dbuser}, $self->{_dbpass}, + my $dbh = DBI->connect($dsn, + $self->{_dbuser}, $self->{_dbpass}, {'PrintError' => 0, 'AutoCommit' => 0}); if (!$dbh) { - dbg("bayes: unable to connect to database: ".DBI->errstr()); + dbg("bayes: unable to connect to database $dsn: ".DBI->errstr()); return 0; } else { - dbg("bayes: database connection established"); + dbg("bayes: database connection established to $dsn"); } $self->{_dbh} = $dbh; diff -ur SpamAssassin.dist/BayesStore/SQL.pm SpamAssassin/BayesStore/SQL.pm --- SpamAssassin.dist/BayesStore/SQL.pm 2006-09-29 13:06:38.000000000 +0000 +++ SpamAssassin/BayesStore/SQL.pm 2006-11-01 20:54:53.999887332 +0000 @@ -73,7 +73,13 @@ return undef; } + if (!$self->{bayes}->{conf}->{bayes_sql_dsn_write}) { + dbg("bayes: invalid config, must set bayes_sql_dsn_write config variable\n"); + return undef; + } + $self->{_dsn} = $self->{bayes}->{conf}->{bayes_sql_dsn}; + $self->{_dsnw} = $self->{bayes}->{conf}->{bayes_sql_dsn_write}; $self->{_dbuser} = $self->{bayes}->{conf}->{bayes_sql_username}; $self->{_dbpass} = $self->{bayes}->{conf}->{bayes_sql_password}; @@ -116,17 +122,13 @@ return 0 unless (HAS_DBI); - if ($self->{_dbh}) { - # already connected, but connection has now become readonly - $self->{db_writable_p} = 0; - return 1; - } + return 1 if ($self->{_dbh} && $self->{db_writable_p} == 0); my $main = $self->{bayes}->{main}; $self->read_db_configs(); - return 0 unless ($self->_connect_db()); + return 0 unless ($self->_connect_db(0)); my $db_ver = $self->_get_db_version(); $self->{db_version} = $db_ver; @@ -163,17 +165,13 @@ return 0 unless (HAS_DBI); - if ($self->{_dbh}) { - # already connected, but now it will be writable - $self->{db_writable_p} = 1; - return 1; - } - + return 1 if ($self->{_dbh} && $self->{db_writable_p} == 1); + my $main = $self->{bayes}->{main}; $self->read_db_configs(); - return 0 unless ($self->_connect_db()); + return 0 unless ($self->_connect_db(1)); my $db_ver = $self->_get_db_version(); $self->{db_version} = $db_ver; diff -ur SpamAssassin.dist/Conf.pm SpamAssassin/Conf.pm --- SpamAssassin.dist/Conf.pm 2006-09-29 13:06:40.000000000 +0000 +++ SpamAssassin/Conf.pm 2006-11-01 21:01:13.971526387 +0000 @@ -2301,6 +2301,21 @@ type => $CONF_TYPE_STRING }); +=item bayes_sql_dsn_write DBI::databasetype:databasename:hostname:port + +Used for BayesStore::SQL storage implementation. + +This option give the connect string used to connect to the SQL based Bayes storage for write operations. + +=cut + + push (@cmds, { + setting => 'bayes_sql_dsn_write', + is_admin => 1, + default => '', + type => $CONF_TYPE_STRING + }); + =item bayes_sql_username Used by BayesStore::SQL storage implementation.