Fix error handling issues

This commit is contained in:
Kijin Sung 2020-06-30 12:16:59 +09:00
parent 936568a8a5
commit 978d3d167a
4 changed files with 37 additions and 12 deletions

View file

@ -305,7 +305,20 @@ class DB
{ {
$this->_last_stmt = $this->_handle->query($query_string); $this->_last_stmt = $this->_handle->query($query_string);
} }
$result = $this->_fetch($this->_last_stmt, $last_index);
if ($this->isError())
{
$output = $this->getError();
$output->add('_query', $query_string);
$output->add('_elapsed_time', '0.00000');
$output->page_navigation = new \PageHandler(0, 0, 0);
$this->_total_time += (microtime(true) - $start_time);
return $output;
}
else
{
$result = $this->_fetch($this->_last_stmt, $last_index);
}
} }
catch (Exceptions\DBError $e) catch (Exceptions\DBError $e)
{ {
@ -361,7 +374,15 @@ class DB
{ {
$this->_last_stmt = $this->_handle->query($query_string); $this->_last_stmt = $this->_handle->query($query_string);
} }
$result = $this->_fetch($this->_last_stmt);
if ($this->isError())
{
return $this->getError();
}
else
{
$result = $this->_fetch($this->_last_stmt);
}
} }
catch (Exceptions\DBError $e) catch (Exceptions\DBError $e)
{ {

View file

@ -366,7 +366,7 @@ class VariableBase
} }
// Check minimum and maximum lengths. // Check minimum and maximum lengths.
$length = iconv_strlen($value, 'UTF-8'); $length = is_scalar($value) ? iconv_strlen($value, 'UTF-8') : (is_countable($value) ? count($value) : 1);
if (isset($this->minlength) && $this->minlength > 0 && $length < $this->minlength) if (isset($this->minlength) && $this->minlength > 0 && $length < $this->minlength)
{ {
throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $this->column . ' must contain no less than ' . $this->minlength . ' characters'); throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $this->column . ' must contain no less than ' . $this->minlength . ' characters');

View file

@ -54,7 +54,7 @@ class DBQueryParser extends BaseParser
$query->pipe = strtoupper($attribs['pipe']) ?: 'AND'; $query->pipe = strtoupper($attribs['pipe']) ?: 'AND';
// Load tables. // Load tables.
foreach ($xml->tables->table as $tag) foreach ($xml->tables->table ?: [] as $tag)
{ {
if (trim($tag['query']) === 'true') if (trim($tag['query']) === 'true')
{ {
@ -81,7 +81,7 @@ class DBQueryParser extends BaseParser
} }
// Load columns. // Load columns.
foreach ($xml->columns->column as $tag) foreach ($xml->columns->column ?: [] as $tag)
{ {
if ($tag->getName() === 'query') if ($tag->getName() === 'query')
{ {
@ -146,7 +146,7 @@ class DBQueryParser extends BaseParser
if ($xml->navigation) if ($xml->navigation)
{ {
$query->navigation = new DBQuery\Navigation; $query->navigation = new DBQuery\Navigation;
foreach ($xml->navigation->index as $tag) foreach ($xml->navigation->index ?: [] as $tag)
{ {
$orderby = new DBQuery\OrderBy; $orderby = new DBQuery\OrderBy;
$orderby->var = trim($tag['var']) ?: null; $orderby->var = trim($tag['var']) ?: null;

View file

@ -78,12 +78,16 @@ class ModuleInfoParser extends BaseParser
} }
// Add information about actions. // Add information about actions.
$action_info = ModuleActionParser::loadXML(strtr($filename, ['info.xml' => 'module.xml'])); $action_filename = strtr($filename, ['info.xml' => 'module.xml']);
$info->admin_index_act = $action_info->admin_index_act; if (file_exists($action_filename))
$info->default_index_act = $action_info->default_index_act; {
$info->setup_index_act = $action_info->setup_index_act; $action_info = ModuleActionParser::loadXML($action_filename);
$info->simple_setup_index_act = $action_info->simple_setup_index_act; $info->admin_index_act = $action_info->admin_index_act;
$info->error_handlers = $action_info->error_handlers ?: []; $info->default_index_act = $action_info->default_index_act;
$info->setup_index_act = $action_info->setup_index_act;
$info->simple_setup_index_act = $action_info->simple_setup_index_act;
$info->error_handlers = $action_info->error_handlers ?: [];
}
// Return the complete result. // Return the complete result.
return $info; return $info;