diff options
Diffstat (limited to 'it_dbi.class')
-rw-r--r-- | it_dbi.class | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/it_dbi.class b/it_dbi.class index bd3e2e8..df21396 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -35,7 +35,7 @@ class it_dbi implements Iterator 'server_update' => null, # server to use for write and subsequent reads (only affects current object!) 'user' => "itools", 'pw' => "", - 'safety' => 1, # 0= never die, 1=die if query invalid, 2=die also if no results + 'safety' => 1, # -1=internal without it_error, 0= never die, 1=die if query invalid, 2=die also if no results #'keyfield' => 'ID', # Don't set to null here, filled later by _get_field_info() #'charset' => # client charset (requires MySQL 5.0.7 or later) 'classprefix' => "", @@ -501,9 +501,9 @@ function _where($params) /** * Internal: Output class name::error message and terminate execution. */ -function _fatal($text, $body = null) +function _fatal($text, $body = null, $fatal = true) { - it::fatal(['title' => $this->_error($text) . ", DB: " . $this->_p['db'] . ", Server: " . $this->_p['server'], 'body' => $body]); + it::error(['fatal' => $fatal, 'title' => $this->_error($text) . ", DB: " . $this->_p['db'] . ", Server: " . $this->_p['server'], 'body' => $body]); /* NOT REACHED */ } @@ -580,9 +580,10 @@ function query($query, $p = array()) if (!($result = $this->_query($query, $p))) { - if ($result === null || !$p['safety']) + if ($result === null || $p['safety'] < 0) return false; - $this->_fatal("query() failed", $query); + $this->_fatal("query() failed", $query, $p['safety']); + return false; } else if (it::match('^(CREATE|ALTER|DROP) ', $query, array('utf8' => false))) { @@ -828,7 +829,7 @@ function store($tags = array()) * Update current record or a number of records given by where condition * @param $tags key => value pairs (these have priority over changes in member vars) * @param $where condition to select records to be modified (if not current record) - * @return number of modified records (or false on error). WARNING: read LIMIT docs before using it + * @return number of modified records (or false on error). can be 0 if data already there. also read LIMIT docs * Does not destroy internal state of last select() call */ function update($tags = array(), $where = null) @@ -1121,7 +1122,7 @@ function _connect_db($p) function _get_field_defs() { - for ($res = $this->query('SHOW COLUMNS FROM ' . $this->_p['table']); $res && ($field = $this->_fetch_assoc($res)); ) + for ($res = $this->query('SHOW COLUMNS FROM ' . $this->_p['table'], ['safety' => -1]); $res && ($field = $this->_fetch_assoc($res)); ) $result[$field['Field']] = it::filter_keys($field, ['Field', 'Type', 'Key', 'Extra']); return (array)$result; } |