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

DB2 constants are missing when setting up db factory #83

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 12 additions & 1 deletion packages/zend-db/library/Zend/Db/Adapter/Db2.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
*
* @var int execution flag (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)
*/
protected $_execute_mode = DB2_AUTOCOMMIT_ON;
protected $_execute_mode;

/**
* Default class name for a DB statement.
Expand Down Expand Up @@ -111,6 +111,17 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
'NUMERIC' => Zend_Db::FLOAT_TYPE
);

public function __construct($config)
{
// Only assign the value if constant is present
// The required extension check is performed in _connect()
if (defined('DB2_AUTOCOMMIT_ON')) {
$this->_execute_mode = DB2_AUTOCOMMIT_ON;
}

parent::__construct($config);
}

/**
* Creates a connection resource.
*
Expand Down
6 changes: 5 additions & 1 deletion tests/Zend/Db/TestSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,18 @@ protected function _setUpTestUtil()
*/
protected function _setUpAdapter()
{
$this->_db = Zend_Db::factory($this->getDriver(), $this->_util->getParams());
try {
$this->_db = Zend_Db::factory($this->getDriver(), $this->_util->getParams());
$conn = $this->_db->getConnection();
} catch (Zend_Exception $e) {
$this->_db = null;
$this->assertTrue($e instanceof Zend_Db_Adapter_Exception,
'Expecting Zend_Db_Adapter_Exception, got ' . get_class($e));
$this->markTestSkipped($e->getMessage());
} catch (Throwable $e) {
if (stristr($e->getMessage(), 'undefined constant')) {
$this->markTestSkipped();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

But I'm thinking maybe this approach is wrong, better emulate in code the same behavior as older php versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class can't be even loaded:

The exception is thrown on class construction:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only solution here is to assign $_execute_mode default value on the constructor. but no idea about is that backward compatible change or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

Expand Down