Index: branches/5.2.x/core/kernel/db/db_connection.php =================================================================== diff -u -N -r14811 -r14845 --- branches/5.2.x/core/kernel/db/db_connection.php (.../db_connection.php) (revision 14811) +++ branches/5.2.x/core/kernel/db/db_connection.php (.../db_connection.php) (revision 14845) @@ -1,6 +1,6 @@ lastQuery = $select_sql; + $this->_queryCount++; + + $query_func = $this->getMetaFunction('query'); + + // set 1st checkpoint: begin + if ($this->_captureStatistics) { + $start_time = microtime(true); + } + // set 1st checkpoint: end + + $this->setError(0, ''); // reset error + $resource = $query_func($select_sql, $this->connectionID); + + // set 2nd checkpoint: begin + if ($this->_captureStatistics) { + $query_time = microtime(true) - $start_time; + if ($query_time > DBG_MAX_SQL_TIME) { + $this->Application->logSlowQuery($select_sql, $query_time); + } + $this->_queryTime += $query_time; + } + // set 2nd checkpoint: end + + if ( is_resource($resource) ) { + return $resource; + } + + return $this->showError($select_sql); + } + + /** + * Returns row count in recordset + * + * @param resource $resource + * @return int + * @access public + */ + public function RowCount($resource) + { + $count_func = $this->getMetaFunction('num_rows'); + + return $count_func($resource); + } + + /** + * Returns next available row from recordset + * + * @param resource $resource + * @param string $fetch_type + * @return Array + * @access public + * @see kDBConnection::QueryRaw + */ + public function GetNextRow($resource, $fetch_type = 'assoc') + { + $fetch_func = $this->getMetaFunction('fetch_' . $fetch_type); + + return $fetch_func($resource); + } + + /** + * Free memory used to hold recordset handle + * + * @param resource $resource + * @access public + * @see kDBConnection::QueryRaw + */ + public function Destroy($resource = null) + { + if ( !isset($resource) ) { + $resource = $this->queryID; + } + + if ( $resource ) { + $free_func = $this->getMetaFunction('free_result'); + $free_func($resource); + + $this->queryID = null; + } + } + + /** * Performs sql query, that will change database content * * @param string $sql @@ -725,20 +817,6 @@ } /** - * Free memory used to hold recordset handle - * - * @access public - */ - public function Destroy() - { - if ( $this->queryID ) { - $free_func = $this->getMetaFunction('free_result'); - $free_func($this->queryID); - $this->queryID = null; - } - } - - /** * Returns auto increment field value from * insert like operation if any, zero otherwise * @@ -987,7 +1065,7 @@ public function getSlaveLag() { // don't use kDBConnection::Query method, since it will create an array of all server processes - $rs = mysql_query('SHOW PROCESSLIST', $this->connectionID); + $rs = $this->QueryRaw('SHOW PROCESSLIST'); $skip_states = Array ( 'Waiting for master to send event', @@ -998,13 +1076,17 @@ ); // find slave SQL thread - while ( $row = mysql_fetch_array($rs) ) { + while ( $row = $this->GetNextRow($rs, 'array') ) { if ( $row['User'] == 'system user' && !in_array($row['State'], $skip_states) ) { // this is it, return the time (except -ve) + $this->Destroy($rs); + return $row['Time'] > 0x7fffffff ? false : $row['Time']; } } + $this->Destroy($rs); + return false; } } \ No newline at end of file