Merge pull request #19457 from kamil-tekiela/Dbi-named-params-and-unbuffered
Dbi named params and unbuffered param
This commit is contained in:
commit
51868a0a22
@ -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;
|
||||
@ -288,7 +267,7 @@ class DatabaseInterface implements DbalInterface
|
||||
// is called for tracking purposes but we want to display the correct number
|
||||
// of rows affected by the original query, not by the query generated for
|
||||
// tracking.
|
||||
return $this->query($sql, ConnectionType::ControlUser, self::QUERY_BUFFERED, false);
|
||||
return $this->query($sql, ConnectionType::ControlUser, cacheAffectedRows: false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,7 +284,7 @@ class DatabaseInterface implements DbalInterface
|
||||
// is called for tracking purposes but we want to display the correct number
|
||||
// of rows affected by the original query, not by the query generated for
|
||||
// tracking.
|
||||
return $this->tryQuery($sql, ConnectionType::ControlUser, self::QUERY_BUFFERED, false);
|
||||
return $this->tryQuery($sql, ConnectionType::ControlUser, cacheAffectedRows: false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1195,7 +1174,7 @@ class DatabaseInterface implements DbalInterface
|
||||
int|string $field = 0,
|
||||
ConnectionType $connectionType = ConnectionType::User,
|
||||
): string|false|null {
|
||||
$result = $this->tryQuery($query, $connectionType, self::QUERY_BUFFERED, false);
|
||||
$result = $this->tryQuery($query, $connectionType, cacheAffectedRows: false);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
@ -1224,7 +1203,7 @@ class DatabaseInterface implements DbalInterface
|
||||
string $type = DbalInterface::FETCH_ASSOC,
|
||||
ConnectionType $connectionType = ConnectionType::User,
|
||||
): array|null {
|
||||
$result = $this->tryQuery($query, $connectionType, self::QUERY_BUFFERED, false);
|
||||
$result = $this->tryQuery($query, $connectionType, cacheAffectedRows: false);
|
||||
if ($result === false) {
|
||||
return null;
|
||||
}
|
||||
@ -1315,7 +1294,7 @@ class DatabaseInterface implements DbalInterface
|
||||
): array {
|
||||
$resultRows = [];
|
||||
|
||||
$result = $this->tryQuery($query, $connectionType, self::QUERY_BUFFERED, false);
|
||||
$result = $this->tryQuery($query, $connectionType, cacheAffectedRows: false);
|
||||
|
||||
// return empty array if result is empty or false
|
||||
if ($result === false) {
|
||||
@ -1397,7 +1376,7 @@ class DatabaseInterface implements DbalInterface
|
||||
*/
|
||||
public function getWarnings(ConnectionType $connectionType = ConnectionType::User): array
|
||||
{
|
||||
$result = $this->tryQuery('SHOW WARNINGS', $connectionType, 0, false);
|
||||
$result = $this->tryQuery('SHOW WARNINGS', $connectionType, cacheAffectedRows: false);
|
||||
if ($result === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
],
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user