ID:               28512
 Comment by:       brian at groundspring dot org
 Reported By:      barry at hpfm dot com dot au
 Status:           Closed
 Bug Type:         *Web Server problem
 Operating System: Redhat 9.0
 PHP Version:      4.3.5
 New Comment:

I have encountered a related bug in php5.  If you select a datetime
field from an MSSQL table without specifying a format, it assumes a
default field length of 19.

On our setup, the datetime is returned in a format of length 24 (eg:
Thu Jul 15 15:26:00 2004).  I've gotten around this by patching
res_length to be arbitrarily large (+= 19 instead of 14 or 10), but
there must be a cleaner solution out there.


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

[2004-07-07 09:59:29] daniel dot beet at accuratesoftware dot com

I have since found that my patch did not fully fix the bug. Sorry to
mess you about, but here is a better patch that will work for DECIMAL
and NUMERIC columns up to the maximum allowed precision (38).

I have also removed the extra code in the first patch for SQLMONEY
types, as they were catered for further up in the function.

Also I noticed that the function mssql_field_type() returns Decimal
types as "real", where as Numeric types are returned as "numeric",
since they are synonymous, I thought that this was not right, and that
both should be called "numeric"?

Patch against: php_mssql.c CVS version 1.86.2.34:

841d840
<               case SQLNUMERIC:
857,859d855
<                                               case SQLMONEY :
<                                               case SQLMONEY4 :
<                                               case SQLMONEYN :
862c858
<                                                       res_length += 5;
---
>                                                       res_length = 40;
932a929,930
>                                       res_length = 23;
>                                       break;
935c933
<                                       res_length += 5;
---
>                                       res_length = 40;
1070a1069,1071
>                       case SQLMONEY4:
>                       case SQLMONEY:
>                       case SQLMONEYN:
1505d1505
<               case SQLDECIMAL:
1517a1518
>               case SQLDECIMAL:

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

[2004-06-30 21:47:55] [EMAIL PROTECTED]

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.



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

[2004-06-30 16:39:20] daniel dot beet at accuratesoftware dot com

Sorry, PHP versions 4.3.7 and 4.3.4

Thanks,

Dan

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

[2004-06-30 16:34:35] daniel dot beet at accuratesoftware dot com

We are experiencing a similar crash, when values in 
decimal or numeric columns are larger than certain values.

Reproduced on MS SQL 2000 on Windows 2000 Server, with 
Apache 1.3.27 as webserver or CLI php exe on Win XP.

Create table with data:

CREATE TABLE [dbo].[test] (
        [test_decimal] [decimal](23, 6) NULL ,
        [test_numeric] [numeric](23, 6) NULL 
) ON [PRIMARY]
GO

INSERT INTO test (test_decimal, test_numeric) 
VALUES (99999999999999999.999999, 99999999999999999.999999)
GO

Run following PHP script:
<?php

$conn = mssql_connect('yourserver', 'you', 'password');
echo "Connection OK<br />\n";

mssql_select_db('yourdatabase', $conn);
echo "DB selected OK<br />\n";

$result = mssql_query('select test_decimal, test_numeric from test',
$conn);
echo "Query OK<br />\n";

$array[] = mssql_fetch_field($result, 0);
$array[] = mssql_field_name($result, 0);
$array[] = mssql_field_type($result, 0);
$array[] = mssql_field_length($result, 0);
$array[] = mssql_fetch_assoc($result);
echo "Results fetched OK<br />\n";

echo '<pre>';
var_export($array);
echo '</pre>';

mssql_close($conn);

?>

I have solved the issue with the following diff of changes to
php_mssql.c:

841a842
>               case SQLDECIMAL:
850,852c851,866
<                                       if (column_type == SQLDATETIM4) res_length += 
14;
<                                       if (column_type == SQLDATETIME) res_length += 
10;
<                       
---
>                                       switch (column_type) {
>                                               case SQLDATETIM4 :
>                                                       res_length += 14;
>                                                       break;
>                                               case SQLDATETIME :
>                                                       res_length += 10;
>                                                       break;
>                                               case SQLMONEY :
>                                               case SQLMONEY4 :
>                                               case SQLMONEYN :
>                                               case SQLDECIMAL :
>                                               case SQLNUMERIC :
>                                                       res_length += 5;
>                                                       break;
>                                       }
> 
919a934,935
>                               case SQLDECIMAL :
>                               case SQLNUMERIC :


The buffer res_buf was beeing allocated to small (20 for above columns,
when 24 is required)

Hope that this helps, as it is critical for us!

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

[2004-06-23 23:22:56] barry at hpfm dot com dot au

Problem still exists  - I'll try to get more details on the exact
sequence of calls though the only real notive we get is a radical
reduction in the performance of the queries and the associated
<path_to_logs>/error_log file produced by Apache.

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/28512

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

Reply via email to