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
35 changes: 2 additions & 33 deletions system/Database/BasePreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ public function __construct(BaseConnection $db)
$this->db = $db;
}

/**
* Prepares the query against the database, and saves the connection
* info necessary to execute the query later.
*
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @return $this
*/
public function prepare(string $sql, array $options = [], string $queryClass = Query::class)
{
// We only support positional placeholders (?), so convert
Expand All @@ -101,18 +92,13 @@ public function prepare(string $sql, array $options = [], string $queryClass = Q
}

/**
* The database-dependent portion of the prepare statement.
* @param array<array-key, mixed> $options Passed to the connection's prepare statement. Only the SQLSRV driver uses it.
*
* @return $this
*/
abstract public function _prepare(string $sql, array $options = []);

/**
* Takes a new set of data and runs it against the currently
* prepared query. Upon success, will return a Results object.
*
* @return bool|ResultInterface<TConnection, TResult>
*
* @throws DatabaseException
*/
public function execute(...$data)
Expand Down Expand Up @@ -186,7 +172,7 @@ public function execute(...$data)
}

/**
* The database dependant version of the execute method.
* @param list<mixed> $data
*/
abstract public function _execute(array $data): bool;

Expand All @@ -197,11 +183,6 @@ abstract public function _execute(array $data): bool;
*/
abstract public function _getResult();

/**
* Explicitly closes the prepared statement.
*
* @throws BadMethodCallException
*/
public function close(): bool
{
if (! isset($this->statement)) {
Expand All @@ -215,14 +196,8 @@ public function close(): bool
}
}

/**
* The database-dependent version of the close method.
*/
abstract protected function _close(): bool;

/**
* Returns the SQL that has been prepared.
*/
public function getQueryString(): string
{
if (! $this->query instanceof QueryInterface) {
Expand All @@ -240,17 +215,11 @@ public function hasError(): bool
return $this->errorString !== '';
}

/**
* Returns the error code created while executing this statement.
*/
public function getErrorCode(): int
{
return $this->errorCode;
}

/**
* Returns the error message created while executing this statement.
*/
public function getErrorMessage(): string
{
return $this->errorString;
Expand Down
20 changes: 10 additions & 10 deletions system/Database/BaseUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
use CodeIgniter\Database\Exceptions\DatabaseException;

/**
* Class BaseUtils
* @template TDb of BaseConnection
*/
abstract class BaseUtils
{
/**
* Database object
*
* @var object
* @var TDb
*/
protected $db;

Expand All @@ -49,7 +47,7 @@ abstract class BaseUtils
protected $repairTable = false;

/**
* Class constructor
* @param TDb $db
*/
public function __construct(ConnectionInterface $db)
{
Expand All @@ -59,7 +57,7 @@ public function __construct(ConnectionInterface $db)
/**
* List databases
*
* @return array|bool
* @return bool|list<mixed>
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -229,6 +227,8 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st

/**
* Generate XML data from a query result object
*
* @param array<string, string> $params
*/
public function getXMLFromResult(ResultInterface $query, array $params = []): string
{
Expand Down Expand Up @@ -264,9 +264,9 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st
/**
* Database Backup
*
* @param array|string $params
* @param array<string, mixed>|string $params
*
* @return false|never|string
* @return false|string
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -320,9 +320,9 @@ public function backup($params = [])
}

/**
* Platform dependent version of the backup function.
* @param array<string, mixed>|null $prefs
*
* @return false|never|string
* @return false|string
*/
abstract public function _backup(?array $prefs = null);
}
19 changes: 0 additions & 19 deletions system/Database/MySQLi/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
*/
class PreparedQuery extends BasePreparedQuery
{
/**
* Prepares the query against the database, and saves the connection
* info necessary to execute the query later.
*
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
*/
public function _prepare(string $sql, array $options = []): PreparedQuery
{
// Mysqli driver doesn't like statements
Expand All @@ -56,10 +46,6 @@ public function _prepare(string $sql, array $options = []): PreparedQuery
return $this;
}

/**
* Takes a new set of data and runs it against the currently
* prepared query. Upon success, will return a Results object.
*/
public function _execute(array $data): bool
{
if (! isset($this->statement)) {
Expand Down Expand Up @@ -104,18 +90,13 @@ public function _execute(array $data): bool
}

/**
* Returns the result object for the prepared query or false on failure.
*
* @return false|mysqli_result
*/
public function _getResult()
{
return $this->statement->get_result();
}

/**
* Deallocate prepared statements.
*/
protected function _close(): bool
{
return $this->statement->close();
Expand Down
12 changes: 4 additions & 8 deletions system/Database/MySQLi/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@

/**
* Utils for MySQLi
*
* @extends BaseUtils<Connection>
*/
class Utils extends BaseUtils
{
/**
* List databases statement
*
* @var string
* @var bool|string
*/
protected $listDatabases = 'SHOW DATABASES';

/**
* OPTIMIZE TABLE statement
*
* @var string
* @var bool|string
*/
protected $optimizeTable = 'OPTIMIZE TABLE %s';

/**
* Platform dependent version of the backup function.
*
* @return never
*/
public function _backup(?array $prefs = null)
Expand Down
19 changes: 0 additions & 19 deletions system/Database/OCI8/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ class PreparedQuery extends BasePreparedQuery
*/
private ?string $lastInsertTableName = null;

/**
* Prepares the query against the database, and saves the connection
* info necessary to execute the query later.
*
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param array $options Passed to the connection's prepare statement.
* Unused in the OCI8 driver.
*/
public function _prepare(string $sql, array $options = []): PreparedQuery
{
if (! $this->statement = oci_parse($this->db->connID, $this->parameterize($sql))) {
Expand All @@ -57,10 +47,6 @@ public function _prepare(string $sql, array $options = []): PreparedQuery
return $this;
}

/**
* Takes a new set of data and runs it against the currently
* prepared query. Upon success, will return a Results object.
*/
public function _execute(array $data): bool
{
if (! isset($this->statement)) {
Expand Down Expand Up @@ -93,18 +79,13 @@ public function _execute(array $data): bool
}

/**
* Returns the statement resource for the prepared query or false when preparing failed.
*
* @return resource|null
*/
public function _getResult()
{
return $this->statement;
}

/**
* Deallocate prepared statements.
*/
protected function _close(): bool
{
return oci_free_statement($this->statement);
Expand Down
8 changes: 3 additions & 5 deletions system/Database/OCI8/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

/**
* Utils for OCI8
*
* @extends BaseUtils<Connection>
*/
class Utils extends BaseUtils
{
/**
* List databases statement
*
* @var string
* @var bool|string
*/
protected $listDatabases = 'SELECT TABLESPACE_NAME FROM USER_TABLESPACES';

/**
* Platform dependent version of the backup function.
*
* @return never
*/
public function _backup(?array $prefs = null)
Expand Down
18 changes: 0 additions & 18 deletions system/Database/Postgre/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ class PreparedQuery extends BasePreparedQuery
protected $result;

/**
* Prepares the query against the database, and saves the connection
* info necessary to execute the query later.
*
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
*
* @throws Exception
*/
public function _prepare(string $sql, array $options = []): PreparedQuery
Expand All @@ -77,10 +68,6 @@ public function _prepare(string $sql, array $options = []): PreparedQuery
return $this;
}

/**
* Takes a new set of data and runs it against the currently
* prepared query. Upon success, will return a Results object.
*/
public function _execute(array $data): bool
{
if (! isset($this->statement)) {
Expand All @@ -99,18 +86,13 @@ public function _execute(array $data): bool
}

/**
* Returns the result object for the prepared query or false on failure.
*
* @return PgSqlResult|null
*/
public function _getResult()
{
return $this->result;
}

/**
* Deallocate prepared statements.
*/
protected function _close(): bool
{
return pg_query($this->db->connID, 'DEALLOCATE "' . $this->db->escapeIdentifiers($this->name) . '"') !== false;
Expand Down
12 changes: 4 additions & 8 deletions system/Database/Postgre/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@

/**
* Utils for Postgre
*
* @extends BaseUtils<Connection>
*/
class Utils extends BaseUtils
{
/**
* List databases statement
*
* @var string
* @var bool|string
*/
protected $listDatabases = 'SELECT datname FROM pg_database';

/**
* OPTIMIZE TABLE statement
*
* @var string
* @var bool|string
*/
protected $optimizeTable = 'REINDEX TABLE %s';

/**
* Platform dependent version of the backup function.
*
* @return never
*/
public function _backup(?array $prefs = null)
Expand Down
Loading
Loading