Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r19713: LJSUP-9507 (warn about database/SQL erro...

Committer: ailyin
LJSUP-9507 (warn about database/SQL errors on production/staging servers)
U   trunk/cgi-bin/ljdb.pl
Modified: trunk/cgi-bin/ljdb.pl
===================================================================
--- trunk/cgi-bin/ljdb.pl	2011-08-15 01:41:58 UTC (rev 19712)
+++ trunk/cgi-bin/ljdb.pl	2011-08-15 02:21:57 UTC (rev 19713)
@@ -135,8 +135,25 @@
     return ($startid, $endid);
 }
 
+sub _connection_options {
+    my $options = {
+        'AutoCommit' => 1,
+        'RaiseError' => 0,
+        'PrintError' => 0,
+    };
+
+    if ( $LJ::IS_DEV_SERVER ) {
+        $options->{'RaiseError'} = 1;
+    }
+    else {
+        $options->{'PrintError'} = 1;
+    }
+
+    return { 'connection_opts' => $options };
+}
+
 sub dbh_by_role {
-    return $LJ::DBIRole->get_dbh( @_ );
+    return $LJ::DBIRole->get_dbh( _connection_options(), @_ );
 }
 
 sub dbh_by_name {
@@ -147,13 +164,13 @@
     my $fdsn = $dbh->selectrow_array("SELECT fdsn FROM dbinfo WHERE name=?", undef, $name);
     die "No fdsn found for db name '$name'\n" unless $fdsn;
 
-    return $LJ::DBIRole->get_dbh_conn($fdsn);
+    return $LJ::DBIRole->get_dbh_conn( _connection_options(), $fdsn );
 
 }
 
 sub dbh_by_fdsn {
     my $fdsn = shift;
-    return $LJ::DBIRole->get_dbh_conn($fdsn);
+    return $LJ::DBIRole->get_dbh_conn( _connection_options(), $fdsn );
 }
 
 sub root_dbh_by_name {
@@ -164,7 +181,7 @@
     my $fdsn = $dbh->selectrow_array("SELECT rootfdsn FROM dbinfo WHERE name=?", undef, $name);
     die "No rootfdsn found for db name '$name'\n" unless $fdsn;
 
-    return $LJ::DBIRole->get_dbh_conn($fdsn);
+    return $LJ::DBIRole->get_dbh_conn( _connection_options(), $fdsn );
 }
 
 sub backup_in_progress {
@@ -401,10 +418,9 @@
 # returns: A dbh.
 # </LJFUNC>
 sub get_dbirole_dbh {
-    my $dbh = $LJ::DBIRole->get_dbh( @_ ) or return undef;
+    my $dbh = $LJ::DBIRole->get_dbh( LJ::DB::_connection_options(), @_ )
+        or return undef;
 
-    $dbh->{'RaiseError'} = 1 if $LJ::IS_DEV_SERVER;
-
     if ( $LJ::DB_LOG_HOST && $LJ::HAVE_DBI_PROFILE ) {
         $LJ::DB_REPORT_HANDLES{ $dbh->{Name} } = $dbh;
 

Tags: andy, livejournal, pl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments