mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 09:41:40 +09:00
More element handling of executeQueryArray()
This commit is contained in:
parent
e89abf14f1
commit
8a3afa03cc
2 changed files with 11 additions and 14 deletions
|
|
@ -204,10 +204,10 @@ class DB
|
|||
* @param string $query_id
|
||||
* @param array $args
|
||||
* @param array $columns
|
||||
* @param string $type
|
||||
* @param string $result_type
|
||||
* @return \BaseObject
|
||||
*/
|
||||
public function executeQuery(string $query_id, $args = [], $column_list = []): \BaseObject
|
||||
public function executeQuery(string $query_id, $args = [], $column_list = [], $result_type = 'auto'): \BaseObject
|
||||
{
|
||||
// Validate the args.
|
||||
if (is_object($args))
|
||||
|
|
@ -337,7 +337,7 @@ class DB
|
|||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_fetch($this->_last_stmt, $last_index);
|
||||
$result = $this->_fetch($this->_last_stmt, $last_index, $result_type);
|
||||
}
|
||||
}
|
||||
catch (Exceptions\DBError $e)
|
||||
|
|
@ -404,7 +404,8 @@ class DB
|
|||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_fetch($this->_last_stmt);
|
||||
$count = $this->_last_stmt->fetchColumn(0);
|
||||
$this->_last_stmt->closeCursor();
|
||||
}
|
||||
}
|
||||
catch (Exceptions\DBError $e)
|
||||
|
|
@ -417,7 +418,7 @@ class DB
|
|||
list($is_expression, $list_count) = $query->navigation->list_count->getValue($args);
|
||||
list($is_expression, $page_count) = $query->navigation->page_count->getValue($args);
|
||||
list($is_expression, $page) = $query->navigation->page->getValue($args);
|
||||
$total_count = intval($result->count);
|
||||
$total_count = intval($count);
|
||||
$total_page = max(1, intval(ceil($total_count / $list_count)));
|
||||
$last_index = $total_count - (($page - 1) * $list_count);
|
||||
$page_handler = new \PageHandler($total_count, $total_page, $page, $page_count);
|
||||
|
|
@ -455,9 +456,10 @@ class DB
|
|||
*
|
||||
* @param \PDOStatement $stmt
|
||||
* @param int $last_index
|
||||
* @param string $result_type
|
||||
* @return mixed
|
||||
*/
|
||||
public function _fetch($stmt, $last_index = 0)
|
||||
public function _fetch($stmt, $last_index = 0, $result_type = 'auto')
|
||||
{
|
||||
if (!($stmt instanceof \PDOStatement))
|
||||
{
|
||||
|
|
@ -476,7 +478,7 @@ class DB
|
|||
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($last_index === 0 && count($result) === 1)
|
||||
if ($result_type === 'auto' && $last_index === 0 && count($result) === 1)
|
||||
{
|
||||
return $result[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ function getClass($module_name)
|
|||
function executeQuery($query_id, $args = [], $arg_columns = NULL)
|
||||
{
|
||||
$oDB = Rhymix\Framework\DB::getInstance();
|
||||
return $oDB->executeQuery($query_id, $args, $arg_columns);
|
||||
return $oDB->executeQuery($query_id, $args, $arg_columns, 'auto');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -157,12 +157,7 @@ function executeQuery($query_id, $args = [], $arg_columns = NULL)
|
|||
function executeQueryArray($query_id, $args = [], $arg_columns = NULL)
|
||||
{
|
||||
$oDB = Rhymix\Framework\DB::getInstance();
|
||||
$output = $oDB->executeQuery($query_id, $args, $arg_columns);
|
||||
if(isset($output->data) && is_object($output->data))
|
||||
{
|
||||
$output->data = array($output->data);
|
||||
}
|
||||
return $output;
|
||||
return $oDB->executeQuery($query_id, $args, $arg_columns, 'array');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue