diff options
author | Christian Schneider | 2007-11-28 18:10:00 +0000 |
---|---|---|
committer | Christian Schneider | 2007-11-28 18:10:00 +0000 |
commit | 5774575030ccedf614c619052bc8c3758e7511d1 (patch) | |
tree | 6678e987a3b6d857f72dd26b074832a18574bae5 /it_dbi.class | |
parent | bcfedeeba1b0a06901e56a4f8987e82a0b30cc4a (diff) | |
download | itools-5774575030ccedf614c619052bc8c3758e7511d1.tar.gz itools-5774575030ccedf614c619052bc8c3758e7511d1.tar.bz2 itools-5774575030ccedf614c619052bc8c3758e7511d1.zip |
Precalculate int property of fields to reduce iterate() overhead
Diffstat (limited to 'it_dbi.class')
-rw-r--r-- | it_dbi.class | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/it_dbi.class b/it_dbi.class index b2c78ef..5552c6d 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -41,6 +41,7 @@ class it_dbi var $_key; # Key of currently loaded record or null (public readonly) var $_fields; # Array of name => array(Field,Type,Null,Key,Default,Extra,Length) of fields (public readonly) + var $_isint; # Array of name => bool if field is an INT field var $_link; # DB link identifier (private) @@ -492,7 +493,7 @@ function iterate() if ($this->_data = mysql_fetch_assoc($this->_result)) { foreach ($this->_data as $field => $value) - $this->$field = ($this->_fields[$field]['Type'] == 'int(11)') ? ($this->_data[$field] = intval($value)) : $value; + $this->$field = $this->_isint[$field] ? ($this->_data[$field] = intval($value)) : $value; if (!empty($this->_p['keyfield'])) $this->_key = $this->_data[$this->_p['keyfield']]; @@ -620,7 +621,10 @@ function _get_field_info() { debug("it_dbi(): no fields for {$this->_p['dbid']}.{$this->_p['table']}, calculating.", 5); for ($res = $this->query('SHOW COLUMNS FROM ' . $this->_p['table']); $field = mysql_fetch_assoc($res);) + { $this->_fields[$field['Field']] = $field + array('Length' => preg_match('/date|time/', $field['Type']) ? 20 : intval(it::match('\d+', $field['Type']))); + $this->_isint[$field['Field']] = $field['Type'] == "int(11)"; + } $GLOBALS['it_dbi']->_state[$this->_p['dbid']]['fields'][$this->_p['table']] = $this->_fields; } |