Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/db_connection.php
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | |||||
* Indicates, that next database query could be cached, when memory caching is enabled | * Indicates, that next database query could be cached, when memory caching is enabled | ||||
* | * | ||||
* @var bool | * @var bool | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public $nextQueryCachable = false; | public $nextQueryCachable = false; | ||||
/** | /** | ||||
* The "no debugging" state of the SQL queries. | |||||
* | |||||
* @var boolean | |||||
*/ | |||||
public $noDebuggingState = false; | |||||
/** | |||||
* For backwards compatibility with kDBLoadBalancer class | * For backwards compatibility with kDBLoadBalancer class | ||||
* | * | ||||
* @var bool | * @var bool | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public $nextQueryFromMaster = false; | public $nextQueryFromMaster = false; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
/** | /** | ||||
* Shows error message from previous operation | * Shows error message from previous operation | ||||
* if it failed | * if it failed | ||||
* | * | ||||
* @param string $sql | * @param string $sql | ||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param boolean|null $no_debug | ||||
* @return bool | * @return bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function showError($sql = '', $key_field = null, $no_debug = false) | protected function showError($sql = '', $key_field = null, $no_debug = null) | ||||
{ | { | ||||
static $retry_count = 0; | static $retry_count = 0; | ||||
if ( $no_debug === null ) { | |||||
$no_debug = $this->noDebuggingState; | |||||
} | |||||
if ( !is_object($this->connectionID) ) { | if ( !is_object($this->connectionID) ) { | ||||
// no connection while doing mysql_query | // no connection while doing mysql_query | ||||
$this->errorCode = mysqli_connect_errno(); | $this->errorCode = mysqli_connect_errno(); | ||||
if ( $this->hasError() ) { | if ( $this->hasError() ) { | ||||
$this->errorMessage = mysqli_connect_error(); | $this->errorMessage = mysqli_connect_error(); | ||||
$ret = $this->callErrorHandler($sql); | $ret = $this->callErrorHandler($sql); | ||||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Queries db with $sql query supplied and returns rows selected if any, false otherwise. | * Queries db with $sql query supplied and returns rows selected if any, false otherwise. | ||||
* | * | ||||
* Optional parameter $key_field allows to set one of the query fields value as key in string array. | * Optional parameter $key_field allows to set one of the query fields value as key in string array. | ||||
* | * | ||||
* @param string $sql | * @param string $sql | ||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param boolean|null $no_debug | ||||
* @return Array | * @return Array | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function Query($sql, $key_field = null, $no_debug = false) | public function Query($sql, $key_field = null, $no_debug = null) | ||||
{ | { | ||||
if ( $no_debug === null ) { | |||||
$no_debug = $this->noDebuggingState; | |||||
} | |||||
if ( !$no_debug ) { | |||||
$this->_queryCount++; | $this->_queryCount++; | ||||
} | |||||
$this->lastQuery = $sql; | $this->lastQuery = $sql; | ||||
// set 1st checkpoint: begin | // set 1st checkpoint: begin | ||||
$start_time = $this->_captureStatistics ? microtime(true) : 0; | $start_time = $this->_captureStatistics ? microtime(true) : 0; | ||||
// set 1st checkpoint: end | // set 1st checkpoint: end | ||||
$this->setError(0, ''); // reset error | $this->setError(0, ''); // reset error | ||||
$this->queryID = $this->connectionID->query($sql); | $this->queryID = $this->connectionID->query($sql); | ||||
if ( is_object($this->queryID) ) { | if ( is_object($this->queryID) ) { | ||||
$ret = Array (); | $ret = Array (); | ||||
if ( isset($key_field) ) { | if ( isset($key_field) ) { | ||||
while ( $row = $this->queryID->fetch_assoc() ) { | while ( $row = $this->queryID->fetch_assoc() ) { | ||||
$ret[$row[$key_field]] = $row; | $ret[$row[$key_field]] = $row; | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
while ( $row = $this->queryID->fetch_assoc() ) { | while ( $row = $this->queryID->fetch_assoc() ) { | ||||
$ret[] = $row; | $ret[] = $row; | ||||
} | } | ||||
} | } | ||||
$this->Destroy(); | |||||
// set 2nd checkpoint: begin | // set 2nd checkpoint: begin | ||||
if ( $this->_captureStatistics ) { | if ( $this->_captureStatistics ) { | ||||
$query_time = microtime(true) - $start_time; | $query_time = microtime(true) - $start_time; | ||||
if ( $query_time > DBG_MAX_SQL_TIME ) { | if ( $query_time > DBG_MAX_SQL_TIME && !$no_debug ) { | ||||
$this->Application->logSlowQuery($sql, $query_time); | $this->Application->logSlowQuery($sql, $query_time); | ||||
} | } | ||||
$this->_queryTime += $query_time; | $this->_queryTime += $query_time; | ||||
} | } | ||||
// set 2nd checkpoint: end | // set 2nd checkpoint: end | ||||
$this->Destroy(); | |||||
return $ret; | return $ret; | ||||
} | } | ||||
else { | else { | ||||
// set 2nd checkpoint: begin | // set 2nd checkpoint: begin | ||||
if ( $this->_captureStatistics ) { | if ( $this->_captureStatistics ) { | ||||
$this->_queryTime += microtime(true) - $start_time; | $this->_queryTime += microtime(true) - $start_time; | ||||
} | } | ||||
// set 2nd checkpoint: end | // set 2nd checkpoint: end | ||||
} | } | ||||
return $this->showError($sql, $key_field, $no_debug); | return $this->showError($sql, $key_field, $no_debug); | ||||
} | } | ||||
/** | /** | ||||
* Returns iterator to a recordset, produced from running $sql query. | * Returns iterator to a recordset, produced from running $sql query. | ||||
* | * | ||||
* Queries db with $sql query supplied and returns kMySQLQuery iterator or false in case of error. | * Queries db with $sql query supplied and returns kMySQLQuery iterator or false in case of error. | ||||
* Optional parameter $key_field allows to set one of the query fields value as key in string array. | * Optional parameter $key_field allows to set one of the query fields value as key in string array. | ||||
* | * | ||||
* @param string $sql | * @param string $sql | ||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param boolean|null $no_debug | ||||
* @param string $iterator_class | * @param string $iterator_class | ||||
* @return kMySQLQuery|bool | * @return kMySQLQuery|bool | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function GetIterator($sql, $key_field = null, $no_debug = false, $iterator_class = 'kMySQLQuery') | public function GetIterator($sql, $key_field = null, $no_debug = null, $iterator_class = 'kMySQLQuery') | ||||
{ | { | ||||
if ( $no_debug === null ) { | |||||
$no_debug = $this->noDebuggingState; | |||||
} | |||||
if ( !$no_debug ) { | |||||
$this->_queryCount++; | $this->_queryCount++; | ||||
} | |||||
$this->lastQuery = $sql; | $this->lastQuery = $sql; | ||||
// set 1st checkpoint: begin | // set 1st checkpoint: begin | ||||
$start_time = $this->_captureStatistics ? microtime(true) : 0; | $start_time = $this->_captureStatistics ? microtime(true) : 0; | ||||
// set 1st checkpoint: end | // set 1st checkpoint: end | ||||
$this->setError(0, ''); // reset error | $this->setError(0, ''); // reset error | ||||
$this->queryID = $this->connectionID->query($sql); | $this->queryID = $this->connectionID->query($sql); | ||||
if ( is_object($this->queryID) ) { | if ( is_object($this->queryID) ) { | ||||
/** @var kMySQLQuery $ret */ | /** @var kMySQLQuery $ret */ | ||||
$ret = new $iterator_class($this->queryID, $key_field); | $ret = new $iterator_class($this->queryID, $key_field); | ||||
// set 2nd checkpoint: begin | // set 2nd checkpoint: begin | ||||
if ( $this->_captureStatistics ) { | if ( $this->_captureStatistics ) { | ||||
$query_time = microtime(true) - $start_time; | $query_time = microtime(true) - $start_time; | ||||
if ( $query_time > DBG_MAX_SQL_TIME ) { | if ( $query_time > DBG_MAX_SQL_TIME && !$no_debug ) { | ||||
$this->Application->logSlowQuery($sql, $query_time); | $this->Application->logSlowQuery($sql, $query_time); | ||||
} | } | ||||
$this->_queryTime += $query_time; | $this->_queryTime += $query_time; | ||||
} | } | ||||
// set 2nd checkpoint: end | // set 2nd checkpoint: end | ||||
return $ret; | return $ret; | ||||
▲ Show 20 Lines • Show All 361 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Queries db with $sql query supplied and returns rows selected if any, false otherwise. | * Queries db with $sql query supplied and returns rows selected if any, false otherwise. | ||||
* | * | ||||
* Optional parameter $key_field allows to set one of the query fields value as key in string array. | * Optional parameter $key_field allows to set one of the query fields value as key in string array. | ||||
* | * | ||||
* @param string $sql | * @param string $sql | ||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param boolean|null $no_debug | ||||
* @return Array | * @return Array | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function Query($sql, $key_field = null, $no_debug = false) | public function Query($sql, $key_field = null, $no_debug = null) | ||||
{ | { | ||||
if ( $no_debug === null ) { | |||||
$no_debug = $this->noDebuggingState; | |||||
} | |||||
if ( $no_debug ) { | if ( $no_debug ) { | ||||
return parent::Query($sql, $key_field, $no_debug); | return parent::Query($sql, $key_field, $no_debug); | ||||
} | } | ||||
global $debugger; | global $debugger; | ||||
$this->_queryCount++; | $this->_queryCount++; | ||||
$this->lastQuery = $sql; | $this->lastQuery = $sql; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Returns iterator to a recordset, produced from running $sql query. | * Returns iterator to a recordset, produced from running $sql query. | ||||
* | * | ||||
* Queries db with $sql query supplied and returns kMySQLQuery iterator or false in case of error. | * Queries db with $sql query supplied and returns kMySQLQuery iterator or false in case of error. | ||||
* Optional parameter $key_field allows to set one of the query fields value as key in string array. | * Optional parameter $key_field allows to set one of the query fields value as key in string array. | ||||
* | * | ||||
* @param string $sql | * @param string $sql | ||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param boolean|null $no_debug | ||||
* @param string $iterator_class | * @param string $iterator_class | ||||
* @return kMySQLQuery|bool | * @return kMySQLQuery|bool | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function GetIterator($sql, $key_field = null, $no_debug = false, $iterator_class = 'kMySQLQuery') | public function GetIterator($sql, $key_field = null, $no_debug = null, $iterator_class = 'kMySQLQuery') | ||||
{ | { | ||||
if ( $no_debug === null ) { | |||||
$no_debug = $this->noDebuggingState; | |||||
} | |||||
if ( $no_debug ) { | if ( $no_debug ) { | ||||
return parent::Query($sql, $key_field, $no_debug, $iterator_class); | return parent::GetIterator($sql, $key_field, $no_debug, $iterator_class); | ||||
} | } | ||||
global $debugger; | global $debugger; | ||||
$this->_queryCount++; | $this->_queryCount++; | ||||
$this->lastQuery = $sql; | $this->lastQuery = $sql; | ||||
// set 1st checkpoint: begin | // set 1st checkpoint: begin | ||||
▲ Show 20 Lines • Show All 339 Lines • Show Last 20 Lines |