summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2011-12-16 16:52:27 +0000
committerUrban Müller2011-12-16 16:52:27 +0000
commite1fe8b0bd01f64b9079ff14313f153a3de5f8a87 (patch)
treed21121083c0db44f32f3cbc964701d4cb2631e88
parent7e8f70d380a9067777d1a755a0c6aeed808baeb1 (diff)
downloaditools-e1fe8b0bd01f64b9079ff14313f153a3de5f8a87.tar.gz
itools-e1fe8b0bd01f64b9079ff14313f153a3de5f8a87.tar.bz2
itools-e1fe8b0bd01f64b9079ff14313f153a3de5f8a87.zip
typesafe floats
-rw-r--r--it_dbi.class9
1 files changed, 5 insertions, 4 deletions
diff --git a/it_dbi.class b/it_dbi.class
index ec152d7..09ff18d 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -596,7 +596,7 @@ function iterate()
unset($this->$field);
foreach ($this->_data as $field => $value)
- $this->$field = isset($value) && $this->_isint[$field] ? ($this->_data[$field] = intval($value)) : $value;
+ $this->$field = (isset($value) && $this->_convertfunc[$field]) ? ($this->_data[$field] = $this->_convertfunc[$field]($value)) : $value;
if ($localizedfields)
{
@@ -764,7 +764,8 @@ function _get_field_info()
for ($res = $this->query('SHOW COLUMNS FROM ' . $this->_p['table']); $res && ($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']] = preg_match('/^(tiny|small|medium|)int/', $field['Type']);
+ if (preg_match('/^(tiny|small|medium|)int|^float|^double/', $field['Type']))
+ $this->_convertfunc[$field['Field']] = it::match('int', $field['Type']) ? "intval" : "floatval";
}
# Consider all fields which have _{localized_defaultlanguage} suffix as localized
@@ -773,11 +774,11 @@ function _get_field_info()
$state = it_dbi::_state_get($dbid); # State could have been modified by query above
$state['fields'][$this->_p['table']] = $this->_fields;
- $state['isint'][$this->_p['table']] = $this->_isint;
+ $state['convertfunc'][$this->_p['table']] = $this->_convertfunc;
it_dbi::_state_put($dbid, $state);
}
else # Existing _fields, copy other info too
- $this->_isint = $state['isint'][$this->_p['table']];
+ $this->_convertfunc = $state['convertfunc'][$this->_p['table']];
foreach((array)$this->_fields as $field)
{