Skip to content

PDO_DBlib: stringify 'uniqueidentifier' fields #2001

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

Closed

Conversation

turboezh
Copy link
Contributor

@turboezh turboezh commented Jul 15, 2016

Before PHP 7.0 pdo_dblib returns uniqueidentifier fields as 36-byte hex string, a 'human' representation of GUID, like, '82A88958-672B-4C22-842F-216E2B88E72A'.
Now such fields returns as 16-byte raw binary string.

I propose keep old behavior and return fields in human representation when PDO::ATTR_STRINGIFY_FETCHES == true.

https://bugs.php.net/bug.php?id=72601

turboezh added 5 commits July 7, 2016 11:17
Keep old 5.6 behavior: return Uniqidentifier value as 36-byte hex string (not binary),
when PDO::ATTR_STRINGIFY_FETCHES is TRUE
Keep old 5.6 behavior: return Uniqidentifier value as 36-byte hex string (not binary),
when PDO::ATTR_STRINGIFY_FETCHES is TRUE

Tests added.
Keep old 5.6 behavior: return Uniqidentifier value as 36-byte hex string (not binary),
when PDO::ATTR_STRINGIFY_FETCHES is TRUE

Tests fix.
@turboezh turboezh changed the title PDO_DBlib: stringify 'uniqidentifier' fields PDO_DBlib: stringify 'uniqueidentifier' fields Jul 15, 2016
@weltling
Copy link
Contributor

@adambaratz could you please check this PR?

Thanks.

@@ -64,3 +69,5 @@ bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

This fails for me. The column type comes back as SQLBINARY (45), so it's handled differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SQLUNIQUE (SYBUNIQUE) is available only since TDS 7.0. =( Maybe I'm wrong, I can't test it with all variants of databases. But when I set tds version 4.6 it really comes as SQLBINARY (45), tds version 6.0+ gives SQLUNIQUE (36).
Must the extension behave identically at all tds versions? I think 4.* versions should be left off as unsupported by this option. If so I will try to fix the test accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, my test VM had the older version set. Looks fine now. I think ideally we would skip this test for older TDS versions, but I don't think we can detect that from PHP/PDO. Maybe just add a comment saying why this test might fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are PDO attributes that are not implemented in pdo_dblib now: PDO::ATTR_SERVER_INFO, PDO::ATTR_SERVER_VERSION, PDO::ATTR_CLIENT_VERSION. They could be used to reveal some info about connection including TDS protocol version. But I think it is a task for a separate PR. I'll put a comment about possible fail in the test now with a TODO about these attrs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds great.

@adambaratz
Copy link
Contributor

I'd recommend this behavior be opt-in. I made this (breaking) change in the interest of making this extension work the same was as the (deprecated) mssql extension. So, my fault. But we should allow both behaviors to handle both sets of expectations. A boolean driver attribute would do the job.

@turboezh
Copy link
Contributor Author

A boolean driver attribute would do the job.

Could you please give me a hint how to name it? DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER?

@adambaratz
Copy link
Contributor

That attribute name is perfect.

Added separate PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER attribute instead of PDO::ATTR_STRINGIFY_FETCHES.
Added `getAttribute` support for PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER.
@turboezh
Copy link
Contributor Author

Ready for another review.

@adambaratz
Copy link
Contributor

adambaratz commented Aug 22, 2016

Thanks for doing the cleanup. Test coverage is good. Unit tests run clean, with/without valgrind. There are some slight changes that I think are worth making to the attribute handling, making the code and the memory usage more concise. I put these up on a remote branch. If you cherry pick that commit onto your branch, you'll be good to go.

@turboezh
Copy link
Contributor Author

Done.

@adambaratz
Copy link
Contributor

@weltling: this is ready to be merged.

@weltling
Copy link
Contributor

The exact part from ext/pdo_dblib/tests/stringify_uniqueidentifier.phpt fails with the default setting. I've tried so far to set tds version = 7.0 and the test passed. Not related here, however two other tests fail with tds 7.0 - ext/pdo_dblib/tests/bug_45876.phpt and ext/pdo_dblib/tests/types.phpt. Seems version dependent, so a way to skip tests were indeed useful.

@adambaratz please send a request to internals for becoming a maintainer. Once you have git access, you'll be able to merge PRs yourself.

Thanks for your work, guys!

@adambaratz
Copy link
Contributor

@weltling: will do, thanks! I'm currently poking at some of these TDS version inconsistencies... see my comment on #2095.

@weltling
Copy link
Contributor

Merged with a000bff.

Thanks!

@weltling weltling closed this Aug 25, 2016
@turboezh turboezh deleted the pdo_dblib_stringify_uniqidentifier branch August 26, 2016 08:58
@stayeronglass
Copy link

stayeronglass commented Dec 8, 2016

please document this feature

@tylers-username
Copy link

Agree with @stayeronglass, this should be documented. I have an API that depends on a MSSQL connection and have yet to be able to get it to upgrade to PHP 7 due to this GUID problem.

How do we restore the human readable output?

@turboezh
Copy link
Contributor Author

@stayeronglass, @tylerssn, @adambaratz.
I doubt my english skills will be enough to update official docs and I have no such experience. I will appreciate if anyone would do it.
The summary is:

  • PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER (boolean) attribute was added since PHP 7.0.11;
  • it may be set as other PDO attributes in PDO constructor or with PDO::setAttribute();
  • when it's FALSE (default), GUIDs returns as 16-byte binary string;
  • when it's TRUE, GUIDs returns as 36-byte formatted string, like '82A88958-672B-4C22-842F-216E2B88E72A';
  • TDS protocol version affects this behavior! uniqueidentifier field type supported only in 7.0+ protocol version, so with version <7.0 field value will be always returned as 16-byte binary string regardless of the attribute value.

@joelharkes
Copy link

has this option been replaced as DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER is no longer available on the PDO class?

@cmb69
Copy link
Member

cmb69 commented Mar 16, 2022

@joelharkes, no, this attribute is still supposed to be supported. Please file a ticket, if you have a PHP with the pdo_dblib extension enabled, and that constant is not defined.

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.

7 participants