Skip to Content.
Sympa Menu

freetds - Re: [freetds] SP input parameter problem on 0.63

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Allan Kim <akim AT freedom.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] SP input parameter problem on 0.63
  • Date: Thu, 01 Sep 2005 11:53:57 -0700

I posted the following as a comment to PHP bug #33693 a few minutes ago as the handling of maxlen for non-null input parameters hasn't been fixed in PHP5.1RC1:

http://bugs.php.net/bug.php?id=33963


The problem with invalid values of maxlen for input parameters still
exists in 5.1RC1.

Previously these published specs were quoted:

-----------------
maxlen
For variable-length return parameters (when type is SQLCHAR, SQLBINARY,
SQLTEXT, or SQLIMAGE), maxlen is the maximum desired byte length for the
value parameter returned from a stored procedure.
Set maxlen to -1 in any of these cases:

For fixed-length return parameters (such as when type is SQLINT4).
To pass a NULL fixed-length parameter value (such as when type is
SQLINT4) to the stored procedure.
*** For parameters that are not designated as return parameters. *** (my
emphasis)
Set maxlen to 0 to pass a NULL variable-length parameter value (when
type is SQLCHAR, SQLBINARY, SQLTEXT, or SQLIMAGE) to the stored
procedure.
-----------------

The specific problem is that maxlen should be set to -1 for "parameters
that are not designated as return parameters" which is a very roundabout
way of saying "input parameters." As currently written mssql_bind() sets
maxlen = 0 for *all* parameters of variable-length type, including input
parameters (see lines 2033-2043).

This poses a problem with FreeTDS >= 0.63 because an error will be
returned if invalid values of maxlen are passed to dbrpcparam().
Previous versions of FreeTDS didn't perform much in the way of
validation.

There were multiple problems with SP parameters in FreeTDS
0.63 discussed on the FreeTDS listserv around the same time. Some were
bona fide FreeTDS bugs and were fixed; when Freddy noted "fixed in CVS"
I think he referred to a FreeTDS bug in handling NULL value parameters,
which was fixed in CVS for dblib/rpc.c on Aug. 8. This particular maxlen
problem with variable-length input parameters seems to be a bug in
php_mssql.c, complicated by certain default settings in ADODB.

Sorry if this seems repetitive but there have been no updates in weeks
and I was afraid earlier comments might not have been worded clearly.

ZIGLIO, Frediano, VF-IT wrote:


Try removing
if (maxlen != -1 && maxlen != 0)
return FAIL;

lines. However PHP is passing wrong parameters... maxlen should not be
4000 for input parameters but -1 (0 from MS specification is string is
null...)

It would be correct to change these line in php_mssql.c (mssql_bind)

if (is_output) {
status=DBRPCRETURN;
}

to

if (is_output) {
status=DBRPCRETURN;
} else {
maxlen = -1;
}

Or change these lines

case 7: {
zval **yyis_output, **yyis_null, **yymaxlen;

if (zend_get_parameters_ex(7, &stmt, &param_name, &var, &yytype,
&yyis_output, &yyis_null, &yymaxlen)==FAILURE){
RETURN_FALSE;
}
convert_to_long_ex(yytype);
convert_to_long_ex(yyis_output);
convert_to_long_ex(yyis_null);
convert_to_long_ex(yymaxlen);
type=Z_LVAL_PP(yytype);
is_output=Z_LVAL_PP(yyis_output);
is_null=Z_LVAL_PP(yyis_null);
maxlen=Z_LVAL_PP(yymaxlen);
}
break;

with

case 7: {
zval **yyis_output, **yyis_null, **yymaxlen;

if (zend_get_parameters_ex(7, &stmt, &param_name, &var, &yytype,
&yyis_output, &yyis_null, &yymaxlen)==FAILURE) {
RETURN_FALSE;
}
convert_to_long_ex(yytype);
convert_to_long_ex(yyis_output);
convert_to_long_ex(yyis_null);
convert_to_long_ex(yymaxlen);
type=Z_LVAL_PP(yytype);
is_output=Z_LVAL_PP(yyis_output);
is_null=Z_LVAL_PP(yyis_null);
maxlen=Z_LVAL_PP(yymaxlen);
if (!is_output)
maxlen = -1;
}
break;

freddy77
_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds





Archive powered by MHonArc 2.6.24.

Top of Page