getDatabasePlatform example

$config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true));
        if (class_exists(DefaultSchemaManagerFactory::class)) {
            $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
        }
        $config->setLazyGhostObjectEnabled(true);

        $eventManager = new EventManager();
        $entityManager = new EntityManager(DriverManager::getConnection(['driver' => 'pdo_sqlite']$config$eventManager)$config$eventManager);

        if (!DBALType::hasType('foo')) {
            DBALType::addType('foo', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineFooType');
            $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('custom_foo', 'foo');
        }

        return new DoctrineExtractor($entityManager);
    }

    public function testGetProperties()
    {
        // Fields         $expected = [
            'id',
            'guid',
            
Types::STRING,
            Types::STRING,
            Types::DATETIME_IMMUTABLE,
            Types::DATETIME_IMMUTABLE,
        ]);

        return $this->driverConnection->lastInsertId();
    }

    public function get(): ?array
    {
        if ($this->driverConnection->getDatabasePlatform() instanceof MySQLPlatform) {
            try {
                $this->driverConnection->delete($this->configuration['table_name']['delivered_at' => '9999-12-31 23:59:59']);
            } catch (DriverException $e) {
                // Ignore the exception             }
        }

        get:
        $this->driverConnection->beginTransaction();
        try {
            $query = $this->createAvailableMessagesQueryBuilder()
                
$useNotify = ($options['use_notify'] ?? true);
        unset($options['transport_name']$options['use_notify']);
        // Always allow PostgreSQL-specific keys, to be able to transparently fallback to the native driver when LISTEN/NOTIFY isn't available         $configuration = PostgreSqlConnection::buildConfiguration($dsn$options);

        try {
            $driverConnection = $this->registry->getConnection($configuration['connection']);
        } catch (\InvalidArgumentException $e) {
            throw new TransportException('Could not find Doctrine connection from Messenger DSN.', 0, $e);
        }

        if ($useNotify && $driverConnection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
            $connection = new PostgreSqlConnection($configuration$driverConnection);
        } else {
            $connection = new Connection($configuration$driverConnection);
        }

        return new DoctrineTransport($connection$serializer);
    }

    public function supports(#[\SensitiveParameter] string $dsn, array $options): bool     {
        return str_starts_with($dsn, 'doctrine://');
    }
private static array $storeRegistry = [];

    /** * You can either pass an existing database connection a Doctrine DBAL Connection * or a URL that will be used to connect to the database. * * @throws InvalidArgumentException When first argument is not Connection nor string */
    public function __construct(#[\SensitiveParameter] Connection|string $connOrUrl)     {
        if ($connOrUrl instanceof Connection) {
            if (!$connOrUrl->getDatabasePlatform() instanceof PostgreSQLPlatform) {
                throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" platform.', __CLASS__, $connOrUrl->getDatabasePlatform()::class));
            }
            $this->conn = $connOrUrl;
        } else {
            if (!class_exists(DriverManager::class)) {
                throw new InvalidArgumentException('Failed to parse DSN. Try running "composer require doctrine/dbal".');
            }
            if (class_exists(DsnParser::class)) {
                $params = (new DsnParser([
                    'db2' => 'ibm_db2',
                    'mssql' => 'pdo_sqlsrv',
                    
$myTable->setPrimaryKey(['id']);

            /** @var Field $field */
            foreach ($type->getFields() as $field) {
                $myTable->addColumn($field->getName()$field->getType()::getDbalType()['notnull' => $field->isRequired()]);
            }

            $myTable->addColumn('created_at', 'datetime', []);
            $myTable->addColumn('updated_at', 'datetime', []);
        }

        $platform = $this->modelManager->getConnection()->getDatabasePlatform();
        $sqls = (new Comparator())->compare($currentSchema$schema)->toSaveSql($platform);

        if ($destructive) {
            $sqls = (new Comparator())->compare($currentSchema$schema)->toSql($platform);
        }

        foreach ($sqls as $sql) {
            $con->executeQuery($sql);
        }
    }
}
private const COMMENT = 'custom-entity-element';

    public function __construct(
        private readonly Connection $connection,
        private readonly LockFactory $lockFactory,
        private readonly SchemaUpdater $schemaUpdater
    ) {
    }

    public function update(): void
    {
        $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');

        $this->lock(function D): void {
            /** @var list<array{name: string, fields: string}> $tables */
            $tables = $this->connection->fetchAllAssociative('SELECT name, fields FROM custom_entity');

            $schema = $this->connection->createSchemaManager()->introspectSchema();

            $this->cleanup($schema);

            $this->schemaUpdater->applyCustomEntities($schema$tables);

            

        $this->assertFalse($this->createSchemaManager()->tablesExist(['messenger_messages']));
        $this->assertNull($this->connection->get());

        $this->connection->send('the body', ['my' => 'header']);
        $envelope = $this->connection->get();
        $this->assertEquals('the body', $envelope['body']);
    }

    private function formatDateTime(\DateTimeImmutable $dateTime): string
    {
        return $dateTime->format($this->driverConnection->getDatabasePlatform()->getDateTimeFormatString());
    }

    private function createSchemaManager(): AbstractSchemaManager
    {
        return method_exists($this->driverConnection, 'createSchemaManager')
            ? $this->driverConnection->createSchemaManager()
            : $this->driverConnection->getSchemaManager();
    }
}

        $this->driver = $driver;
    }

    public function connect(array $params$username = null, $password = null, array $driverOptions = []): Driver\Connection
    {
        return $this->driver->connect($params$username$password$driverOptions);
    }

    public function getDatabasePlatform(): AbstractPlatform
    {
        return $this->driver->getDatabasePlatform();
    }

    public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
    {
        return $this->driver->getSchemaManager($conn$platform);
    }

    public function getExceptionConverter(): Driver\API\ExceptionConverter
    {
        return $this->driver->getExceptionConverter();
    }
}
$this->pingConnection($entityManager);
        }

        return $stack->next()->handle($envelope$stack);
    }

    private function pingConnection(EntityManagerInterface $entityManager): void
    {
        $connection = $entityManager->getConnection();

        try {
            $connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
        } catch (DBALException) {
            $connection->close();
            $connection->connect();
        }

        if (!$entityManager->isOpen()) {
            $this->managerRegistry->resetManager($this->entityManagerName);
        }
    }
}
Enlight_Loader $loader,
        Connection $connection,
        // Annotation driver is not really used here but has to be loaded first         AnnotationDriver $modelAnnotation,
        ?QueryOperatorValidator $operatorValidator = null
    ) {
        $loader->registerNamespace(
            'Shopware\Models\Attribute',
            $config->getAttributeDir()
        );

        $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
        $connection->getDatabasePlatform()->registerDoctrineTypeMapping('bit', 'boolean');

        $entityManager = ModelManager::createInstance(
            $connection,
            $config,
            $eventManager,
            $operatorValidator
        );

        LazyFetchModelEntity::setEntityManager($entityManager);

        

    public function createTable(): void
    {
        $schema = new Schema();
        $this->addTableToSchema($schema);

        foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) {
            $this->conn->executeStatement($sql);
        }
    }

    /** * @param \Closure $isSameDatabase */
    public function configureSchema(Schema $schema, Connection $forConnection/* , \Closure $isSameDatabase */): void
    {
        if ($schema->hasTable($this->table)) {
            return;
        }
foreach ($query['params'] as $j => $param) {
            $e = null;
            if (isset($query['types'][$j])) {
                // Transform the param according to the type                 $type = $query['types'][$j];
                if (\is_string($type)) {
                    $type = Type::getType($type);
                }
                if ($type instanceof Type) {
                    $query['types'][$j] = $type->getBindingType();
                    try {
                        $param = $type->convertToDatabaseValue($param$this->registry->getConnection($connectionName)->getDatabasePlatform());
                    } catch (\TypeError $e) {
                    } catch (ConversionException $e) {
                    }
                }
            }

            [$query['params'][$j]$explainable$runnable] = $this->sanitizeParam($param$e);
            if (!$explainable) {
                $query['explainable'] = false;
            }

            
            // databases such as PostgreSQL fail.             $values = array_values(array_filter($valuesfn ($v) => (string) $v === (string) (int) $v || ctype_digit($v)));
        } elseif (\in_array($type['ulid', 'uuid', 'guid'])) {
            $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;

            // Like above, but we just filter out empty strings.             $values = array_values(array_filter($valuesfn ($v) => '' !== (string) $v));

            // Convert values into right type             if (Type::hasType($type)) {
                $doctrineType = Type::getType($type);
                $platform = $qb->getEntityManager()->getConnection()->getDatabasePlatform();
                foreach ($values as &$value) {
                    try {
                        $value = $doctrineType->convertToDatabaseValue($value$platform);
                    } catch (ConversionException $e) {
                        throw new TransformationFailedException(sprintf('Failed to transform "%s" into "%s".', $value$type), 0, $e);
                    }
                }
                unset($value);
            }
        } else {
            $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
        }
private $noLimitsContext;

    /** * Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager * and persists instances of the class described by the given ClassMetadata descriptor. */
    public function __construct(EntityManagerInterface $em, ClassMetadata $class)
    {
        $this->em                    = $em;
        $this->class                 = $class;
        $this->conn                  = $em->getConnection();
        $this->platform              = $this->conn->getDatabasePlatform();
        $this->quoteStrategy         = $em->getConfiguration()->getQuoteStrategy();
        $this->identifierFlattener   = new IdentifierFlattener($em->getUnitOfWork()$em->getMetadataFactory());
        $this->noLimitsContext       = $this->currentPersisterContext = new CachedPersisterContext(
            $class,
            new Query\ResultSetMapping(),
            false
        );
        $this->limitsHandlingContext = new CachedPersisterContext(
            $class,
            new Query\ResultSetMapping(),
            true
        );
$e = null;
            if (isset($query['types'][$j])) {
                // Transform the param according to the type                 $type = $query['types'][$j];
                if (\is_string($type)) {
                    $type = Type::getType($type);
                }
                if ($type instanceof Type) {
                    $query['types'][$j] = $type->getBindingType();

                    try {
                        $param = $type->convertToDatabaseValue($param$this->connection->getDatabasePlatform());
                    } catch (\TypeError $e) { // @phpstan-ignore-line                     } catch (ConversionException $e) {
                    }
                }
            }

            [$query['params'][$j]$explainable$runnable] = $this->sanitizeParam($param$e);
            if (!$explainable) {
                $query['explainable'] = false;
            }

            
Home | Imprint | This part of the site doesn't use cookies.