Skip to content

[Bug #77120] Handle OCI_SUCCESS_WITH_INFO returned from OCISessionBegin #6857

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

Merged
merged 2 commits into from
Jun 9, 2021
Merged

[Bug #77120] Handle OCI_SUCCESS_WITH_INFO returned from OCISessionBegin #6857

merged 2 commits into from
Jun 9, 2021

Conversation

morozov
Copy link
Contributor

@morozov morozov commented Apr 11, 2021

Create a test user:

CREATE PROFILE test_profile LIMIT PASSWORD_LIFE_TIME 1/86400 PASSWORD_GRACE_TIME 7;
CREATE USER bob IDENTIFIED BY password PROFILE test_profile;
GRANT CREATE SESSION TO bob;

Run the script:

$conn = new PDO('oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)))', 'bob', 'password');

Expected result:
The connection is successfully established. The details of the informational message are available via PDO::errorInfo().

Actual result:

PDOException: SQLSTATE[HY000]: OCISessionBegin: OCI_SUCCESS_WITH_INFO: ORA-28002: the password will expire within 7 days
 (ext/pdo_oci/oci_driver.c:685) in test.php on line 3

Change summary:

  1. Proceed with connection initialization if OCI_SUCCESS_WITH_INFO is returned.
  2. Do not throw an exception upon OCI_SUCCESS_WITH_INFO.

@morozov morozov marked this pull request as ready for review April 11, 2021 20:36
@nikic
Copy link
Member

nikic commented Apr 12, 2021

cc @cjbj

@morozov
Copy link
Contributor Author

morozov commented Apr 26, 2021

@nikic is there a way to proceed given the absence of @cjbj's feedback?

@cjbj
Copy link
Contributor

cjbj commented Apr 26, 2021

I'd like to review it first.

@ramsey
Copy link
Member

ramsey commented May 7, 2021

@morozov Is it possible to provide a test with this?

@morozov
Copy link
Contributor Author

morozov commented May 7, 2021

Absolutely. I just want to make sure the fix as such is acceptable.

@cjbj
Copy link
Contributor

cjbj commented May 8, 2021

Adding a test now would expedite me reviewing it. Otherwise I have to create the test... :)

@morozov
Copy link
Contributor Author

morozov commented May 8, 2021

I can add a test by Monday.

@morozov
Copy link
Contributor Author

morozov commented May 9, 2021

@cjbj, @ramsey please see the test.

@cjbj
Copy link
Contributor

cjbj commented May 10, 2021

@morozov Thank you. I should get time later this week to take a look.

Copy link
Contributor

@cjbj cjbj left a comment

Choose a reason for hiding this comment

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

Can you also check some other SUCCESS_WITH_INFO cases such as PL/SQL compilation failures? Check them for various PDO::ATTR_ERRMODE values. (And verify the old & new behaviors). Thank you!

@morozov
Copy link
Contributor Author

morozov commented May 17, 2021

Can you also check some other SUCCESS_WITH_INFO cases such as PL/SQL compilation failures? Check them for various PDO::ATTR_ERRMODE values.

What would be the best way to reproduce this? I tried a couple of examples I found online (e.g. this) in PhpStorm but it didn't trigger the expected error.

Verified

This commit was signed with the committer’s verified signature.
morozov Sergei Morozov
1. Proceed with connection initialization if OCI_SUCCESS_WITH_INFO is returned
2. Do not throw an exception upon OCI_SUCCESS_WITH_INFO
@morozov
Copy link
Contributor Author

morozov commented May 17, 2021

I manages to reproduce the compilation error with the following:

function triggerCompilationError(PDO $conn): void {
    $conn->exec(<<<'SQL'
CREATE OR REPLACE FUNCTION BUG77120(INT A) RETURN INT
AS
BEGIN
    RETURN 0;
END;
SQL
    );
}

triggerCompilationError($conn);

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
triggerCompilationError($conn);

Which produces the following:

Warning: PDO::exec(): SQLSTATE[HY000]: General error: 24344 OCIStmtExecute: OCI_SUCCESS_WITH_INFO: ORA-24344: success with compilation error
(ext/pdo_oci/oci_driver.c:340) in ext/pdo_oci/tests/oci_success_with_info.php on line 41

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 24344 OCIStmtExecute: OCI_SUCCESS_WITH_INFO: ORA-24344: success with compilation error
(ext/pdo_oci/oci_driver.c:340) in ext/pdo_oci/tests/oci_success_with_info.php:41

I assume the error handling still exists in this scenario but it's out of the scope of the original issue. Statement error handling can be configured at runtime while connection error handling cannot.

@cjbj
Copy link
Contributor

cjbj commented May 18, 2021

I assume the error handling still exists in this scenario but it's out of the scope of the original issue. Statement error handling can be configured at runtime while connection error handling cannot.

The PR changes _oci_error() which is called in oci_statement.c so it seems wiser to check that any existing statement error handling isn't borked.

You could use create or replace procedure p() as begin null; end; to create a compilation error.

@morozov
Copy link
Contributor Author

morozov commented May 18, 2021

The PR changes _oci_error() which is called in oci_statement.c so it seems wiser to check that any existing statement error handling isn't borked.

It wasn't borked, it worked as previously, see #6857 (comment).

Please see the update. I modified handling OCI_SUCCESS_WITH_INFO returned from OCIStmtExecute and updated the test.

Copy link
Contributor

@cjbj cjbj left a comment

Choose a reason for hiding this comment

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

Thanks for tidying up, and for adding the extra checks to confirm the behavior.
With the trivial test changes I noted, let's get this merged.
Thanks for making PDO_OCI better.

Verified

This commit was signed with the committer’s verified signature.
morozov Sergei Morozov
1. Backup last_error before replacing it with the error code
2. Continue normal operations if last_error is OCI_SUCCESS_WITH_INFO
@morozov
Copy link
Contributor Author

morozov commented May 26, 2021

@cjbj thanks for the review. Please see the update.

@morozov
Copy link
Contributor Author

morozov commented Jun 3, 2021

@cjbj any chance you could review this again?

@cjbj
Copy link
Contributor

cjbj commented Jun 4, 2021

LGTM

@ramsey can you advise on the (new) current process for merging?

@morozov
Copy link
Contributor Author

morozov commented Jun 9, 2021

@ramsey what would be the next step to get this patch accepted?

@ramsey
Copy link
Member

ramsey commented Jun 9, 2021

All good. Sorry for the delay. Thanks!

@ramsey ramsey merged commit e496123 into php:master Jun 9, 2021
@morozov morozov deleted the bug77120 branch June 9, 2021 20:50
@cmb69
Copy link
Member

cmb69 commented Jun 9, 2021

This should have an entry in NEWS.

@cjbj
Copy link
Contributor

cjbj commented Jun 10, 2021

This should have an entry in NEWS.

Done. Thanks all.

@ramsey
Copy link
Member

ramsey commented Jun 10, 2021

Thanks, @cjbj!

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

Successfully merging this pull request may close these issues.

None yet

5 participants