diff options
-rw-r--r-- | it_dbi.class | 13 | ||||
-rwxr-xr-x | test/it_dbi.t | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/it_dbi.class b/it_dbi.class index 0eaced2..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))) { @@ -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; } diff --git a/test/it_dbi.t b/test/it_dbi.t index b453da2..083047f 100755 --- a/test/it_dbi.t +++ b/test/it_dbi.t @@ -38,7 +38,7 @@ $opts['subclass']::createclass(['table' => "it_dbi_test", 'forcecreate' => true] $record = new it_dbi_test; $GLOBALS['it_defaultconfig']['fatal_throws_exception'] = true; -is($record->query("SYNTAX ERROR", ['safety' => 0]), false, "Suppress failures with safety 0"); +is(@$record->query("SYNTAX ERROR", ['safety' => 0]), false, "Suppress failures with safety 0"); try { is(@$record->select("SYNTAX ERROR"), "Exception", "Syntax triggers exception for fatal_throws_exception mode"); } catch (Exception $e) { |