Change $options into $unbuffered

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2024-12-17 22:38:56 +00:00
parent c9a3c06fe1
commit dd05ed6e45
8 changed files with 23 additions and 67 deletions

View File

@ -81,15 +81,10 @@ class DatabaseInterface implements DbalInterface
{
public static self|null $instance = null;
/**
* Force STORE_RESULT method, ignored by classic MySQL.
*/
public const QUERY_BUFFERED = 0;
/**
* Do not read all rows immediately.
*/
public const QUERY_UNBUFFERED = 2;
public const QUERY_UNBUFFERED = true;
/**
* Get session variable.
@ -165,20 +160,13 @@ class DatabaseInterface implements DbalInterface
return self::$instance;
}
/**
* runs a query
*
* @param string $query SQL query to execute
* @param int $options optional query options
* @param bool $cacheAffectedRows whether to cache affected rows
*/
public function query(
string $query,
ConnectionType $connectionType = ConnectionType::User,
int $options = self::QUERY_BUFFERED,
bool $unbuffered = false,
bool $cacheAffectedRows = true,
): ResultInterface {
$result = $this->tryQuery($query, $connectionType, $options, $cacheAffectedRows);
$result = $this->tryQuery($query, $connectionType, $unbuffered, $cacheAffectedRows);
if (! $result) {
Generator::mysqlDie($this->getError($connectionType), $query);
@ -192,19 +180,10 @@ class DatabaseInterface implements DbalInterface
return $this->cache;
}
/**
* runs a query and returns the result
*
* @param string $query query to run
* @param int $options if DatabaseInterface::QUERY_UNBUFFERED
* is provided, it will instruct the extension
* to use unbuffered mode
* @param bool $cacheAffectedRows whether to cache affected row
*/
public function tryQuery(
string $query,
ConnectionType $connectionType = ConnectionType::User,
int $options = self::QUERY_BUFFERED,
bool $unbuffered = false,
bool $cacheAffectedRows = true,
): ResultInterface|false {
if (! isset($this->connections[$connectionType->value])) {
@ -213,7 +192,7 @@ class DatabaseInterface implements DbalInterface
$time = microtime(true);
$result = $this->extension->realQuery($query, $this->connections[$connectionType->value], $options);
$result = $this->extension->realQuery($query, $this->connections[$connectionType->value], $unbuffered);
if ($connectionType === ConnectionType::User) {
$this->lastQueryExecutionTime = microtime(true) - $time;

View File

@ -21,32 +21,24 @@ interface DbalInterface
public const FETCH_ASSOC = 'ASSOC';
/**
* runs a query
*
* @param string $query SQL query to execute
* @param int $options optional query options
* @param bool $cacheAffectedRows whether to cache affected rows
* Executes a query and returns the result
*/
public function query(
string $query,
ConnectionType $connectionType = ConnectionType::User,
int $options = 0,
bool $unbuffered = false,
bool $cacheAffectedRows = true,
): ResultInterface;
/**
* runs a query and returns the result
*
* @param string $query query to run
* @param int $options query options
* @param bool $cacheAffectedRows whether to cache affected row
* Executes a query and returns the result or false on error
*/
public function tryQuery(
string $query,
ConnectionType $connectionType = ConnectionType::User,
int $options = 0,
bool $unbuffered = false,
bool $cacheAffectedRows = true,
): mixed;
): ResultInterface|false;
/**
* Send multiple SQL queries to the database server and execute the first one

View File

@ -32,12 +32,9 @@ interface DbiExtension
/**
* runs a query and returns the result
*
* @param string $query query to execute
* @param int $options query options
*
* @return ResultInterface|false result
*/
public function realQuery(string $query, Connection $connection, int $options): ResultInterface|false;
public function realQuery(string $query, Connection $connection, bool $unbuffered = false): ResultInterface|false;
/**
* Run the multi query and output the results

View File

@ -11,7 +11,6 @@ use mysqli;
use mysqli_sql_exception;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\Settings\Server;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Query\Utilities;
@ -154,21 +153,13 @@ class DbiMysqli implements DbiExtension
/**
* runs a query and returns the result
*
* @param string $query query to execute
* @param int $options query options
*/
public function realQuery(string $query, Connection $connection, int $options): MysqliResult|false
public function realQuery(string $query, Connection $connection, bool $unbuffered = false): MysqliResult|false
{
$method = MYSQLI_STORE_RESULT;
if ($options === ($options | DatabaseInterface::QUERY_UNBUFFERED)) {
$method = MYSQLI_USE_RESULT;
}
/** @var mysqli $mysqli */
$mysqli = $connection->connection;
$result = $mysqli->query($query, $method);
$result = $mysqli->query($query, $unbuffered ? MYSQLI_USE_RESULT : MYSQLI_STORE_RESULT);
if ($result === false) {
return false;
}

View File

@ -77,7 +77,7 @@ class DbiMysqliTest extends AbstractTestCase
->with(self::equalTo($query))
->willReturn($mysqliResult);
self::assertInstanceOf(MysqliResult::class, $this->object->realQuery($query, new Connection($mysqli), 0));
self::assertInstanceOf(MysqliResult::class, $this->object->realQuery($query, new Connection($mysqli)));
}
/**

View File

@ -168,11 +168,8 @@ class DbiDummy implements DbiExtension
/**
* runs a query and returns the result
*
* @param string $query query to run
* @param int $options query options
*/
public function realQuery(string $query, Connection $connection, int $options): DummyResult|false
public function realQuery(string $query, Connection $connection, bool $unbuffered = false): DummyResult|false
{
$query = trim((string) preg_replace('/ */', ' ', str_replace("\n", ' ', $query)));
$found = $this->findFifoQuery($query) ?? $this->findDummyQuery($query);

View File

@ -1399,29 +1399,29 @@ class TableTest extends AbstractTestCase
[
'SHOW CREATE TABLE `aa`.`ad`',
ConnectionType::User,
DatabaseInterface::QUERY_BUFFERED,
false,
true,
$resultStub,
],
[
'SHOW TABLE STATUS FROM `aa` WHERE Name = \'ad\'',
ConnectionType::User,
DatabaseInterface::QUERY_BUFFERED,
false,
true,
$resultStub,
],
['USE `aa`', ConnectionType::User, DatabaseInterface::QUERY_BUFFERED, true, $resultStub],
['USE `aa`', ConnectionType::User, false, true, $resultStub],
[
'RENAME TABLE `PMA`.`PMA_BookMark` TO `PMA`.`PMA_.BookMark`;',
ConnectionType::User,
DatabaseInterface::QUERY_BUFFERED,
false,
true,
false,
],
[
'RENAME TABLE `aa`.`ad` TO `bb`.`ad`;',
ConnectionType::User,
DatabaseInterface::QUERY_BUFFERED,
false,
true,
false,
],

View File

@ -184,9 +184,9 @@ class TrackerTest extends AbstractTestCase
$useStatement = 'USE `pma_test`';
$showCreateTableQuery = 'SHOW CREATE TABLE `pma_test`.`pma_tbl`';
$dbi->expects(self::exactly(3))->method('tryQuery')->willReturnMap([
[$showTableStatusQuery, ConnectionType::User, DatabaseInterface::QUERY_BUFFERED, true, $resultStub],
[$useStatement, ConnectionType::User, DatabaseInterface::QUERY_BUFFERED, true, $resultStub],
[$showCreateTableQuery, ConnectionType::User, DatabaseInterface::QUERY_BUFFERED, true, $resultStub],
[$showTableStatusQuery, ConnectionType::User, false, true, $resultStub],
[$useStatement, ConnectionType::User, false, true, $resultStub],
[$showCreateTableQuery, ConnectionType::User, false, true, $resultStub],
]);
$dbi->expects(self::any())->method('query')