Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 4 additions & 139 deletions system/Database/BaseResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,32 @@
abstract class BaseResult implements ResultInterface
{
/**
* Connection ID
*
* @var TConnection
*/
public $connID;

/**
* Result ID
*
* @var false|TResult
*/
public $resultID;

/**
* Result Array
*
* @var list<array>
*/
public $resultArray = [];

/**
* Result Object
*
* @var list<object>
*/
public $resultObject = [];

/**
* Custom Result Object
*
* @var array
* @var array<class-string, list<object>>
*/
public $customResultObject = [];

/**
* Current Row index
* Current row index
*
* @var int
*/
Expand All @@ -74,15 +64,11 @@ abstract class BaseResult implements ResultInterface
protected $numRows;

/**
* Row data
*
* @var array|null
* @var array<string, mixed>|null
*/
public $rowData;

/**
* Constructor
*
* @param TConnection $connID
* @param TResult $resultID
*/
Expand All @@ -92,13 +78,6 @@ public function __construct(&$connID, &$resultID)
$this->resultID = $resultID;
}

/**
* Retrieve the results of the query. Typically an array of
* individual data rows, which can be either an 'array', an
* 'object', or a custom class name.
*
* @param string $type The row type. Either 'array', 'object', or a class name to use
*/
public function getResult(string $type = 'object'): array
{
if ($type === 'array') {
Expand All @@ -112,13 +91,6 @@ public function getResult(string $type = 'object'): array
return $this->getCustomResultObject($type);
}

/**
* Returns the results as an array of custom objects.
*
* @param class-string $className
*
* @return array
*/
public function getCustomResultObject(string $className)
{
if (isset($this->customResultObject[$className])) {
Expand Down Expand Up @@ -165,11 +137,6 @@ public function getCustomResultObject(string $className)
return $this->customResultObject[$className];
}

/**
* Returns the results as an array of arrays.
*
* If no results, an empty array is returned.
*/
public function getResultArray(): array
{
if ($this->resultArray !== []) {
Expand Down Expand Up @@ -202,13 +169,6 @@ public function getResultArray(): array
return $this->resultArray;
}

/**
* Returns the results as an array of objects.
*
* If no results, an empty array is returned.
*
* @return list<stdClass>
*/
public function getResultObject(): array
{
if ($this->resultObject !== []) {
Expand Down Expand Up @@ -245,19 +205,6 @@ public function getResultObject(): array
return $this->resultObject;
}

/**
* Wrapper object to return a row as either an array, an object, or
* a custom class.
*
* If the row doesn't exist, returns null.
*
* @template T of object
*
* @param int|string $n The index of the results to return, or column name.
* @param 'array'|'object'|class-string<T> $type The type of result object. 'array', 'object' or class name.
*
* @return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null)))
*/
public function getRow($n = 0, string $type = 'object')
{
// $n is a column name.
Expand Down Expand Up @@ -286,18 +233,6 @@ public function getRow($n = 0, string $type = 'object')
return $this->getCustomRowObject($n, $type);
}

/**
* Returns a row as a custom class instance.
*
* If the row doesn't exist, returns null.
*
* @template T of object
*
* @param int $n The index of the results to return.
* @param class-string<T> $className
*
* @return T|null
*/
public function getCustomRowObject(int $n, string $className)
{
if (! isset($this->customResultObject[$className])) {
Expand All @@ -315,13 +250,6 @@ public function getCustomRowObject(int $n, string $className)
return $this->customResultObject[$className][$this->currentRow] ?? null;
}

/**
* Returns a single row from the results as an array.
*
* If row doesn't exist, returns null.
*
* @return array|null
*/
public function getRowArray(int $n = 0)
{
$result = $this->getResultArray();
Expand All @@ -336,13 +264,6 @@ public function getRowArray(int $n = 0)
return $result[$this->currentRow] ?? null;
}

/**
* Returns a single row from the results as an object.
*
* If row doesn't exist, returns null.
*
* @return object|stdClass|null
*/
public function getRowObject(int $n = 0)
{
$result = $this->getResultObject();
Expand All @@ -357,14 +278,6 @@ public function getRowObject(int $n = 0)
return $result[$this->currentRow] ?? null;
}

/**
* Assigns an item into a particular column slot.
*
* @param array|string $key
* @param array|object|stdClass|null $value
*
* @return void
*/
public function setRow($key, $value = null)
{
// We cache the row data for subsequent uses
Expand All @@ -385,29 +298,20 @@ public function setRow($key, $value = null)
}
}

/**
* Returns the "first" row of the current results.
*/
public function getFirstRow(string $type = 'object')
{
$result = $this->getResult($type);

return ($result === []) ? null : $result[0];
}

/**
* Returns the "last" row of the current results.
*/
public function getLastRow(string $type = 'object')
{
$result = $this->getResult($type);

return ($result === []) ? null : $result[count($result) - 1];
}

/**
* Returns the "next" row of the current results.
*/
public function getNextRow(string $type = 'object')
{
$result = $this->getResult($type);
Expand All @@ -418,9 +322,6 @@ public function getNextRow(string $type = 'object')
return isset($result[$this->currentRow + 1]) ? $result[++$this->currentRow] : null;
}

/**
* Returns the "previous" row of the current results.
*/
public function getPreviousRow(string $type = 'object')
{
$result = $this->getResult($type);
Expand All @@ -435,11 +336,6 @@ public function getPreviousRow(string $type = 'object')
return $result[$this->currentRow] ?? null;
}

/**
* Returns an unbuffered row and move the pointer to the next row.
*
* @return array|object|null
*/
public function getUnbufferedRow(string $type = 'object')
{
if ($type === 'array') {
Expand Down Expand Up @@ -478,43 +374,12 @@ private function isValidResultId(): bool
return is_resource($this->resultID) || is_object($this->resultID);
}

/**
* Gets the number of fields in the result set.
*/
abstract public function getFieldCount(): int;

/**
* Generates an array of column names in the result set.
*/
abstract public function getFieldNames(): array;

/**
* Generates an array of objects representing field meta-data.
*/
abstract public function getFieldData(): array;

/**
* Frees the current result.
*
* @return void
*/
abstract public function freeResult();

/**
* Moves the internal pointer to the desired offset. This is called
* internally before fetching results to make sure the result set
* starts at zero.
*
* @return bool
*/
abstract public function dataSeek(int $n = 0);

/**
* Returns the result set as an array.
*
* Overridden by driver classes.
*
* @return array|false|null
* @return array<string, mixed>|false|null
*/
abstract protected function fetchAssoc();

Expand Down
2 changes: 1 addition & 1 deletion system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ protected function _indexData(string $table): array
$type = 'PRIMARY';
} elseif ($index['Index_type'] === 'FULLTEXT') {
$type = 'FULLTEXT';
} elseif ($index['Non_unique']) {
} elseif ((bool) $index['Non_unique']) {
$type = $index['Index_type'] === 'SPATIAL' ? 'SPATIAL' : 'INDEX';
} else {
$type = 'UNIQUE';
Expand Down
40 changes: 1 addition & 39 deletions system/Database/MySQLi/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@
*/
class Result extends BaseResult
{
/**
* Gets the number of fields in the result set.
*/
public function getFieldCount(): int
{
return $this->resultID->field_count;
}

/**
* Generates an array of column names in the result set.
*/
public function getFieldNames(): array
{
$fieldNames = [];
Expand All @@ -49,9 +43,6 @@ public function getFieldNames(): array
return $fieldNames;
}

/**
* Generates an array of objects representing field meta-data.
*/
public function getFieldData(): array
{
static $dataTypes = [
Expand Down Expand Up @@ -103,11 +94,6 @@ public function getFieldData(): array
return $retVal;
}

/**
* Frees the current result.
*
* @return void
*/
public function freeResult()
{
if (is_object($this->resultID)) {
Expand All @@ -116,38 +102,17 @@ public function freeResult()
}
}

/**
* Moves the internal pointer to the desired offset. This is called
* internally before fetching results to make sure the result set
* starts at zero.
*
* @return bool
*/
public function dataSeek(int $n = 0)
{
return $this->resultID->data_seek($n);
}

/**
* Returns the result set as an array.
*
* Overridden by driver classes.
*
* @return array|false|null
*/
protected function fetchAssoc()
{
return $this->resultID->fetch_assoc();
}

/**
* Returns the result set as an object.
*
* Overridden by child classes.
*
* @return Entity|false|object|stdClass
*/
protected function fetchObject(string $className = 'stdClass')
protected function fetchObject(string $className = stdClass::class)
{
if (is_subclass_of($className, Entity::class)) {
$data = $this->fetchAssoc();
Expand All @@ -158,9 +123,6 @@ protected function fetchObject(string $className = 'stdClass')
return $this->resultID->fetch_object($className);
}

/**
* Returns the number of rows in the resultID (i.e., mysqli_result object)
*/
public function getNumRows(): int
{
if (! is_int($this->numRows)) {
Expand Down
Loading
Loading