php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75534 Column aliases not working with FreeTDS
Submitted: 2017-11-16 19:48 UTC Modified: -
Votes:5
Avg. Score:4.2 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: chris at ocproducts dot com Assigned:
Status: Open Package: ODBC related
PHP Version: 7.1.11 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-11-16 19:48 UTC] chris at ocproducts dot com
Description:
------------
I am on a Mac using recent versions of FreeTDS (1.00.70, homebrew) and unixODBC (2.3.4, homebrew), connecting to SQL Server Express 2017 on Windows 10.

Column aliases (e.g. SELECT foo AS bar FROM something) are not respected. odbc_field_name will return 'foo', not 'bar'.

This is a known issue, but as far as I can see was never reporting directly to PHP as a bug.

Discussed on FreeTDS mailing list:
https://lists.ibiblio.org/pipermail/freetds/2010q2/025720.html
https://lists.ibiblio.org/pipermail/freetds/2012q1/027752.html

It is FreeTDS version specific, as at some point they improved their ODBC support to return original table field names rather than only aliases, with PHP now failing on assuming nothing will do that correctly.

Many asking questions across the web, and using kludgy workarounds like forced casts or noop expressions or downgrading the TDS protocol version:
https://stackoverflow.com/questions/10597898/php-unixodbc-freetds-select-field-as-name-does-not-work
https://github.com/ADOdb/ADOdb/issues/141
http://www.devnetwork.net/viewtopic.php?f=2&t=128778

I was able to resolve via a trivial patch, which is attached.

I am by no means an expert on ODBC. I can't confirm all ODBC implementations will correctly SQL_DESC_NAME, only that using it corrects my issue.


Patches

odbc-field-name-fix.diff (last revision 2017-11-16 19:48 UTC by chris at ocproducts dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-02 22:21 UTC] kuya1284 at gmail dot com
I just posted another workaround to this bug on SO that doesn't involve type-casting:

https://stackoverflow.com/a/55484317/2418233

It basically involves the use of variables before (or after) executing the SELECT query.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Sep 20 05:01:26 2019 UTC