Bug #33060 [Com]: mssql extension has a max length on returnable fieldnames
Edit report at https://bugs.php.net/bug.php?id=33060&edit=1
ID: 33060
Comment by: myself at myownserver dot org
Reported by: phpbugs at mfoxx dot myspamkiller dot com
Summary: mssql extension has a max length on returnable
fieldnames
Status: Not a bug
Type: Bug
Package: MSSQL related
Operating System: winxp, sp1
PHP Version: 5.0.4
Block user comment: N
Private report: N
New Comment:
This can be solved by changing freetds version to 8.0 in /etc/freetds/freetds.conf:
Change from:
[global]
# TDS protocol version
; tds version = 4.2
To:
[global]
# TDS protocol version
tds version = 8.0
Previous Comments:
------------------------------------------------------------------------
[2013-04-15 13:58:11] rnowak at rafalnowak dot info
On Linux (Debian) Apache/2.2.21 (distrib), PHP/5.2.17 (distrib) and FreeTDS/1.12
(distrib) problem occurs too. Truncate columns names to 30 chars.
------------------------------------------------------------------------
[2005-05-18 23:03:47] tony2001@php.net
"Note: In Windows, the DBLIB from Microsoft is used. Functions that return a column name are
based on the dbcolname() function in DBLIB. DBLIB was developed for SQL Server 6.x where the max
identifier length is 30. For this reason, the maximum column length is 30 characters. On platforms
where FreeTDS is used (Linux), this is not a problem".
http://www.php.net/mssql
------------------------------------------------------------------------
[2005-05-18 22:51:15] phpbugs at mfoxx dot myspamkiller dot com
Description:
------------
FYI: I am running php 5.0.4 (binary distro) for windows, with apache 2.0.50 (binary distro), on a
winXP sp1 machine.
If i execute:
select field1 as 'abcdefghijklmnopqrstuvwxyz0123456789' from mytable
in SQL Query Analyzer against a SQL Server 2000 database, i get the expected result that the field
name is named that whole big long alias, 36 characters in length.
However, when i execute the same query using mssql_query() in PHP, and i examine the results of
mssql_fetch_object(), mssql_fetch_array(), or mssql_fetch_assoc(), the field name (alias) is
truncated at 30 characters (it seems).
I do the same test against the mysql_xxx extension, and I get no truncation (i tested with upwards
of about 100 chars in the field_name alias and all was fine).
Reproduce code:
---------------
$link = mssql_connect("localhost","sa","mypassword");
mssql_select_db("my_db",$link);
$query = "select field1 as 'abcdefghijklmnopqrstuvwxyz0123456789' from
my_table";
$result = mssql_query($query);
print_r(mssql_fetch_object($result));
$result = mssql_query($query);
print_r(mssql_fetch_array($result));
$result = mssql_query($query);
print_r(mssql_fetch_assoc($result));
Expected result:
----------------
stdClass Object ( [abcdefghijklmnopqrstuvwxyz0123456789] => 0 ) Array ( [0] => 0
[abcdefghijklmnopqrstuvwxyz0123456789] => 0 ) Array ( [abcdefghijklmnopqrstuvwxyz0123456789]
=> 0 )
Actual result:
--------------
stdClass Object ( [abcdefghijklmnopqrstuvwxyz0123] => 0 ) Array ( [0] => 0
[abcdefghijklmnopqrstuvwxyz0123] => 0 ) Array ( [abcdefghijklmnopqrstuvwxyz0123] => 0 )
** notice that all 3 methods have a truncated field_name to 30 characters. This obviously results
in unexpected code problems when I have dynamic SQL queries being generated and its difficult to
predict if an alias I assign to a field may exceed this limit, and if it does, i never get the value
out in my result-set processing because the name doesn't match what i think it should.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=33060&edit=1
Thread (5 messages)