diff --git a/src/DbRow.php b/src/DbRow.php index 53369bea..ad6e9029 100644 --- a/src/DbRow.php +++ b/src/DbRow.php @@ -198,7 +198,7 @@ public function _dbLoadIfNotLoaded(): void $sql = 'SELECT * FROM '.$connection->quoteIdentifier($this->dbTableName).' WHERE '.$sql_where; $result = $connection->executeQuery($sql, $parameters); - $row = $result->fetch(\PDO::FETCH_ASSOC); + $row = $result->fetchAssociative(); if ($row === false) { throw new TDBMException("Could not retrieve object from table \"$this->dbTableName\" using filter \".$sql_where.\" with data \"".var_export($parameters, true)."\"."); diff --git a/src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php b/src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php index b16beff9..2df404bb 100644 --- a/src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php +++ b/src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php @@ -232,7 +232,9 @@ private function formatSelect(array $baseSelect): array } $table = $this->schema->getTable($tableName); - $pkColumns = $table->getPrimaryKeyColumns(); + $primaryKey = $table->getPrimaryKey(); + assert($primaryKey !== null, 'TDBM Only works on tables with primary keys'); + $pkColumns = $primaryKey->getUnquotedColumns(); foreach ($table->getColumns() as $column) { $columnName = $column->getName(); $alias = AbstractQueryFactory::getColumnAlias($tableName, $columnName); @@ -252,7 +254,7 @@ private function formatSelect(array $baseSelect): array ] ]; $formattedSelect[] = $astColumn; - if (array_key_exists($columnName, $pkColumns)) { + if (in_array($columnName, $pkColumns, true)) { $formattedCountSelect[] = $astColumn; } $columnDescriptors[$alias] = [ diff --git a/tests/Performance/ManyToOneBench.php b/tests/Performance/ManyToOneBench.php index ef4ec138..779d3f19 100644 --- a/tests/Performance/ManyToOneBench.php +++ b/tests/Performance/ManyToOneBench.php @@ -3,7 +3,6 @@ namespace TheCodingMachine\TDBM\Performance; use Doctrine\Common\Cache\ArrayCache; -use Doctrine\Common\Cache\VoidCache; use Doctrine\DBAL\Connection; use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer; use PhpBench\Benchmark\Metadata\Annotations\Iterations; @@ -11,7 +10,6 @@ use TheCodingMachine\TDBM\Configuration; use TheCodingMachine\TDBM\ConfigurationInterface; use TheCodingMachine\TDBM\ConnectionFactory; -use TheCodingMachine\TDBM\DummyGeneratorListener; use TheCodingMachine\TDBM\SchemaLockFileDumper; use TheCodingMachine\TDBM\TDBMAbstractServiceTest; use TheCodingMachine\TDBM\TDBMSchemaAnalyzer; @@ -70,7 +68,7 @@ private static function initSchema(Connection $connection): void $sqlStmts = $toSchema->getMigrateFromSql($fromSchema, $connection->getDatabasePlatform()); foreach ($sqlStmts as $sqlStmt) { - $connection->exec($sqlStmt); + $connection->executeStatement($sqlStmt); } for ($i = 1; $i < 200; $i++) { diff --git a/tests/TDBMAbstractServiceTest.php b/tests/TDBMAbstractServiceTest.php index c18b015b..e1659958 100644 --- a/tests/TDBMAbstractServiceTest.php +++ b/tests/TDBMAbstractServiceTest.php @@ -444,12 +444,12 @@ private static function initSchema(Connection $connection): void foreach ($sqlStmts as $sqlStmt) { //echo $sqlStmt."\n"; - $connection->exec($sqlStmt); + $connection->executeStatement($sqlStmt); } // Let's generate computed columns if ($connection->getDatabasePlatform() instanceof MySqlPlatform && !self::isMariaDb($connection)) { - $connection->exec('CREATE TABLE `players` ( + $connection->executeStatement('CREATE TABLE `players` ( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, `player_and_games` JSON NOT NULL, `names_virtual` VARCHAR(20) GENERATED ALWAYS AS (`player_and_games` ->> \'$.name\') NOT NULL COMMENT \'@ReadOnly\', diff --git a/tests/Utils/BeanDescriptorTest.php b/tests/Utils/BeanDescriptorTest.php index 3229f056..9ac3a222 100644 --- a/tests/Utils/BeanDescriptorTest.php +++ b/tests/Utils/BeanDescriptorTest.php @@ -22,11 +22,9 @@ namespace TheCodingMachine\TDBM\Utils; -use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\VoidCache; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer; use TheCodingMachine\TDBM\Configuration;