mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Allow class name to be specified when executing queries
PDO에는 결과를 어떤 클래스로 받아올지 선택하는 기능이 있는데 (기본값 stdClass) executeQuery()로 쿼리를 실행할 때도 이 기능을 활용할 수 있도록 개선합니다. stdClass를 받아와서 속성들을 추출한 후 documentItem에 도로 집어넣는 등 비효율적인 부분을 추후 개선하는 데 도움이 될 것으로 예상합니다.
This commit is contained in:
parent
1d9033742a
commit
ce5dc45326
2 changed files with 12 additions and 8 deletions
|
|
@ -223,9 +223,10 @@ class DB
|
|||
* @param array $args
|
||||
* @param array $columns
|
||||
* @param string $result_type
|
||||
* @param string $result_class
|
||||
* @return \BaseObject
|
||||
*/
|
||||
public function executeQuery(string $query_id, $args = [], $column_list = [], $result_type = 'auto'): \BaseObject
|
||||
public function executeQuery(string $query_id, $args = [], $column_list = [], $result_type = 'auto', $result_class = ''): \BaseObject
|
||||
{
|
||||
// Validate the args.
|
||||
if (is_object($args))
|
||||
|
|
@ -363,7 +364,7 @@ class DB
|
|||
}
|
||||
elseif ($query->type === 'SELECT')
|
||||
{
|
||||
$result = $this->_fetch($this->_last_stmt, $last_index, $result_type);
|
||||
$result = $this->_fetch($this->_last_stmt, $last_index, $result_type, $result_class);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -506,9 +507,10 @@ class DB
|
|||
* @param \PDOStatement $stmt
|
||||
* @param int $last_index
|
||||
* @param string $result_type
|
||||
* @param string $result_class
|
||||
* @return mixed
|
||||
*/
|
||||
public function _fetch($stmt, $last_index = 0, $result_type = 'auto')
|
||||
public function _fetch($stmt, $last_index = 0, $result_type = 'auto', $result_class = '')
|
||||
{
|
||||
if (!($stmt instanceof \PDOStatement))
|
||||
{
|
||||
|
|
@ -525,7 +527,7 @@ class DB
|
|||
$index = $last_index;
|
||||
$step = $last_index !== 0 ? -1 : 1;
|
||||
|
||||
while ($row = $stmt->fetchObject())
|
||||
while ($row = $stmt->fetchObject($result_class ?: 'stdClass'))
|
||||
{
|
||||
$result[$index] = $row;
|
||||
$index += $step;
|
||||
|
|
|
|||
|
|
@ -137,12 +137,13 @@ function getClass($module_name)
|
|||
* @param array|object $args Arguments
|
||||
* @param array $column_list Column list
|
||||
* @param string $result_type 'auto', 'array' or 'raw'
|
||||
* @param string $result_class Name of class to use instead of stdClass
|
||||
* @return object Query result data
|
||||
*/
|
||||
function executeQuery($query_id, $args = [], $column_list = [], $result_type = 'auto')
|
||||
function executeQuery($query_id, $args = [], $column_list = [], $result_type = 'auto', $result_class = 'stdClass')
|
||||
{
|
||||
$oDB = Rhymix\Framework\DB::getInstance();
|
||||
return $oDB->executeQuery($query_id, $args, $column_list, $result_type);
|
||||
return $oDB->executeQuery($query_id, $args, $column_list, $result_type, $result_class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -152,12 +153,13 @@ function executeQuery($query_id, $args = [], $column_list = [], $result_type = '
|
|||
* @param string $query_id (module name.query XML file)
|
||||
* @param array|object $args Arguments
|
||||
* @param array $column_list Column list
|
||||
* @param string $result_class Name of class to use instead of stdClass
|
||||
* @return object Query result data
|
||||
*/
|
||||
function executeQueryArray($query_id, $args = [], $column_list = [])
|
||||
function executeQueryArray($query_id, $args = [], $column_list = [], $result_class = 'stdClass')
|
||||
{
|
||||
$oDB = Rhymix\Framework\DB::getInstance();
|
||||
return $oDB->executeQuery($query_id, $args, $column_list, 'array');
|
||||
return $oDB->executeQuery($query_id, $args, $column_list, 'array', $result_class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue