Changeset View
Changeset View
Standalone View
Standalone View
core/kernel/db/db_connection.php
Show First 20 Lines • Show All 500 Lines • ▼ Show 20 Line(s) | |||||
* @param string $sql | * @param string $sql | ||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param bool $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 = false) | ||||
{ | { | ||||
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 | ||||
Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
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 | ||||
Show All 12 Lines | |||||
* @param string $key_field | * @param string $key_field | ||||
* @param bool $no_debug | * @param bool $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 = false, $iterator_class = 'kMySQLQuery') | ||||
{ | { | ||||
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 451 Lines • ▼ Show 20 Line(s) | |||||
* @param bool $no_debug | * @param bool $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 = false, $iterator_class = 'kMySQLQuery') | ||||
{ | { | ||||
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 |
Inline comments must end in full-stops, exclamation marks, or question marks