Changeset 1194 in subversion


Ignore:
Timestamp:
Mar 19, 2008 10:36:47 AM (5 years ago)
Author:
thomasb
Message:

Enable SQL logging (set 'sql_debug' config param to true); Switch to emulated prepare mode for better performance

Location:
trunk/roundcubemail/program/include
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/main.inc

    r1145 r1194  
    7575  $DB = new $dbclass($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); 
    7676  $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql'; 
     77  $DB->set_debug((bool)$CONFIG['sql_debug']); 
    7778  $DB->db_connect('w'); 
    7879 
  • trunk/roundcubemail/program/include/rcube_db.inc

    r1089 r1194  
    154154    $this->db_connected = $this->db_handle ? TRUE : FALSE; 
    155155    } 
     156 
     157 
     158  /** 
     159   * Activate/deactivate debug mode 
     160   * (not implemented) 
     161   */ 
     162  function set_debug($dbg = true) 
     163  { 
    156164     
    157      
     165  } 
     166 
     167 
    158168  /** 
    159169   * Getter for error state 
  • trunk/roundcubemail/program/include/rcube_mdb2.inc

    r1084 r1194  
    4949  var $db_error = false; 
    5050  var $db_error_msg = ''; 
     51  var $debug_mode = false; 
    5152 
    5253  var $a_query_results = array('dummy'); 
     
    9596    { 
    9697    // Use persistent connections if available 
    97     $dbh = MDB2::connect($dsn, 
    98       array('persistent' => $this->db_pconn, 
     98    $dbh = MDB2::connect($dsn, array( 
     99        'emulate_prepared' => true, 
     100        'persistent' => $this->db_pconn, 
     101        'debug' => $this->debug_mode, 
     102        'debug_handler' => 'mdb2_debug_handler', 
    99103        'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL)); 
    100104 
     
    156160    } 
    157161 
     162 
     163  /** 
     164   * Activate/deactivate debug mode 
     165   * 
     166   * @param boolean True if SQL queries should be logged 
     167   */ 
     168  function set_debug($dbg = true) 
     169  { 
     170    $this->debug_mode = $dbg; 
     171    if ($this->db_connected) 
     172      $this->db_handle->setOption('debug', $dbg); 
     173  } 
    158174 
    159175     
     
    570586  }  // end class rcube_db 
    571587 
     588 
     589/* this is our own debug handler for the MDB2 connection */ 
     590function mdb2_debug_handler(&$db, $scope, $message, $context = array()) 
     591{ 
     592  if ($scope != 'prepare') 
     593  { 
     594    $debug_output = $scope . '('.$db->db_index.'): '; 
     595    $debug_output .= $message . $db->getOption('log_line_break'); 
     596    write_log('sqllog', $debug_output); 
     597  } 
     598} 
     599 
     600 
    572601?> 
Note: See TracChangeset for help on using the changeset viewer.