#45551 [Opn->Fbk]: Wrong result when selecting from varchar field

From: Date: Mon, 06 Oct 2008 22:07:12 +0000
Subject: #45551 [Opn->Fbk]: Wrong result when selecting from varchar field
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129522@lists.php.net to get a copy of this message
 ID:               45551
 Updated by:       felipe@php.net
 Reported By:      brack at wjp dot de
-Status:           Open
+Status:           Feedback
 Bug Type:         MSSQL related
 Operating System: Windows Vista Business
 PHP Version:      5.2.6
 New Comment:

Your example looks wrong then, because the first output is produced by:
echo strlen($string).


Previous Comments:
------------------------------------------------------------------------

[2008-07-18 08:23:22] brack at wjp dot de

Same problem occurs on MS SQL Server 2000!

------------------------------------------------------------------------

[2008-07-18 06:33:58] brack at wjp dot de

Description:
------------
On SQL Server 2005 when I execute a SELECT query to retrieve the
content of a VARCHAR field with a specified length greater than 255 and
less than MAX, the resulting value is truncated at a length of 255
characters.

Reproduce code:
---------------
For testing purposes, I used a table created by the following SQL
code:

CREATE TABLE [TESTTABLE](
	[id] [int] NOT NULL,
	[testvalue] [varchar](1000) NULL,
 CONSTRAINT [PK_TESTTABLE] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

PHP test script code:

$conn = mssql_connect('localhost', 'testuser', 'testpassword');
mssql_select_db('testdb');
$string =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
echo strlen($string) . '<br>';
mssql_query('INSERT INTO TESTTABLE (id, testvalue) VALUES (1, \'' .
$string . '\')');
$result = mssql_query('SELECT testvalue FROM TESTTABLE WHERE id=1');
echo(strlen(mssql_result($result, 0, testvalue')));

Expected result:
----------------
Expected output of the PHP test script:

396
396

Actual result:
--------------
Actual output of the PHP test script:

255
396


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45551&edit=1



Thread (4 messages)

« previous php.bugs (#129522) next »