Skip to content

Commit

Permalink
Merge branch 'dbal_3_compat'
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 15, 2023
2 parents 8918019 + cdbec7d commit 5d4d431
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/Persistence/Sql/DbalDriverMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Query as DbalQuery;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
Expand All @@ -28,8 +28,8 @@ class DbalDriverMiddleware extends AbstractDriverMiddleware
{
protected function replaceDatabasePlatform(AbstractPlatform $platform): AbstractPlatform
{
if ($platform instanceof SqlitePlatform) {
$platform = new class() extends SqlitePlatform {
if ($platform instanceof SQLitePlatform) {
$platform = new class() extends SQLitePlatform {
use Sqlite\PlatformTrait;
};
} elseif ($platform instanceof PostgreSQLPlatform) {
Expand Down Expand Up @@ -64,7 +64,7 @@ public function createDatabasePlatformForVersion($version): AbstractPlatform
*/
public function getSchemaManager(DbalConnection $connection, AbstractPlatform $platform): AbstractSchemaManager
{
if ($platform instanceof SqlitePlatform) {
if ($platform instanceof SQLitePlatform) {
return new class($connection, $platform) extends SqliteSchemaManager { // @phpstan-ignore-line
use Sqlite\SchemaManagerTrait;
};
Expand Down
6 changes: 3 additions & 3 deletions src/Persistence/Sql/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Result as DbalResult;

Expand Down Expand Up @@ -287,9 +287,9 @@ protected function escapeStringLiteral(string $value): string
$sqlLeft = 'CAST(' . $sqlLeft . ' AS NVARCHAR(MAX))';
}

return ($platform instanceof SqlitePlatform ? '(' : 'CONCAT(')
return ($platform instanceof SQLitePlatform ? '(' : 'CONCAT(')
. $sqlLeft
. ($platform instanceof SqlitePlatform ? ' || ' : ', ')
. ($platform instanceof SQLitePlatform ? ' || ' : ', ')
. $buildConcatSqlFx($partsRight)
. ')';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
Expand Down Expand Up @@ -253,7 +253,7 @@ public function field(string $fieldName, array $options = []): self
}

if (in_array($type, ['string', 'text'], true)) {
if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
$column->setPlatformOption('collation', 'NOCASE');
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;

abstract class TestCase extends BaseTestCase
Expand Down Expand Up @@ -114,7 +114,7 @@ function ($matches) use ($platform) {
$sql
);

if ($platform instanceof SqlitePlatform && $convertedSql !== $sql) {
if ($platform instanceof SQLitePlatform && $convertedSql !== $sql) {
self::assertSame($sql, $convertedSql);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/ExpressionSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Atk4\Data\Model;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class ExpressionSqlTest extends TestCase
{
Expand All @@ -33,7 +33,7 @@ public function testBasic(): void
$i->addField('total_vat', ['type' => 'float']);
$i->addExpression('total_gross', ['expr' => '[total_net] + [total_vat]', 'type' => 'float']);

if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
self::assertSame(
'select `id`, `total_net`, `total_vat`, (`total_net` + `total_vat`) `total_gross` from `invoice`',
$i->action('select')->render()[0]
Expand All @@ -50,7 +50,7 @@ public function testBasic(): void

$i->addExpression('double_total_gross', ['expr' => '[total_gross] * 2', 'type' => 'float']);

if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
self::assertSame(
'select `id`, `total_net`, `total_vat`, (`total_net` + `total_vat`) `total_gross`, ((`total_net` + `total_vat`) * 2) `double_total_gross` from `invoice`',
$i->action('select')->render()[0]
Expand All @@ -77,7 +77,7 @@ public function testBasicCallback(): void
return '[total_net] + [total_vat]';
}, 'type' => 'float']);

if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
self::assertSame(
'select `id`, `total_net`, `total_vat`, (`total_net` + `total_vat`) `total_gross` from `invoice`',
$i->action('select')->render()[0]
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testQuery(): void
$i->addField('total_vat', ['type' => 'float']);
$i->addExpression('sum_net', ['expr' => $i->action('fx', ['sum', 'total_net']), ['type' => 'integer']]);

if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
self::assertSame(
'select `id`, `total_net`, `total_vat`, (select sum(`total_net`) from `invoice`) `sum_net` from `invoice`',
$i->action('select')->render()[0]
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testExpressions(): void
$m->addField('surname');
$m->addField('cached_name');

if ($this->getDatabasePlatform() instanceof SqlitePlatform || $this->getDatabasePlatform() instanceof OraclePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform || $this->getDatabasePlatform() instanceof OraclePlatform) {
$concatExpr = '[name] || \' \' || [surname]';
} else {
$concatExpr = 'CONCAT([name], \' \', [surname])';
Expand Down
8 changes: 4 additions & 4 deletions tests/ModelAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Atk4\Data\Model\Scope;
use Atk4\Data\Model\Scope\Condition;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class ModelAggregateTest extends TestCase
{
Expand Down Expand Up @@ -178,7 +178,7 @@ public function testGroupSelectCondition2(): void
'double',
'>',
// TODO Sqlite bind param does not work, expr needed, even if casted to float with DBAL type (comparison works only if casted to/bind as int)
$this->getDatabasePlatform() instanceof SqlitePlatform ? $aggregate->expr('10') : 10
$this->getDatabasePlatform() instanceof SQLitePlatform ? $aggregate->expr('10') : 10
);

self::assertSame([
Expand All @@ -201,7 +201,7 @@ public function testGroupSelectCondition3(): void
$aggregate->addCondition(
'double',
// TODO Sqlite bind param does not work, expr needed, even if casted to float with DBAL type (comparison works only if casted to/bind as int)
$this->getDatabasePlatform() instanceof SqlitePlatform ? $aggregate->expr('38') : 38
$this->getDatabasePlatform() instanceof SQLitePlatform ? $aggregate->expr('38') : 38
);

self::assertSame([
Expand Down Expand Up @@ -239,7 +239,7 @@ public function testGroupSelectScope(): void
self::fixAllNonAggregatedFieldsInGroupBy($aggregate);

// TODO Sqlite bind param does not work, expr needed, even if casted to float with DBAL type (comparison works only if casted to/bind as int)
$numExpr = $this->getDatabasePlatform() instanceof SqlitePlatform ? $aggregate->expr('4') : 4;
$numExpr = $this->getDatabasePlatform() instanceof SQLitePlatform ? $aggregate->expr('4') : 4;
$scope = Scope::createAnd(new Condition('client_id', 2), new Condition('amount', $numExpr));
$aggregate->addCondition($scope);

Expand Down
6 changes: 3 additions & 3 deletions tests/Persistence/Sql/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use Atk4\Data\Persistence;
use Atk4\Data\Persistence\Sql\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class DummyConnection extends Connection
{
public function getDatabasePlatform(): AbstractPlatform
{
return new class() extends SqlitePlatform {
return new class() extends SQLitePlatform {
public function getName()
{
return 'dummy';
Expand All @@ -27,7 +27,7 @@ class DummyConnection2 extends Connection
{
public function getDatabasePlatform(): AbstractPlatform
{
return new class() extends SqlitePlatform {
return new class() extends SQLitePlatform {
public function getName()
{
return 'dummy2';
Expand Down
4 changes: 2 additions & 2 deletions tests/RandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class Model_Rate extends Model
{
Expand Down Expand Up @@ -508,7 +508,7 @@ public function testNoWriteActionDelete(): void

public function testTableWithSchema(): void
{
if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
$userSchema = 'db1';
$docSchema = 'db2';
$runWithDb = false;
Expand Down
4 changes: 2 additions & 2 deletions tests/Schema/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Atk4\Data\Model;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class TestCaseTest extends TestCase
{
Expand Down Expand Up @@ -37,7 +37,7 @@ public function testLogQuery(): void
ob_end_clean();
}

if (!$this->getDatabasePlatform() instanceof SqlitePlatform && !$this->getDatabasePlatform() instanceof MySQLPlatform) {
if (!$this->getDatabasePlatform() instanceof SQLitePlatform && !$this->getDatabasePlatform() instanceof MySQLPlatform) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Atk4\Data\Model\Scope\Condition;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class SCountry extends Model
{
Expand Down Expand Up @@ -184,7 +184,7 @@ public function testConditionToWords(): void
$condition = new Condition('country_id', 2);
self::assertSame('Country ID is equal to 2 (\'Latvia\')', $condition->toWords($user));

if ($this->getDatabasePlatform() instanceof SqlitePlatform || $this->getDatabasePlatform() instanceof MySQLPlatform) {
if ($this->getDatabasePlatform() instanceof SQLitePlatform || $this->getDatabasePlatform() instanceof MySQLPlatform) {
$condition = new Condition('name', $user->expr('[surname]'));
self::assertSame('Name is equal to expression \'`surname`\'', $condition->toWords($user));
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public function testConditionOnReferencedRecords(): void
$user->addCondition('Tickets/user/country_id/Users/#', '>', 1);
$user->addCondition('Tickets/user/country_id/Users/#', '>=', 2);
$user->addCondition('Tickets/user/country_id/Users/country_id/Users/#', '>', 1);
if (!$this->getDatabasePlatform() instanceof SqlitePlatform) {
if (!$this->getDatabasePlatform() instanceof SQLitePlatform) {
// not supported because of limitation/issue in Sqlite, the generated query fails
// with error: "parser stack overflow"
$user->addCondition('Tickets/user/country_id/Users/country_id/Users/name', '!=', null); // should be always true
Expand Down
4 changes: 2 additions & 2 deletions tests/TypecastingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Atk4\Data\Model;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;

class TypecastingTest extends TestCase
{
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testType(): void
$m->load(2)->set('float', 8.202343767574732)->save();
// pdo_sqlite in truncating float, see https://github.com/php/php-src/issues/8510
// fixed since PHP 8.1, but if converted in SQL to string explicitly, the result is still rounded to 15 significant digits
if (!$this->getDatabasePlatform() instanceof SqlitePlatform || \PHP_VERSION_ID >= 80100) {
if (!$this->getDatabasePlatform() instanceof SQLitePlatform || \PHP_VERSION_ID >= 80100) {
self::assertSame(8.202343767574732, $m->load(2)->get('float'));
}
}
Expand Down

0 comments on commit 5d4d431

Please sign in to comment.