From 494bfc89661c578a987f99db5ca42fc23c102a3f Mon Sep 17 00:00:00 2001 From: Juozas Kaziukenas Date: Wed, 9 Jun 2010 15:40:54 +0100 Subject: [PATCH 1/4] Fixed length, lower, upper and mod AST functions to use platform for generating SQL --- .../ORM/Query/AST/Functions/LengthFunction.php | 5 +++-- lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php | 5 +++-- lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php | 10 ++++------ lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php | 5 +++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php index fc779e4f7..36787786d 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php @@ -41,8 +41,9 @@ class LengthFunction extends FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - //TODO: Use platform to get SQL - return 'LENGTH(' . $sqlWalker->walkStringPrimary($this->stringPrimary) . ')'; + return $sqlWalker->getConnection()->getDatabasePlatform()->getLengthExpression( + $sqlWalker->walkSimpleArithmeticExpression($this->stringPrimary) + ); } /** diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php index b5d33face..775f51d9a 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php @@ -41,8 +41,9 @@ class LowerFunction extends FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - //TODO: Use platform to get SQL - return 'LOWER(' . $sqlWalker->walkStringPrimary($this->stringPrimary) . ')'; + return $sqlWalker->getConnection()->getDatabasePlatform()->getLowerExpression( + $sqlWalker->walkSimpleArithmeticExpression($this->stringPrimary) + ); } /** diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php index 7c52d60b8..4d124fe85 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php @@ -42,12 +42,10 @@ class ModFunction extends FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - //TODO: Use platform to get SQL - return 'MOD(' - . $sqlWalker->walkSimpleArithmeticExpression($this->firstSimpleArithmeticExpression) - . ', ' - . $sqlWalker->walkSimpleArithmeticExpression($this->secondSimpleArithmeticExpression) - . ')'; + return $sqlWalker->getConnection()->getDatabasePlatform()->getModExpression( + $sqlWalker->walkSimpleArithmeticExpression($this->firstSimpleArithmeticExpression), + $sqlWalker->walkSimpleArithmeticExpression($this->secondSimpleArithmeticExpression) + ); } /** diff --git a/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php index ff2b1e30b..acc8dd8eb 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php @@ -41,8 +41,9 @@ class UpperFunction extends FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - //TODO: Use platform to get SQL - return 'UPPER(' . $sqlWalker->walkStringPrimary($this->stringPrimary) . ')'; + return $sqlWalker->getConnection()->getDatabasePlatform()->getUpperExpression( + $sqlWalker->walkSimpleArithmeticExpression($this->stringPrimary) + ); } /** From b6da2e0e425c4481aac3bc332a0e0eced1d2bacf Mon Sep 17 00:00:00 2001 From: Juozas Kaziukenas Date: Tue, 16 Nov 2010 16:12:08 -0800 Subject: [PATCH 2/4] Proper FORM clause generation to support locking --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index f249ac29a..2903ac96f 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -844,8 +844,8 @@ class BasicEntityPersister } return 'SELECT ' . $this->_getSelectColumnListSQL() - . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' - . $this->_getSQLTableAlias($this->_class->name) + . $this->_platform->appendLockHint(' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' + . $this->_getSQLTableAlias($this->_class->name), $lockMode) . $joinSql . ($conditionSql ? ' WHERE ' . $conditionSql : '') . $orderBySql @@ -1082,7 +1082,7 @@ class BasicEntityPersister } $sql = 'SELECT 1 ' - . $this->getLockTablesSql() + . $this->_platform->appendLockHint($this->getLockTablesSql(), $lockMode) . ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' ' . $lockSql; $params = array_values($criteria); $this->_conn->executeQuery($sql, $params); From 831b40e0938f77602934ed869f98644ee47faef1 Mon Sep 17 00:00:00 2001 From: Juozas Kaziukenas Date: Wed, 17 Nov 2010 13:18:18 -0800 Subject: [PATCH 3/4] Fixes required for Microsoft SQL tests --- tests/Doctrine/Tests/Models/DirectoryTree/File.php | 1 + tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php | 2 -- tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 2 +- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/File.php b/tests/Doctrine/Tests/Models/DirectoryTree/File.php index 353177c81..57f505c33 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/File.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/File.php @@ -22,6 +22,7 @@ namespace Doctrine\Tests\Models\DirectoryTree; /** * @Entity + * @Table(name="File_model") */ class File extends AbstractContentItem { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php index 8ab65d8c6..3b0734998 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php @@ -66,7 +66,6 @@ class DDC809Variant /** * @Column(name="variant_id", type="integer") * @Id - * @GeneratedValue(strategy="AUTO") */ protected $variantId; @@ -98,7 +97,6 @@ class DDC809SpecificationValue /** * @Column(name="specification_value_id", type="integer") * @Id - * @GeneratedValue(strategy="AUTO") */ protected $specificationValueId; diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 642637116..b7b33542b 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -840,7 +840,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertSqlGeneration( 'SELECT f FROM Doctrine\Tests\Models\DirectoryTree\File f JOIN f.parentDirectory d WHERE f.id = ?1', - 'SELECT f0_.id AS id0, f0_.extension AS extension1, f0_.name AS name2 FROM File f0_ INNER JOIN Directory d1_ ON f0_.parentDirectory_id = d1_.id WHERE f0_.id = ?' + 'SELECT f0_.id AS id0, f0_.extension AS extension1, f0_.name AS name2 FROM File_model f0_ INNER JOIN Directory d1_ ON f0_.parentDirectory_id = d1_.id WHERE f0_.id = ?' ); } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index a115abc46..53706ed47 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -168,7 +168,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM navigation_countries'); } if (isset($this->_usedModelSets['directorytree'])) { - $conn->executeUpdate('DELETE FROM File'); + $conn->executeUpdate('DELETE FROM File_model'); // MySQL doesnt know deferred deletions therefore only executing the second query gives errors. $conn->executeUpdate('DELETE FROM Directory WHERE parentDirectory_id IS NOT NULL'); $conn->executeUpdate('DELETE FROM Directory'); From ec50125568c838652ebff873b8b3a91db40cce6b Mon Sep 17 00:00:00 2001 From: Juozas Kaziukenas Date: Wed, 17 Nov 2010 14:07:05 -0800 Subject: [PATCH 4/4] Fix for foreign keys and autoincrement --- lib/Doctrine/ORM/Tools/SchemaTool.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 0da4be1f3..0838f55bf 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -185,6 +185,7 @@ class SchemaTool $idMapping = $class->fieldMappings[$class->identifier[0]]; $this->_gatherColumn($class, $idMapping, $table); $columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform); + $table->getColumn($class->identifier[0])->setAutoincrement(false); $pkColumns[] = $columnName; // TODO: REMOVE