From b7cac8c310676c700a7cf406e9ca1fda0a4025e0 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 20 Apr 2010 23:20:42 +0200 Subject: [PATCH] Fixed pecl/ibm_db2 Driver and Connection to run smoothly against the complete test-suite (depending on a c-patch to the extension though) --- .../DBAL/Driver/IbmDb2/Db2Connection.php | 10 ++-------- .../DBAL/Driver/IbmDb2/Db2Statement.php | 20 +++++++++++++++---- lib/Doctrine/DBAL/Platforms/Db2Platform.php | 16 ++++++--------- .../ORM/Functional/AdvancedDqlQueryTest.php | 2 +- .../ORM/Functional/DefaultValuesTest.php | 2 +- .../ManyToManyBasicAssociationTest.php | 6 +++++- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Connection.php b/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Connection.php index bc180fac6..2d13ce03f 100644 --- a/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Connection.php @@ -71,18 +71,12 @@ class Db2Connection implements \Doctrine\DBAL\Driver\Connection { $stmt = $this->prepare($statement); $stmt->execute(); - return $stmt; + return $stmt->rowCount(); } function lastInsertId($name = null) { - $sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1'; - if ($stmt = $this->query($sql)) { - if ($col = $stmt->fetchColumn()) { - return $col; - } - } - return false; + return db2_last_insert_id($this->_conn); } function beginTransaction() diff --git a/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Statement.php b/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Statement.php index c4594ff04..d25269cc3 100644 --- a/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IbmDb2/Db2Statement.php @@ -25,6 +25,8 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement { private $_stmt = null; + private $_bindParam = array(); + /** * DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG * @var @@ -54,7 +56,7 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement */ function bindValue($param, $value, $type = null) { - return $this->bindParam($param, $variable, $type); + return $this->bindParam($param, $value, $type); } /** @@ -81,7 +83,9 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement */ function bindParam($column, &$variable, $type = null) { - if (!$type && isset(self::$_typeMap[$type])) { + $this->_bindParam[$column] =& $variable; + + if ($type && isset(self::$_typeMap[$type])) { $type = self::$_typeMap[$type]; } else { $type = DB2_CHAR; @@ -90,6 +94,7 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) { throw new Db2Exception(db2_stmt_errormsg()); } + return true; } /** @@ -103,6 +108,8 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement return false; } + $this->_bindParam = array(); + db2_free_result($this->_stmt); $ret = db2_free_stmt($this->_stmt); $this->_stmt = false; return $ret; @@ -171,12 +178,17 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement return false; } - $retval = true; + /*$retval = true; if ($params !== null) { $retval = @db2_execute($this->_stmt, $params); } else { $retval = @db2_execute($this->_stmt); + }*/ + if ($params === null) { + ksort($this->_bindParam); + $params = array_values($this->_bindParam); } + $retval = @db2_execute($this->_stmt, $params); if ($retval === false) { throw new Db2Exception(db2_stmt_errormsg()); @@ -260,7 +272,7 @@ class Db2Statement implements \Doctrine\DBAL\Driver\Statement function fetchColumn($columnIndex = 0) { $row = $this->fetch(\PDO::FETCH_NUM); - if (!$row && isset($row[$columnIndex])) { + if ($row && isset($row[$columnIndex])) { return $row[$columnIndex]; } return false; diff --git a/lib/Doctrine/DBAL/Platforms/Db2Platform.php b/lib/Doctrine/DBAL/Platforms/Db2Platform.php index b02d2eade..96cb18870 100644 --- a/lib/Doctrine/DBAL/Platforms/Db2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/Db2Platform.php @@ -282,7 +282,7 @@ class Db2Platform extends AbstractPlatform */ public function getCurrentDateSQL() { - return 'current date'; + return 'VALUES CURRENT DATE'; } /** @@ -292,7 +292,7 @@ class Db2Platform extends AbstractPlatform */ public function getCurrentTimeSQL() { - return 'current time'; + return 'VALUES CURRENT TIME'; } /** @@ -300,10 +300,11 @@ class Db2Platform extends AbstractPlatform * * @return string */ - /*public function getCurrentTimestampSQL() + + public function getCurrentTimestampSQL() { - return 'current timestamp'; - }*/ + return "VALUES CURRENT TIMESTAMP"; + } /** * Obtain DBMS specific SQL code portion needed to set an index @@ -437,11 +438,6 @@ class Db2Platform extends AbstractPlatform return "SESSION." . $tableName; } - public function getCurrentTimestampSQL() - { - return "VALUES CURRENT TIMESTAMP"; - } - public function modifyLimitQuery($query, $limit, $offset = null) { if ($limit === null && $offset === null) { diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php index be75c2c1e..6a994c944 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php @@ -122,7 +122,7 @@ class AdvancedDqlQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testUpdateAs() { $dql = 'UPDATE Doctrine\Tests\Models\Company\CompanyEmployee AS p SET p.salary = 1'; - $this->_em->createQuery($dql)->getResult(); + $this->_em->createQuery($dql)->execute(); $this->assertTrue(count($this->_em->createQuery( 'SELECT count(p.id) FROM Doctrine\Tests\Models\Company\CompanyEmployee p WHERE p.salary = 1')->getResult()) > 0); diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php index 71edf4dc2..873f0d938 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php @@ -28,7 +28,7 @@ class DefaultValuesTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'romanb'; $this->_em->persist($user); $this->_em->flush(); - $this->_em->clear(); + $this->_em->clear(); $userId = $user->id; // e.g. from $_REQUEST $user2 = $this->_em->getReference(get_class($user), $userId); diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index bdabf6206..0ccb8db45 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -47,7 +47,9 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa // Get user $user = $uRep->findOneById($user->getId()); - + + $this->assertNotNull($user, "Has to return exactly one entry."); + $this->assertFalse($user->getGroups()->isInitialized()); // Check groups @@ -89,6 +91,8 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa // Association should not exist $user2 = $this->_em->find(get_class($user), $user->getId()); + + $this->assertNotNull($user2, "Has to return exactly one entry."); $this->assertEquals(0, $user2->getGroups()->count()); }