Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 3.8.x up into 4.0.x #6231

Merged
merged 5 commits into from
Nov 24, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,19 @@ jobs:
- "10.4" # Oldest version supported by DBAL, LTS (Jun 2024)
- "10.5" # LTS (Jun 2025)
- "10.6" # LTS (Jul 2026)
- "10.10" # STS (Nov 2023)
- "10.11" # LTS (Feb 2028)
- "11.0" # STS (Jun 2024)
- "11.1" # STS (Aug 2024)
- "11.2" # STS (Nov 2024)
extension:
- "mysqli"
- "pdo_mysql"
include:
- php-version: "8.2"
mariadb-version: "11.1"
mariadb-version: "11.2"
extension: "mysqli"
- php-version: "8.3"
mariadb-version: "11.1"
mariadb-version: "11.2"
extension: "pdo_mysql"

services:
Expand Down
32 changes: 32 additions & 0 deletions src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
use InvalidArgumentException;

use function array_combine;
use function array_keys;
Expand All @@ -29,9 +30,11 @@
use function array_unique;
use function array_values;
use function count;
use function explode;
use function implode;
use function sprintf;
use function str_replace;
use function strpos;
use function strtolower;
use function trim;

Expand Down Expand Up @@ -538,6 +541,35 @@
return $sql;
}

/** {@inheritDoc} */
public function getCreateIndexSQL(Index $index, string $table): string
{
$name = $index->getQuotedName($this);
$columns = $index->getColumns();

if (strpos($table, '.') !== false) {
[$schema, $table] = explode('.', $table);
$name = $schema . '.' . $name;
}

if (count($columns) === 0) {
throw new InvalidArgumentException(sprintf(
'Incomplete or invalid index definition %s on table %s',
$name,
$table,
));

Check warning on line 560 in src/Platforms/SQLitePlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/SQLitePlatform.php#L556-L560

Added lines #L556 - L560 were not covered by tests
}

if ($index->isPrimary()) {
return $this->getCreatePrimaryKeySQL($index, $table);

Check warning on line 564 in src/Platforms/SQLitePlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/SQLitePlatform.php#L564

Added line #L564 was not covered by tests
}

$query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table;
$query .= ' (' . implode(', ', $index->getQuotedColumns($this)) . ')' . $this->getPartialIndexSQL($index);

return $query;
}

/**
* {@inheritDoc}
*/
Expand Down
40 changes: 40 additions & 0 deletions tests/Functional/Platform/OtherSchemaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Platform;

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\DBAL\Types\Types;

class OtherSchemaTest extends FunctionalTestCase
{
public function testATableCanBeCreatedInAnotherSchema(): void
{
$databasePlatform = $this->connection->getDatabasePlatform();
if (! ($databasePlatform instanceof SQLitePlatform)) {
self::markTestSkipped('This test requires SQLite');
}

$this->connection->executeStatement("ATTACH DATABASE '/tmp/test_other_schema.sqlite' AS other");

$table = new Table('other.test_other_schema');
$table->addColumn('id', Types::INTEGER);
$table->addIndex(['id']);

$this->dropAndCreateTable($table);
$this->connection->insert('other.test_other_schema', ['id' => 1]);

self::assertEquals(1, $this->connection->fetchOne('SELECT COUNT(*) FROM other.test_other_schema'));
$dsnParser = new DsnParser();
$connection = DriverManager::getConnection(
$dsnParser->parse('sqlite3:////tmp/test_other_schema.sqlite'),
);
$onlineTable = $connection->createSchemaManager()->introspectTable('test_other_schema');
self::assertCount(1, $onlineTable->getIndexes());
}
}