MINOR Performance optimisation in MSSQLDatabase::nextRecord() by

building field meta-data only on construct of MSSQLQuery
This commit is contained in:
Sean Harvey 2012-06-12 13:31:29 +12:00
parent a4c269bf62
commit 0465f1b1a2

View File

@ -1724,6 +1724,12 @@ class MSSQLQuery extends SS_Query {
*/ */
private $mssql = null; private $mssql = null;
/**
* A list of field meta-data, such as column name and data type.
* @var array
*/
private $fields = array();
/** /**
* Hook the result-set given into a Query class, suitable for use by sapphire. * Hook the result-set given into a Query class, suitable for use by sapphire.
* @param database The database object that created this query. * @param database The database object that created this query.
@ -1733,6 +1739,15 @@ class MSSQLQuery extends SS_Query {
$this->database = $database; $this->database = $database;
$this->handle = $handle; $this->handle = $handle;
$this->mssql = $mssql; $this->mssql = $mssql;
// build a list of field meta-data for this query we'll use in nextRecord()
// doing it here once saves us from calling mssql_fetch_field() in nextRecord()
// potentially hundreds of times, which is unnecessary.
if($this->mssql && is_resource($this->handle)) {
for($i = 0; $i < mssql_num_fields($handle); $i++) {
$this->fields[$i] = mssql_fetch_field($handle, $i);
}
}
} }
public function __destruct() { public function __destruct() {
@ -1776,7 +1791,7 @@ class MSSQLQuery extends SS_Query {
if($this->mssql) { if($this->mssql) {
if($row = mssql_fetch_row($this->handle)) { if($row = mssql_fetch_row($this->handle)) {
foreach($row as $i => $value) { foreach($row as $i => $value) {
$field = mssql_fetch_field($this->handle, $i); $field = $this->fields[$i];
// fix datetime formatting from format "Jan 1 2012 12:00:00:000AM" to "2012-01-01 12:00:00" // fix datetime formatting from format "Jan 1 2012 12:00:00:000AM" to "2012-01-01 12:00:00"
// strtotime doesn't understand this format, so we need to do some modification of the value first // strtotime doesn't understand this format, so we need to do some modification of the value first