Bug #75534 [Com]: Column aliases not working with FreeTDS
| From: | samsnow at tjsnow dot com | Date: | Thu, 29 Jun 2023 03:00:28 +0000 |
| Subject: | Bug #75534 [Com]: Column aliases not working with FreeTDS | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-244833@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75534&edit=1
ID: 75534
Comment by: samsnow at tjsnow dot com
Reported by: chris at ocproducts dot com
Summary: Column aliases not working with FreeTDS
Status: Open
Type: Bug
Package: ODBC related
PHP Version: 7.1.11
Block user comment: N
Private report: N
New Comment:
Running debian bookworm with PHP 8.2.5 and FreeTDS 1.3.17 and seeing this same bug.
Working around it right now, using the "set a variable before you do a the query" trick,
but it would be great to get this fixed.
Previous Comments:
------------------------------------------------------------------------
[2019-04-02 22:21:05] 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.
------------------------------------------------------------------------
[2017-11-16 19:48:01] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75534&edit=1