Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,11 @@ public function getCacheSize(): int
* An internal wrapper to dbsafeString, used to process a complete array of parameters
* as used by prepared statements.
*
* @param array<array-key, BackedEnum|EscapeableParameterInterface|scalar|null> $params
* @param array<array-key, BackedEnum|EscapeableParameterInterface|Stringable|scalar|null> $params
* @param list<bool>|false $escapes An array of boolean for each param, used to block the escaping of html-special chars.
* If not passed, all params will be cleaned.
*
* @return list<scalar|null>
* @return list<scalar|Stringable|null>
*
* @see Db::dbsafeString($string, $htmlSpecialChars = true)
*/
Expand Down Expand Up @@ -1257,6 +1257,7 @@ private function dbsafeParams(array $params, array | false $escapes = []): array
$replace[$key] = $param;
}

/** @var list<scalar|Stringable|null> */
return array_values($replace);
}

Expand Down
30 changes: 22 additions & 8 deletions src/Driver/MysqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,31 @@ public function getPArray(string $query, array $params): Generator
throw new QueryException('Could not execute statement: ' . $this->getError(), $query, $params);
}

$result = $statement->get_result();

if ($result === false) {
return;
$meta = $statement->result_metadata();
if ($meta === false) {
throw new QueryException('Could not get result meta', $query, $params);
}

while ($row = $result->fetch_assoc()) {
yield $row;
}
$columnNames = array_column($meta->fetch_fields(), 'name');

$meta->free();

$statement->store_result();

$boundValues = array_fill(0, count($columnNames), null);

$result->free_result();
$refs = &$boundValues;

$statement->bind_result(...$refs);

while ($statement->fetch()) {
$values = [];
foreach ($boundValues as $value) {
$values[] = $value;
}

yield array_combine($columnNames, $values);
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/ConnectionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Artemeon\Database\Exception\ConnectionException;
use Artemeon\Database\Exception\QueryException;
use Artemeon\Database\Schema\DataType;
use Override;
use PHPUnit\Framework\TestCase;

abstract class ConnectionTestCase extends TestCase
Expand All @@ -27,7 +28,7 @@ abstract class ConnectionTestCase extends TestCase

protected const string TEST_TABLE_NAME = 'agp_test_table';

#[\Override]
#[Override]
protected function setUp(): void
{
parent::setUp();
Expand All @@ -36,7 +37,7 @@ protected function setUp(): void
$this->setupFixture();
}

#[\Override]
#[Override]
protected function tearDown(): void
{
parent::tearDown();
Expand Down
11 changes: 11 additions & 0 deletions tests/Driver/PostgresDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@
use Artemeon\Database\ConnectionParameters;
use Artemeon\Database\Driver\PostgresDriver;
use Mockery;
use Override;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;

/**
* @internal
*/
final class PostgresDriverTest extends TestCase
{
#[Override]
protected function setUp(): void
{
$dumpBin = new ExecutableFinder()->find('pg_dump');
if ($dumpBin === null) {
self::markTestSkipped('pg_dump not available');
}
}

public function testBuildsDatabaseSpecificSubstringExpression(): void
{
$postgresDriver = new PostgresDriver();
Expand Down
Loading