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

Add support for IbmDb2 (IBM i) #565

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

alanseiden
Copy link

Create storage class for the ibm_db2 extension, which is commonly used with DB2 on IBM i. The class includes DDL optimized for IBM i (chiefly the "for system name" clause).


// this is how ZF2 handles connection errors
if ($connection === false) {
throw new Exception\RuntimeException(sprintf(
Copy link
Owner

Choose a reason for hiding this comment

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

This will throw a namespace error, as it will be looking for OAuth2\Storage\ Exception\RuntimeException

Copy link
Author

Choose a reason for hiding this comment

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

Would \Exception\RuntimeException (add slash in front) be acceptable here?

Copy link
Owner

Choose a reason for hiding this comment

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

no, the PHP class is \RuntimeException (see here)

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I tested \RuntimeException successfully today. Thanks.

@bshaffer
Copy link
Owner

Wow, this is impressive! I am unfamiliar with IBM DB2... how can we add tests for this?

It is easy to add tests for new storage engines in the test suite... you just need to add the class to the BaseTest::provideStorage method, and all the applicable storage tests will be run.

@alanseiden
Copy link
Author

It seems that Pdo's tests use sqlite; DynamoDb uses mock objects. Are there any tests with something similar to ibm_db2 that requires a real server? The ibm_db2 extension is not OO, so might not be easy to mock.

@bshaffer
Copy link
Owner

@alanseiden DynamoDB doesn't use mock objects in the storage tests - it calls a real DynamoDB instance that I've set up with my Amazon credentials. I had to add an exception so it only runs against php 5.5 in travis ci - otherwise the tests ran 6 times and conflicted with each other.

Is it possible to test against a local (travis) or remote (cloud) instance of IBM DB2?


// use persistent or not
$isPersistent = $connection['persistent'];
$connectFunction = ((bool) $isPersistent) ? 'db2_pconnect' : 'db2_connect';
Copy link
Owner

Choose a reason for hiding this comment

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

we should verify here that these functions exist - if they don't, we should throw an exception requiring the ibm_db2 extension

Copy link
Author

Choose a reason for hiding this comment

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

I've added a check for the ibm_db2 extension using extension_loaded(), the technique used in ZF2. Sufficient or should we also check for the functions?

@bshaffer
Copy link
Owner

Is there anything I can do to help this along? I am waiting to hear back from you concerning the testability of IMB-DB2

@alanseiden
Copy link
Author

IBM Db2 requires a real server. Clark Everetts of Zend wrote tests against a real IBM i server for ZF2's Zend_Db, so it's possible to do.

@alanseiden
Copy link
Author

I'm going to see Clark this week at a conference. Perhaps we can put our heads together.

@bshaffer
Copy link
Owner

bshaffer commented May 4, 2015

@alanseiden any progress on this?

@alanseiden
Copy link
Author

Today I did find a couple of bugs in the DDL and know how to correct the
exception bug. Will correct those first.

Brent Shaffer wrote:

@alanseiden https://github.com/alanseiden any progress on this?


Reply to this email directly or view it on GitHub
#565 (comment).

$result = db2_fetch_assoc($stmt);

// make this extensible
return $result && $result['client_secret'] == $client_secret;
Copy link

Choose a reason for hiding this comment

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

Is the purpose of the expression to test if $result exists, and if so, perform the == comparison? The == comparison operator has higher precedence than && logical operator, meaning if I have the intent correct, the expression should actually be $result && ($result['client_secret'] == $client_secret). In this way, PHP's short-circuit boolean evaluation can be applied without undefined variable notice. Actually, the effect is the same: == will be evaluated before &&. I wonder if isset() is required here; will have to test. Or have I missed something obvious (it wouldn't be the first time)?

@afilippov1985
Copy link
Contributor

PDO is able to work with IBM DB2 http://php.net/manual/en/ref.pdo-ibm.php

@bshaffer
Copy link
Owner

excellent find! We should add IBM DB2 to the travis tests then, and we can close this sucker.

@alanseiden
Copy link
Author

I don't understand how PDO would help with testing of the ibm_db2 extension.

@bshaffer
Copy link
Owner

Using the PDO storage class and the pdo-ibm extension, a user should be able to integrate with this server and the IBM DB out of the box. They just need to create a PDO object using the IMB_DB2 dsn

@CiTRO33
Copy link

CiTRO33 commented Mar 14, 2017

Hello @alanseiden
we are trying to use Oauth with JWT Access Token (https://bshaffer.github.io/oauth2-server-php-docs/overview/jwt-access-tokens/) .

We insert the public / Private keys into the oauth_public_keys table.

If we want to generate a new access token, we got an error.
I figured out, that the SQL in the functions getPublicKey (Line 467 in /src/OAuth2/Storage/IbmDb2.php ), getPrivateKey (Line 477 in /src/OAuth2/Storage/IbmDb2.php ) and getEncryptionAlgorithm (Line 487 in /src/OAuth2/Storage/IbmDb2.php ) didn't work, because ORDER BY client_id IS NOT NULL DESC didn't exists in DB2 V7R1.

When i change this to ORDER BY client_id ASC the correct data is returned.
Sorted by example "testclient", NULL .

maybe its a performance improvements if we add FETCH FIRST ROW ONLY to retrun only one row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants